Android Open Source - dw2020 Http Request Adapter






From Project

Back to project page dw2020.

License

The source code is released under:

Apache License

If you think the Android project dw2020 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2013 Patrik kerfeldt/*www .  j  a  va 2 s  . c  om*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package se.akerfeldt.signpost.retrofit;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import oauth.signpost.http.HttpRequest;

import retrofit.client.Header;
import retrofit.client.Request;

public class HttpRequestAdapter implements HttpRequest {

  private static final String DEFAULT_CONTENT_TYPE = "application/json";
  
  private Request request;

  private String contentType;

  public HttpRequestAdapter(Request request) {
        this(request, DEFAULT_CONTENT_TYPE);
    }
  
  public HttpRequestAdapter(Request request, String contentType) {
    this.request = request;
    this.contentType = contentType;
  }
  
  @Override
  public Map<String, String> getAllHeaders() {
    HashMap<String, String> headers = new HashMap<String, String>(); 
    for(Header header : request.getHeaders()) {
      headers.put(header.getName(), header.getValue());
    }
    return headers;
  }

  @Override
  public String getContentType() {
    return contentType;
  }

  @Override
  public String getHeader(String key) {
    for(Header header : request.getHeaders()) {
      if(key.equals(header.getName())) {
        return header.getValue();
      }
    }
    return null;
  }

  @Override
  public InputStream getMessagePayload() throws IOException {
    throw new RuntimeException(new UnsupportedOperationException());
  }

  @Override
  public String getMethod() {
    return request.getMethod();
  }

  @Override
  public String getRequestUrl() {
    return request.getUrl();
  }

  @Override
  public void setHeader(String key, String value) {
    ArrayList<Header> headers = new ArrayList<Header>();
    headers.addAll(request.getHeaders());
    headers.add(new Header(key, value));
    Request copy = new Request(request.getMethod(), request.getUrl(), headers, request.getBody());
    request = copy;
  }
  

  @Override
  public void setRequestUrl(String url) {
     throw new RuntimeException(new UnsupportedOperationException());
  }

  @Override
  public Object unwrap() {
    return request;
  }

}




Java Source Code List

com.fivehundredpx.api.FiveHundredException.java
com.fivehundredpx.api.PxApi.java
com.fivehundredpx.api.auth.AccessToken.java
com.fivehundredpx.api.auth.FacebookAuthProvider.java
com.fivehundredpx.api.auth.HttpParameterUtil.java
com.fivehundredpx.api.auth.OAuthAuthorization.java
com.fivehundredpx.api.auth.OAuthConstants.java
com.fivehundredpx.api.auth.OAuthParameters.java
com.fivehundredpx.api.auth.OAuthProvider.java
com.fivehundredpx.api.auth.PlusAuthProvider.java
com.fivehundredpx.api.auth.TwitterAuthProvider.java
com.fivehundredpx.api.auth.XAuthProvider.java
com.fivehundredpx.api.tasks.UserDetailTask.java
com.fivehundredpx.api.tasks.XAuth500pxTask.java
net.darkwire.example.BaseActivity.java
net.darkwire.example.BaseSpiceActivity.java
net.darkwire.example.MainActivity.java
net.darkwire.example.ObservableApp.java
net.darkwire.example.builder.FiveHundredPxAccessToken.java
net.darkwire.example.exception.AuthenticationError.java
net.darkwire.example.model.FiveHundredPxConfiguration.java
net.darkwire.example.model.FiveHundredPxImageMetadata.java
net.darkwire.example.model.FiveHundredPxPhotoContainer.java
net.darkwire.example.model.FiveHundredPxPhoto.java
net.darkwire.example.service.CacheableSpiceRequest.java
net.darkwire.example.service.FiveHundredPxGsonSpiceService.java
net.darkwire.example.service.FiveHundredPxJacksonSpiceService.java
net.darkwire.example.service.FiveHundredPxRecentPhotosSpiceRequest.java
net.darkwire.example.service.FiveHundredPxSearchSpiceRequest.java
net.darkwire.example.service.FiveHundredPxSpiceRequest.java
net.darkwire.example.service.FiveHundredPx.java
net.darkwire.example.service.catalog.UrlCatalog.java
net.darkwire.example.service.client.FiveHundredPxClient.java
net.darkwire.example.widgets.adapter.NumericPaginationBaseAdapter.java
net.darkwire.example.widgets.adapter.NumericPagination.java
net.darkwire.example.widgets.adapter.PhotoAdapter.java
net.darkwire.example.widgets.listener.InfiniteScrollListener.java
net.darkwire.example.widgets.view.SquareImageView.java
se.akerfeldt.signpost.retrofit.HttpRequestAdapter.java
se.akerfeldt.signpost.retrofit.RetrofitHttpOAuthConsumer.java
se.akerfeldt.signpost.retrofit.SigningOkClient.java