All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.belladati.sdk.impl.oauth.BellaDatiHttpRequestAdapter Maven / Gradle / Ivy

Go to download

The BellaDati SDK allows accessing a BellaDati server from 3rd-party applications using Java. This project contains the implementation for Android.

There is a newer version: 0.9.7
Show newest version
package com.belladati.sdk.impl.oauth;

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

import oauth.signpost.http.HttpRequest;

import com.belladati.httpclientandroidlib.Header;
import com.belladati.httpclientandroidlib.HttpEntity;
import com.belladati.httpclientandroidlib.HttpEntityEnclosingRequest;
import com.belladati.httpclientandroidlib.client.methods.HttpUriRequest;

public class BellaDatiHttpRequestAdapter implements HttpRequest {

	private HttpUriRequest request;

	private HttpEntity entity;

	public BellaDatiHttpRequestAdapter(HttpUriRequest request) {
		this.request = request;
		if (request instanceof HttpEntityEnclosingRequest) {
			entity = ((HttpEntityEnclosingRequest) request).getEntity();
		}
	}

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

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

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

	@Override
	public String getHeader(String name) {
		Header header = request.getFirstHeader(name);
		if (header == null) {
			return null;
		}
		return header.getValue();
	}

	@Override
	public void setHeader(String name, String value) {
		request.setHeader(name, value);
	}

	@Override
	public Map getAllHeaders() {
		Header[] origHeaders = request.getAllHeaders();
		HashMap headers = new HashMap();
		for (Header h : origHeaders) {
			headers.put(h.getName(), h.getValue());
		}
		return headers;
	}

	@Override
	public String getContentType() {
		if (entity == null) {
			return null;
		}
		Header header = entity.getContentType();
		if (header == null) {
			return null;
		}
		return header.getValue();
	}

	@Override
	public InputStream getMessagePayload() throws IOException {
		if (entity == null) {
			return null;
		}
		return entity.getContent();
	}

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy