use of org.apache.commons.httpclient.methods.StringRequestEntity in project alfresco-remote-api by Alfresco.
the class PublicApiHttpClient method post.
public HttpResponse post(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation, final String body) throws IOException {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null);
String url = endpoint.getUrl();
PostMethod req = new PostMethod(url.toString());
if (body != null) {
StringRequestEntity requestEntity = null;
if (cmisBinding.equals(Binding.atom)) {
requestEntity = new StringRequestEntity(body, "text/xml", "UTF-8");
} else if (cmisBinding.equals(Binding.browser)) {
requestEntity = new StringRequestEntity(body, "application/json", "UTF-8");
}
req.setRequestEntity(requestEntity);
}
return submitRequest(req, rq);
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project alfresco-remote-api by Alfresco.
the class PublicApiHttpClient method post.
public HttpResponse post(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId, final String relationCollectionName, final Object relationshipEntityId, final String body, String contentType, final Map<String, String> params) throws IOException {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params);
String url = endpoint.getUrl();
PostMethod req = new PostMethod(url.toString());
if (body != null) {
if (contentType == null || contentType.isEmpty()) {
contentType = "application/json";
}
StringRequestEntity requestEntity = new StringRequestEntity(body, contentType, "UTF-8");
req.setRequestEntity(requestEntity);
}
return submitRequest(req, rq);
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project alfresco-remote-api by Alfresco.
the class PublicApiHttpClient method post.
public HttpResponse post(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId, final String body) throws IOException {
RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, null);
String url = endpoint.getUrl();
PostMethod req = new PostMethod(url.toString());
if (body != null) {
StringRequestEntity requestEntity = new StringRequestEntity(body, "application/json", "UTF-8");
req.setRequestEntity(requestEntity);
}
return submitRequest(req, rq);
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestBasicAuth method testPutBasicAuthentication.
public void testPutBasicAuthentication() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new EchoService()));
HttpState state = new HttpState();
AuthScope authscope = new AuthScope(this.server.getLocalAddress(), this.server.getLocalPort(), "test");
state.setCredentials(authscope, creds);
this.client.setState(state);
this.server.setRequestHandler(handlerchain);
PutMethod put = new PutMethod("/test/");
put.setRequestEntity(new StringRequestEntity("Test body"));
try {
this.client.executeMethod(put);
assertEquals("Test body", put.getResponseBodyAsString());
} finally {
put.releaseConnection();
}
assertNotNull(put.getStatusLine());
assertEquals(HttpStatus.SC_OK, put.getStatusLine().getStatusCode());
Header auth = put.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
assertEquals(expected, auth.getValue());
AuthState authstate = put.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestPostParameterEncoding method testPostSetRequestBody.
public void testPostSetRequestBody() throws Exception {
PostMethod post = new PostMethod("/foo");
String body = "this+is+the+body";
post.setRequestEntity(new StringRequestEntity(body));
assertEquals(body, getRequestAsString(post.getRequestEntity()));
}
Aggregations