use of com.github.kevinsawicki.http.HttpRequest in project restfuse by eclipsesource.
the class Response_Test method mockRequest.
private HttpRequest mockRequest() throws MalformedURLException {
HttpRequest httpRequest = mock(HttpRequest.class);
HttpURLConnection connection = mock(HttpURLConnection.class);
when(connection.getURL()).thenReturn(new URL("http://test.com"));
when(httpRequest.getConnection()).thenReturn(connection);
when(httpRequest.body()).thenReturn("test");
when(httpRequest.code()).thenReturn(200);
when(httpRequest.contentType()).thenReturn(MediaType.TEXT_PLAIN.toString());
HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
List<String> values = new ArrayList<String>();
values.add("test");
headers.put("test", values);
when(httpRequest.headers()).thenReturn(headers);
return httpRequest;
}
use of com.github.kevinsawicki.http.HttpRequest in project restfuse by eclipsesource.
the class InternalRequest method put.
public Response put() {
HttpRequest request = HttpRequest.put(url);
addContentType(request);
addHeaders(request);
addAuthentication(request);
request.send(content);
sendRequest(request);
return new ResponseImpl(request);
}
use of com.github.kevinsawicki.http.HttpRequest in project restfuse by eclipsesource.
the class InternalRequest method options.
public Response options() {
HttpRequest request = HttpRequest.options(url);
addContentType(request);
addHeaders(request);
addAuthentication(request);
sendRequest(request);
return new ResponseImpl(request);
}
use of com.github.kevinsawicki.http.HttpRequest in project restfuse by eclipsesource.
the class InternalRequest method delete.
public Response delete() {
HttpRequest request = HttpRequest.delete(url);
addContentType(request);
addHeaders(request);
addAuthentication(request);
sendRequest(request);
return new ResponseImpl(request);
}
use of com.github.kevinsawicki.http.HttpRequest in project scdl by passy.
the class AbstractSoundcloudApiQueryImpl method executePost.
/**
* Executes the POST request. Instead of using the bare HttpURLConnection
* API, we use our modified HttpRequest client to be able to upload with
* multipart and other cool things.
*
* @return
* @throws APIException
*/
protected HttpURLConnection executePost() throws APIException {
Ln.d("Executing POST against URL " + mUrl.toString());
final HttpRequest request = HttpRequest.post(mUrl);
setupPostRequest(request);
if (mSendCallback != null) {
request.setSendCallback(mSendCallback);
}
if (mPartParameters.size() > 0) {
applyPostParametersAsPart(request);
applyPartParameters(request);
} else {
applyPostParameters(request);
}
try {
request.closeOutput();
} catch (final IOException e) {
throw new APIException(e, -1);
}
return request.getConnection();
}
Aggregations