use of org.apache.commons.httpclient.methods.PutMethod in project tdi-studio-se by Talend.
the class MDMTransactionClient method newTransaction.
public static MDMTransaction newTransaction(String url, String username, String password) throws IOException {
HttpClient client = new HttpClient();
client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
client.getParams().setAuthenticationPreemptive(true);
PutMethod put = new PutMethod(url);
put.setDoAuthentication(true);
String tid;
String sessionID;
try {
client.executeMethod(put);
tid = put.getResponseBodyAsString();
sessionID = parseSessionID(put);
} catch (HttpException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
put.releaseConnection();
}
MDMTransaction result = new MDMTransaction();
result.setUrl(url);
result.setId(tid);
result.setUsername(username);
result.setPassword(password);
result.setSessionId(sessionID);
return result;
}
use of org.apache.commons.httpclient.methods.PutMethod in project zm-mailbox by Zimbra.
the class TestCalDav method testCreateContactWithIfNoneMatchTesting.
@Test
public void testCreateContactWithIfNoneMatchTesting() throws ServiceException, IOException {
Account dav1 = users[1].create();
// Based on UID
String davBaseName = "SCRUFF1.vcf";
String contactsFolderUrl = getFolderUrl(dav1, "Contacts");
String url = String.format("%s%s", contactsFolderUrl, davBaseName);
HttpClient client = new HttpClient();
PutMethod putMethod = new PutMethod(url);
addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addRequestHeader("Content-Type", "text/vcard");
putMethod.setRequestEntity(new ByteArrayRequestEntity(simpleVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
// Bug 84246 this used to fail with 409 Conflict because we used to require an If-None-Match header
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_CREATED);
// Check that trying to put the same thing again when we don't expect it to exist (i.e. Using If-None-Match
// header) will fail.
putMethod = new PutMethod(url);
addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addRequestHeader("Content-Type", "text/vcard");
putMethod.addRequestHeader(DavProtocol.HEADER_IF_NONE_MATCH, "*");
putMethod.setRequestEntity(new ByteArrayRequestEntity(simpleVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_PRECONDITION_FAILED);
}
use of org.apache.commons.httpclient.methods.PutMethod in project camel by apache.
the class HttpRouteTest method testPutParameterInURI.
@Test
public void testPutParameterInURI() throws Exception {
HttpClient client = new HttpClient();
PutMethod put = new PutMethod("http://localhost:" + port1 + "/parameter?request=PutParameter&others=bloggs");
StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8");
put.setRequestEntity(entity);
client.executeMethod(put);
InputStream response = put.getResponseBodyAsStream();
String out = context.getTypeConverter().convertTo(String.class, response);
assertEquals("Get a wrong output ", "PutParameter", out);
}
use of org.apache.commons.httpclient.methods.PutMethod in project sling by apache.
the class PutMethodServletTest method testPutMethodServletDefaultRT.
public void testPutMethodServletDefaultRT() throws Exception {
final PutMethod put = new PutMethod(testNodeNORT.nodeUrl);
final int status = httpClient.executeMethod(put);
assertFalse("PUT to testNodeRT should not return 200", 200 == status);
}
use of org.apache.commons.httpclient.methods.PutMethod in project fabric8 by jboss-fuse.
the class ProxyServlet method doPut.
/**
* Performs an HTTP PUT request
*
* @param httpServletRequest The {@link javax.servlet.http.HttpServletRequest} object passed
* in by the servlet engine representing the
* client request to be proxied
* @param httpServletResponse The {@link javax.servlet.http.HttpServletResponse} object by which
* we can send a proxied response to the client
*/
@Override
public void doPut(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
ProxyDetails proxyDetails = createProxyDetails(httpServletRequest, httpServletResponse);
if (!proxyDetails.isValid()) {
noMappingFound(httpServletRequest, httpServletResponse);
} else {
PutMethod putMethodProxyRequest = new PutMethod(proxyDetails.getStringProxyURL());
setProxyRequestHeaders(proxyDetails, httpServletRequest, putMethodProxyRequest);
if (ServletFileUpload.isMultipartContent(httpServletRequest)) {
handleMultipartPost(putMethodProxyRequest, httpServletRequest);
} else {
handleEntity(putMethodProxyRequest, httpServletRequest);
}
executeProxyRequest(proxyDetails, putMethodProxyRequest, httpServletRequest, httpServletResponse);
}
}
Aggregations