Search in sources :

Example 1 with PutMethod

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;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) PutMethod(org.apache.commons.httpclient.methods.PutMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 2 with PutMethod

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);
}
Also used : Account(com.zimbra.cs.account.Account) HttpClient(org.apache.commons.httpclient.HttpClient) PutMethod(org.apache.commons.httpclient.methods.PutMethod) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) Test(org.junit.Test)

Example 3 with PutMethod

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);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Test(org.junit.Test)

Example 4 with PutMethod

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);
}
Also used : PutMethod(org.apache.commons.httpclient.methods.PutMethod)

Example 5 with PutMethod

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);
    }
}
Also used : PutMethod(org.apache.commons.httpclient.methods.PutMethod)

Aggregations

PutMethod (org.apache.commons.httpclient.methods.PutMethod)92 Test (org.junit.Test)49 GetMethod (org.apache.commons.httpclient.methods.GetMethod)27 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)21 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)19 Page (org.xwiki.rest.model.jaxb.Page)15 HttpClient (org.apache.commons.httpclient.HttpClient)14 IOException (java.io.IOException)13 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)13 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)10 PostMethod (org.apache.commons.httpclient.methods.PostMethod)8 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)7 DeleteMethod (org.apache.jackrabbit.webdav.client.methods.DeleteMethod)7 Link (org.xwiki.rest.model.jaxb.Link)7 Header (org.apache.commons.httpclient.Header)6 FileRequestEntity (org.apache.commons.httpclient.methods.FileRequestEntity)6 File (java.io.File)5 HttpMethod (org.apache.commons.httpclient.HttpMethod)5 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)5 Object (org.xwiki.rest.model.jaxb.Object)5