use of org.apache.http.impl.client.BasicResponseHandler in project nanohttpd by NanoHttpd.
the class CookieIntegrationTest method testNoCookies.
@Test
public void testNoCookies() throws Exception {
HttpGet httpget = new HttpGet("http://localhost:8192/");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
this.httpclient.execute(httpget, responseHandler);
CookieStore cookies = this.httpclient.getCookieStore();
assertEquals(0, cookies.getCookies().size());
}
use of org.apache.http.impl.client.BasicResponseHandler in project nanohttpd by NanoHttpd.
the class GetAndPostIntegrationTest method testPostWithNoParameters.
@Test
public void testPostWithNoParameters() throws Exception {
this.testServer.response = "testPostWithNoParameters";
HttpPost httppost = new HttpPost("http://localhost:8192/");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = this.httpclient.execute(httppost, responseHandler);
assertEquals("POST:testPostWithNoParameters", responseBody);
}
use of org.apache.http.impl.client.BasicResponseHandler in project nanohttpd by NanoHttpd.
the class GetAndPostIntegrationTest method testPostRequestWithMultipartEncodedParameters.
@Test
public void testPostRequestWithMultipartEncodedParameters() throws Exception {
this.testServer.response = "testPostRequestWithMultipartEncodedParameters";
HttpPost httppost = new HttpPost("http://localhost:8192/");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("age", new StringBody("120"));
reqEntity.addPart("gender", new StringBody("Male"));
httppost.setEntity(reqEntity);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = this.httpclient.execute(httppost, responseHandler);
assertEquals("POST:testPostRequestWithMultipartEncodedParameters-params=2;age=120;gender=Male", responseBody);
}
use of org.apache.http.impl.client.BasicResponseHandler in project nanohttpd by NanoHttpd.
the class GetAndPostIntegrationTest method testPostRequestWithFormEncodedParameters.
@Test
public void testPostRequestWithFormEncodedParameters() throws Exception {
this.testServer.response = "testPostRequestWithFormEncodedParameters";
HttpPost httppost = new HttpPost("http://localhost:8192/");
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("age", "120"));
postParameters.add(new BasicNameValuePair("gender", "Male"));
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = this.httpclient.execute(httppost, responseHandler);
assertEquals("POST:testPostRequestWithFormEncodedParameters-params=2;age=120;gender=Male", responseBody);
}
use of org.apache.http.impl.client.BasicResponseHandler in project OpenRefine by OpenRefine.
the class RefineBroker method getUserId.
// ----------------------------------------------------------------------------------------
@SuppressWarnings("unchecked")
protected String getUserId(HttpServletRequest request) throws Exception {
// This is useful for testing
if (developmentMode) {
return getParameter(request, "uid");
}
String oauth = request.getHeader(DELEGATED_OAUTH_HEADER);
if (oauth == null) {
throw new RuntimeException("The request needs to contain the '" + DELEGATED_OAUTH_HEADER + "' header set to obtain user identity via Freebase.");
}
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
Map<String, String> params = (Map<String, String>) request.getParameterMap();
for (Entry<String, String> e : params.entrySet()) {
formparams.add(new BasicNameValuePair((String) e.getKey(), (String) e.getValue()));
}
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
HttpPost httpRequest = new HttpPost(USER_INFO_URL);
httpRequest.setHeader(OAUTH_HEADER, oauth);
httpRequest.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "OpenRefine Broker");
httpRequest.setEntity(entity);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpRequest, responseHandler);
JSONObject o = new JSONObject(responseBody);
return o.getString("username");
}
Aggregations