Example usage for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity

List of usage examples for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity.

Prototype

public InputStreamRequestEntity(InputStream paramInputStream) 

Source Link

Usage

From source file:org.springframework.ws.transport.http.WebServiceHttpHandlerIntegrationTest.java

@Test
public void testResponse() throws IOException {
    PostMethod postMethod = new PostMethod(url);
    postMethod.addRequestHeader(HttpTransportConstants.HEADER_CONTENT_TYPE, "text/xml");
    postMethod.addRequestHeader(TransportConstants.HEADER_SOAP_ACTION,
            "http://springframework.org/spring-ws/Response");
    Resource soapRequest = new ClassPathResource("soapRequest.xml", WebServiceHttpHandlerIntegrationTest.class);
    postMethod.setRequestEntity(new InputStreamRequestEntity(soapRequest.getInputStream()));
    client.executeMethod(postMethod);/*  w ww. j  a  va  2  s.c  o  m*/
    assertEquals("Invalid Response Code", HttpTransportConstants.STATUS_OK, postMethod.getStatusCode());
    assertTrue("No Response retrieved", postMethod.getResponseContentLength() > 0);
}

From source file:org.springframework.ws.transport.http.WebServiceHttpHandlerIntegrationTest.java

@Test
public void testNoEndpoint() throws IOException {
    PostMethod postMethod = new PostMethod(url);
    postMethod.addRequestHeader(HttpTransportConstants.HEADER_CONTENT_TYPE, "text/xml");
    postMethod.addRequestHeader(TransportConstants.HEADER_SOAP_ACTION,
            "http://springframework.org/spring-ws/NoEndpoint");
    Resource soapRequest = new ClassPathResource("soapRequest.xml", WebServiceHttpHandlerIntegrationTest.class);
    postMethod.setRequestEntity(new InputStreamRequestEntity(soapRequest.getInputStream()));
    client.executeMethod(postMethod);//from  w w  w  .j a  va 2 s .c o m
    assertEquals("Invalid Response Code", HttpTransportConstants.STATUS_NOT_FOUND, postMethod.getStatusCode());
    assertEquals("Response retrieved", 0, postMethod.getResponseContentLength());
}

From source file:org.springframework.ws.transport.http.WebServiceHttpHandlerIntegrationTest.java

@Test
public void testFault() throws IOException {
    PostMethod postMethod = new PostMethod(url);
    postMethod.addRequestHeader(HttpTransportConstants.HEADER_CONTENT_TYPE, "text/xml");
    postMethod.addRequestHeader(TransportConstants.HEADER_SOAP_ACTION,
            "http://springframework.org/spring-ws/Fault");
    Resource soapRequest = new ClassPathResource("soapRequest.xml", WebServiceHttpHandlerIntegrationTest.class);
    postMethod.setRequestEntity(new InputStreamRequestEntity(soapRequest.getInputStream()));
    client.executeMethod(postMethod);//w ww .  j av  a2 s .c o m
    assertEquals("Invalid Response Code", HttpTransportConstants.STATUS_INTERNAL_SERVER_ERROR,
            postMethod.getStatusCode());
    assertTrue("No Response retrieved", postMethod.getResponseContentLength() > 0);
}

From source file:org.talend.mdm.bulkload.client.BulkloadClientUtil.java

public static void bulkload(String url, String cluster, String concept, String datamodel, boolean validate,
        boolean smartpk, boolean insertonly, InputStream itemdata, String username, String password,
        String transactionId, String sessionId, String universe, String tokenKey, String tokenValue)
        throws Exception {
    HostConfiguration config = new HostConfiguration();
    URI uri = new URI(url, false, "UTF-8"); //$NON-NLS-1$
    config.setHost(uri);//from   w  w  w. ja v a2s. co m

    NameValuePair[] parameters = { new NameValuePair("cluster", cluster), //$NON-NLS-1$
            new NameValuePair("concept", concept), //$NON-NLS-1$
            new NameValuePair("datamodel", datamodel), //$NON-NLS-1$
            new NameValuePair("validate", String.valueOf(validate)), //$NON-NLS-1$
            new NameValuePair("action", "load"), //$NON-NLS-1$ //$NON-NLS-2$
            new NameValuePair("smartpk", String.valueOf(smartpk)), //$NON-NLS-1$
            new NameValuePair("insertonly", String.valueOf(insertonly)) }; //$NON-NLS-1$

    HttpClient client = new HttpClient();
    String user = universe == null || universe.trim().length() == 0 ? username : universe + "/" + username; //$NON-NLS-1$
    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
    HttpClientParams clientParams = client.getParams();
    clientParams.setAuthenticationPreemptive(true);
    clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);

    PutMethod putMethod = new PutMethod();
    // This setPath call is *really* important (if not set, request will be sent to the JBoss root '/')
    putMethod.setPath(url);
    String responseBody;
    try {
        // Configuration
        putMethod.setRequestHeader("Content-Type", "text/xml; charset=utf8"); //$NON-NLS-1$ //$NON-NLS-2$
        if (transactionId != null) {
            putMethod.setRequestHeader("transaction-id", transactionId); //$NON-NLS-1$
        }
        if (sessionId != null) {
            putMethod.setRequestHeader("Cookie", STICKY_SESSION + "=" + sessionId); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (tokenKey != null && tokenValue != null) {
            putMethod.setRequestHeader(tokenKey, tokenValue);
        }

        putMethod.setQueryString(parameters);
        putMethod.setContentChunked(true);
        // Set the content of the PUT request
        putMethod.setRequestEntity(new InputStreamRequestEntity(itemdata));

        client.executeMethod(config, putMethod);
        responseBody = putMethod.getResponseBodyAsString();
        if (itemdata instanceof InputStreamMerger) {
            ((InputStreamMerger) itemdata).setAlreadyProcessed(true);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        putMethod.releaseConnection();
    }

    int statusCode = putMethod.getStatusCode();
    if (statusCode >= 500) {
        throw new BulkloadException(responseBody);
    } else if (statusCode >= 400) {
        throw new BulkloadException("Could not send data to MDM (HTTP status code: " + statusCode + ")."); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:org.tuckey.web.filters.urlrewrite.RequestProxy.java

private static HttpMethod setupProxyRequest(final HttpServletRequest hsRequest, final URL targetUrl)
        throws IOException {
    final String methodName = hsRequest.getMethod();
    final HttpMethod method;
    if ("POST".equalsIgnoreCase(methodName)) {
        PostMethod postMethod = new PostMethod();
        InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity(
                hsRequest.getInputStream());
        postMethod.setRequestEntity(inputStreamRequestEntity);
        method = postMethod;//from  w ww  .jav a 2s.c om
    } else if ("GET".equalsIgnoreCase(methodName)) {
        method = new GetMethod();
    } else if ("PUT".equalsIgnoreCase(methodName)) {
        PutMethod putMethod = new PutMethod();
        InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity(
                hsRequest.getInputStream());
        putMethod.setRequestEntity(inputStreamRequestEntity);
        method = putMethod;
    } else if ("DELETE".equalsIgnoreCase(methodName)) {
        method = new DeleteMethod();
    } else {
        log.warn("Unsupported HTTP method requested: " + hsRequest.getMethod());
        return null;
    }

    method.setFollowRedirects(false);
    method.setPath(targetUrl.getPath());
    method.setQueryString(targetUrl.getQuery());

    Enumeration e = hsRequest.getHeaderNames();
    if (e != null) {
        while (e.hasMoreElements()) {
            String headerName = (String) e.nextElement();
            if ("host".equalsIgnoreCase(headerName)) {
                //the host value is set by the http client
                continue;
            } else if ("content-length".equalsIgnoreCase(headerName)) {
                //the content-length is managed by the http client
                continue;
            } else if ("accept-encoding".equalsIgnoreCase(headerName)) {
                //the accepted encoding should only be those accepted by the http client.
                //The response stream should (afaik) be deflated. If our http client does not support
                //gzip then the response can not be unzipped and is delivered wrong.
                continue;
            } else if (headerName.toLowerCase().startsWith("cookie")) {
                //fixme : don't set any cookies in the proxied request, this needs a cleaner solution
                continue;
            }

            Enumeration values = hsRequest.getHeaders(headerName);
            while (values.hasMoreElements()) {
                String headerValue = (String) values.nextElement();
                log.info("setting proxy request parameter:" + headerName + ", value: " + headerValue);
                method.addRequestHeader(headerName, headerValue);
            }
        }
    }

    if (log.isInfoEnabled())
        log.info("proxy query string " + method.getQueryString());
    return method;
}

From source file:org.wso2.carbon.mashup.javascript.hostobjects.pooledhttpclient.PooledHttpClientHostObject.java

/**
 * Used by jsFunction_executeMethod().//from  w w w  .ja v  a2  s.c o  m
 * 
 * @param httpClient
 * @param contentType
 * @param charset
 * @param methodName
 * @param content
 * @param params
 */
private static void setParams(PooledHttpClientHostObject httpClient, HttpMethod method, String contentType,
        String charset, String methodName, Object content, NativeObject params) {
    // other parameters have been set, they are properly set to the
    // corresponding context
    if (ScriptableObject.getProperty(params, "cookiePolicy") instanceof String) {
        method.getParams().setCookiePolicy((String) ScriptableObject.getProperty(params, "cookiePolicy"));
    } else if (!ScriptableObject.getProperty(params, "cookiePolicy").equals(UniqueTag.NOT_FOUND)) {
        throw new RuntimeException("Method parameters should be Strings");
    }

    if (ScriptableObject.getProperty(params, "contentType") instanceof String) {
        contentType = (String) ScriptableObject.getProperty(params, "contentType");
    } else if (!ScriptableObject.getProperty(params, "contentType").equals(UniqueTag.NOT_FOUND)) {
        throw new RuntimeException("Method parameters should be Strings");
    }

    if (ScriptableObject.getProperty(params, "charset") instanceof String) {
        charset = (String) ScriptableObject.getProperty(params, "charset");
    } else if (!ScriptableObject.getProperty(params, "charset").equals(UniqueTag.NOT_FOUND)) {
        throw new RuntimeException("Method parameters should be Strings");
    }

    if (ScriptableObject.getProperty(params, "timeout") instanceof Integer) {
        method.getParams().setSoTimeout((Integer) ScriptableObject.getProperty(params, "timeout"));
    } else if (!ScriptableObject.getProperty(params, "timeout").equals(UniqueTag.NOT_FOUND)) {
        throw new RuntimeException("Method parameters should be Strings");
    }

    if (ScriptableObject.getProperty(params, "doAuthentication") instanceof Boolean) {
        method.setDoAuthentication((Boolean) ScriptableObject.getProperty(params, "doAuthentication"));
    } else if (!ScriptableObject.getProperty(params, "doAuthentication").equals(UniqueTag.NOT_FOUND)) {
        throw new RuntimeException("Method parameters should be Strings");
    }

    if (ScriptableObject.getProperty(params, "followRedirect") instanceof Boolean) {
        method.setFollowRedirects((Boolean) ScriptableObject.getProperty(params, "followRedirect"));
    } else if (!ScriptableObject.getProperty(params, "followRedirect").equals(UniqueTag.NOT_FOUND)) {
        throw new RuntimeException("Method parameters should be Strings");
    }

    if (methodName.equals("POST")) {
        // several parameters are specific to POST method
        if (ScriptableObject.getProperty(params, "contentChunked") instanceof Boolean) {
            boolean chuncked = (Boolean) ScriptableObject.getProperty(params, "contentChunked");
            ((PostMethod) method).setContentChunked(chuncked);
            if (chuncked && content != null) {
                // if contentChucked is set true, then
                // InputStreamRequestEntity or
                // MultipartRequestEntity is used
                if (content instanceof String) {
                    // InputStreamRequestEntity for string content
                    ((PostMethod) method).setRequestEntity(new InputStreamRequestEntity(
                            new ByteArrayInputStream(((String) content).getBytes())));
                } else {
                    // MultipartRequestEntity for Name-Value pair
                    // content
                    NativeObject element;
                    List<StringPart> parts = new ArrayList<StringPart>();
                    String eName;
                    String eValue;
                    // create pairs using name-value pairs
                    for (int i = 0; i < ((NativeArray) content).getLength(); i++) {
                        if (((NativeArray) content).get(i, (NativeArray) content) instanceof NativeObject) {
                            element = (NativeObject) ((NativeArray) content).get(i, (NativeArray) content);
                            if (ScriptableObject.getProperty(element, "name") instanceof String
                                    && ScriptableObject.getProperty(element, "value") instanceof String) {
                                eName = (String) ScriptableObject.getProperty(element, "name");
                                eValue = (String) ScriptableObject.getProperty(element, "value");
                                parts.add(new StringPart(eName, eValue));
                            } else {
                                throw new RuntimeException("Invalid content definition, objects of the content"
                                        + " array should consists with strings for both key/value");
                            }

                        } else {
                            throw new RuntimeException(
                                    "Invalid content definition, content array should contain "
                                            + "Javascript Objects");
                        }
                    }
                    ((PostMethod) method).setRequestEntity(new MultipartRequestEntity(
                            parts.toArray(new Part[parts.size()]), method.getParams()));
                }
            }

        } else if (ScriptableObject.getProperty(params, "contentChunked").equals(UniqueTag.NOT_FOUND)
                && content != null) {
            // contentChunking has not used
            if (content instanceof String) {
                try {
                    ((PostMethod) method)
                            .setRequestEntity(new StringRequestEntity((String) content, contentType, charset));
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException("Unsupported Charset");
                }
            } else {
                NativeObject element;
                List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                String eName;
                String eValue;
                // create pairs using name-value pairs
                for (int i = 0; i < ((NativeArray) content).getLength(); i++) {
                    if (((NativeArray) content).get(i, (NativeArray) content) instanceof NativeObject) {
                        element = (NativeObject) ((NativeArray) content).get(i, (NativeArray) content);
                        if (ScriptableObject.getProperty(element, "name") instanceof String
                                && ScriptableObject.getProperty(element, "value") instanceof String) {
                            eName = (String) ScriptableObject.getProperty(element, "name");
                            eValue = (String) ScriptableObject.getProperty(element, "value");
                            pairs.add(new NameValuePair(eName, eValue));
                        } else {
                            throw new RuntimeException(
                                    "Invalid content definition, objects of the content array "
                                            + "should consists with strings for both key/value");
                        }

                    } else {
                        throw new RuntimeException("Invalid content definition, content array should contain "
                                + "Javascript Objects");
                    }
                }
                ((PostMethod) method).setRequestBody(pairs.toArray(new NameValuePair[pairs.size()]));
            }
        } else if (!ScriptableObject.getProperty(params, "contentChunked").equals(UniqueTag.NOT_FOUND)) {
            throw new RuntimeException("Method parameters should be Strings");
        }

    } else if (methodName.equals("GET")) {
        // here, the method now is GET
        if (content != null) {
            if (content instanceof String) {
                method.setQueryString((String) content);
            } else {
                NativeObject element;
                List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                String eName;
                String eValue;
                // create pairs using name-value pairs
                for (int i = 0; i < ((NativeArray) content).getLength(); i++) {
                    if (((NativeArray) content).get(i, (NativeArray) content) instanceof NativeObject) {
                        element = (NativeObject) ((NativeArray) content).get(i, (NativeArray) content);
                        if (ScriptableObject.getProperty(element, "name") instanceof String
                                && ScriptableObject.getProperty(element, "value") instanceof String) {
                            eName = (String) ScriptableObject.getProperty(element, "name");
                            eValue = (String) ScriptableObject.getProperty(element, "value");
                            pairs.add(new NameValuePair(eName, eValue));
                        } else {
                            throw new RuntimeException(
                                    "Invalid content definition, objects of the content array "
                                            + "should consists with strings for both key/value");
                        }

                    } else {
                        throw new RuntimeException("Invalid content definition, content array should contain "
                                + "Javascript Objects");
                    }
                }
                method.setQueryString(pairs.toArray(new NameValuePair[pairs.size()]));
            }
        }
    } else if (methodName.equals("PUT")) {
        // several parameters are specific to PUT method
        if (ScriptableObject.getProperty(params, "contentChunked") instanceof Boolean) {
            boolean chuncked = (Boolean) ScriptableObject.getProperty(params, "contentChunked");
            ((PutMethod) method).setContentChunked(chuncked);
            if (chuncked && content != null) {
                // if contentChucked is set true, then
                // InputStreamRequestEntity or
                // MultipartRequestEntity is used
                if (content instanceof String) {
                    // InputStreamRequestEntity for string content
                    ((PostMethod) method).setRequestEntity(new InputStreamRequestEntity(
                            new ByteArrayInputStream(((String) content).getBytes())));
                } else {
                    throw new RuntimeException(
                            "Invalid content definition, content should be a string when PUT "
                                    + "method is used");
                }
            }

        } else if (ScriptableObject.getProperty(params, "contentChunked").equals(UniqueTag.NOT_FOUND)
                && content != null) {
            // contentChunking has not used
            if (content instanceof String) {
                try {
                    ((PostMethod) method)
                            .setRequestEntity(new StringRequestEntity((String) content, contentType, charset));
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException("Unsupported Charset");
                }
            } else {
                throw new RuntimeException(
                        "Invalid content definition, content should be a string when PUT " + "method is used");
            }
        } else if (!ScriptableObject.getProperty(params, "contentChunked").equals(UniqueTag.NOT_FOUND)) {
            throw new RuntimeException("Method parameters should be Strings");
        }

    }

    // check whether preemptive authentication is used
    if (ScriptableObject.getProperty(params, "preemptiveAuth") instanceof Boolean) {
        httpClient.httpClient.getParams()
                .setAuthenticationPreemptive((Boolean) ScriptableObject.getProperty(params, "preemptiveAuth"));
    } else if (!ScriptableObject.getProperty(params, "preemptiveAuth").equals(UniqueTag.NOT_FOUND)) {
        throw new RuntimeException("Method parameters should be Strings");
    }
}

From source file:org.xwiki.test.rest.framework.AbstractHttpTest.java

protected PostMethod executePost(String uri, InputStream is, String userName, String password)
        throws Exception {
    HttpClient httpClient = new HttpClient();
    httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
    httpClient.getParams().setAuthenticationPreemptive(true);

    PostMethod postMethod = new PostMethod(uri);
    postMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());

    RequestEntity entity = new InputStreamRequestEntity(is);
    postMethod.setRequestEntity(entity);

    httpClient.executeMethod(postMethod);

    return postMethod;
}

From source file:org.xwiki.test.webdav.AbstractWebDAVTest.java

/**
 * Tests the PUT method on the given url.
 * //  w w w .  j  a  v a 2  s .  co  m
 * @param url the target url.
 * @param the content for the {@link PutMethod}.
 * @param expect the return status expected.
 * @return the {@link HttpMethod} which contains the response.
 */
protected HttpMethod put(String url, String content, int expect) {
    PutMethod putMethod = new PutMethod();
    putMethod.setDoAuthentication(true);
    putMethod.setPath(url);
    putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(content.getBytes())));
    testMethod(putMethod, expect);
    return putMethod;
}

From source file:org.xwiki.test.webdav.DefaultWebDAVTest.java

/**
 * Test update page content.//from  ww  w. j  av  a  2s .  c om
 */
public void testUpdatePageWikiContent() {
    String spaceUrl = SPACES + "/TestSpace";
    String pageUrl = spaceUrl + "/TestPage";
    String wikiTextFileUrl = pageUrl + "/wiki.txt";
    String wikiXMLFileUrl = pageUrl + "/wiki.xml";
    String newContent = "New Content";
    DeleteMethod deleteMethod = new DeleteMethod();
    deleteMethod.setDoAuthentication(true);
    MkcolMethod mkColMethod = new MkcolMethod();
    mkColMethod.setDoAuthentication(true);
    PutMethod putMethod = new PutMethod();
    putMethod.setDoAuthentication(true);
    GetMethod getMethod = new GetMethod();
    getMethod.setDoAuthentication(true);
    try {
        deleteMethod.setPath(spaceUrl);
        assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
        mkColMethod.setPath(spaceUrl);
        assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
        mkColMethod.setPath(pageUrl);
        assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
        putMethod.setPath(wikiTextFileUrl);
        putMethod.setRequestEntity(
                new InputStreamRequestEntity(new ByteArrayInputStream(newContent.getBytes())));
        // Already existing resource, in which case SC_NO_CONTENT will be the return status.
        assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(putMethod));
        getMethod.setPath(wikiTextFileUrl);
        assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod));
        assertEquals(newContent, getMethod.getResponseBodyAsString());
        putMethod.setPath(wikiXMLFileUrl);
        putMethod.setRequestEntity(
                new InputStreamRequestEntity(new ByteArrayInputStream(newContent.getBytes())));
        // XML saving was disabled recently. See http://jira.xwiki.org/jira/browse/XWIKI-2910
        assertEquals(DavServletResponse.SC_METHOD_NOT_ALLOWED, getHttpClient().executeMethod(putMethod));
        deleteMethod.setPath(pageUrl);
        assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
        deleteMethod.setPath(spaceUrl);
        assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
    } catch (HttpException ex) {
        fail(ex.getMessage());
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
}

From source file:org.xwiki.test.webdav.DefaultWebDAVTest.java

/**
 * Test making attachment./*  www .j  a v  a 2  s.c o  m*/
 */
public void testMakingAttachment() {
    String spaceUrl = SPACES + "/TestSpace";
    String pageUrl = spaceUrl + "/TestPage";
    String attachmentUrl = pageUrl + "/attachment.txt";
    String attachmentContent = "Attachment Content";
    DeleteMethod deleteMethod = new DeleteMethod();
    deleteMethod.setDoAuthentication(true);
    MkcolMethod mkColMethod = new MkcolMethod();
    mkColMethod.setDoAuthentication(true);
    PutMethod putMethod = new PutMethod();
    putMethod.setDoAuthentication(true);
    GetMethod getMethod = new GetMethod();
    getMethod.setDoAuthentication(true);
    try {
        deleteMethod.setPath(spaceUrl);
        assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
        mkColMethod.setPath(spaceUrl);
        assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
        mkColMethod.setPath(pageUrl);
        assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
        getMethod.setPath(attachmentUrl);
        assertEquals(DavServletResponse.SC_NOT_FOUND, getHttpClient().executeMethod(getMethod));
        putMethod.setPath(attachmentUrl);
        putMethod.setRequestEntity(
                new InputStreamRequestEntity(new ByteArrayInputStream(attachmentContent.getBytes())));
        assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(putMethod));
        getMethod.setPath(attachmentUrl);
        assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod));
        assertEquals(attachmentContent, getMethod.getResponseBodyAsString());
        deleteMethod.setPath(attachmentUrl);
        assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
        deleteMethod.setPath(pageUrl);
        assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
        deleteMethod.setPath(spaceUrl);
        assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
    } catch (HttpException ex) {
        fail(ex.getMessage());
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
}