Example usage for org.apache.commons.httpclient.methods RequestEntity writeRequest

List of usage examples for org.apache.commons.httpclient.methods RequestEntity writeRequest

Introduction

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

Prototype

public abstract void writeRequest(OutputStream paramOutputStream) throws IOException;

Source Link

Usage

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3EntityExtractor.java

private static String entityUtilsToString(final RequestEntity entity, final String charSet) throws Exception {
    final FixedByteArrayOutputStream outStream = new FixedByteArrayOutputStream(MAX_READ_SIZE);
    entity.writeRequest(outStream);
    final String entityValue = outStream.toString(charSet);
    if (entity.getContentLength() > MAX_READ_SIZE) {
        StringBuilder sb = new StringBuilder();
        sb.append(entityValue);//from  w w w  .  j ava 2s. co  m
        sb.append(" (HTTP entity is large. length: ");
        sb.append(entity.getContentLength());
        sb.append(" )");
        return sb.toString();
    }

    return entityValue;
}

From source file:com.eviware.soapui.impl.wsdl.submit.filters.HttpCompressionRequestFilter.java

@Override
public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> httpRequest) {
    Settings settings = httpRequest.getSettings();
    String compressionAlg = settings.getString(HttpSettings.REQUEST_COMPRESSION, "None");
    if (!"None".equals(compressionAlg)) {
        try {//  ww w .java  2  s . c o  m
            ExtendedHttpMethod method = (ExtendedHttpMethod) context
                    .getProperty(BaseHttpRequestTransport.HTTP_METHOD);
            if (method instanceof EntityEnclosingMethod) {
                RequestEntity requestEntity = method.getRequestEntity();
                if (requestEntity != null) {
                    ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
                    requestEntity.writeRequest(tempOut);

                    byte[] compressedData = CompressionSupport.compress(compressionAlg, tempOut.toByteArray());
                    ((EntityEnclosingMethod) method)
                            .setRequestEntity(new ByteArrayRequestEntity(compressedData));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.hp.alm.ali.idea.rest.RestServiceTest.java

private String asString(RequestEntity requestEntity) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/*  www  .j  av a  2s.  c o m*/
        requestEntity.writeRequest(baos);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return baos.toString();
}

From source file:org.apache.abdera.test.client.util.MultipartRelatedRequestEntityTest.java

License:asdf

@Test
public void testMultipartFormat() throws IOException {
    Entry entry = new FOMEntry();
    entry.setTitle("my image");
    entry.addAuthor("david");
    entry.setId("tag:apache.org,2008:234534344");
    entry.setSummary("multipart test");
    entry.setContent(new IRI("cid:234234@example.com"), "image/jpg");
    RequestEntity request = new MultipartRelatedRequestEntity(entry,
            this.getClass().getResourceAsStream("info.png"), "image/jpg", "asdfasdfasdf");

    StringWriter sw = new StringWriter();
    WriterOutputStream os = new WriterOutputStream(sw);
    request.writeRequest(os);

    String multipart = sw.toString();
    // System.out.println(sw.toString());

    assertTrue(multipart.contains("content-id: <234234@example.com>"));
    assertTrue(multipart.contains("content-type: image/jpg"));
}

From source file:org.apache.servicemix.http.HttpSpringTest.java

public void testMimeWithHttpClient() throws Exception {
    File f = new File(getClass().getResource("servicemix.jpg").getFile());
    PostMethod filePost = new PostMethod("http://localhost:18192/Service/");
    Part[] parts = { new StringPart("request", "<dummy/>"), new FilePart(f.getName(), f) };
    RequestEntity entity = new MultipartRequestEntity(parts, filePost.getParams());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    entity.writeRequest(baos);
    logger.info(baos);//from   w w w .  j ava 2s . co  m
    filePost.setRequestEntity(entity);
    HttpClient client = new HttpClient();
    int status = client.executeMethod(filePost);
    assertEquals(200, status);
    filePost.releaseConnection();
}

From source file:org.tuleap.mylyn.task.core.internal.client.rest.TuleapRestConnector.java

/**
 * Logs a debug message of the REST request/response.
 *
 * @param method// ww  w. j  a  v  a2  s .  c o  m
 *            The method executed
 * @param bodyReceived
 *            The response body received
 */
private void debugRestCall(HttpMethod method, String bodyReceived) {
    int responseStatus = method.getStatusCode();
    StringBuilder b = new StringBuilder();
    b.append(method.getName());
    b.append(" ").append(method.getPath()); //$NON-NLS-1$
    String qs = method.getQueryString();
    if (qs != null && !qs.isEmpty()) {
        b.append('?').append(method.getQueryString());
    }
    if (method instanceof EntityEnclosingMethod) {
        RequestEntity requestEntity = ((EntityEnclosingMethod) method).getRequestEntity();
        String body = ""; //$NON-NLS-1$
        if (requestEntity.isRepeatable()) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            try {
                requestEntity.writeRequest(os);
                body = os.toString("UTF-8"); //$NON-NLS-1$
            } catch (UnsupportedEncodingException e) {
                // Nothing to do
            } catch (IOException e) {
                // Nothing to do
            }
        }
        b.append("\nbody:\n").append(body.replaceAll(//$NON-NLS-1$
                "\"password\" *: *\".*\"", "\"password\":\"(hidden in debug)\"")); //$NON-NLS-1$ //$NON-NLS-2$
    }
    b.append("\n__________\nresponse:\n"); //$NON-NLS-1$
    b.append(method.getStatusLine()).append("\n"); //$NON-NLS-1$
    b.append("body:\n"); //$NON-NLS-1$
    b.append(bodyReceived);
    int status = IStatus.INFO;
    if (responseStatus != HttpURLConnection.HTTP_OK) {
        status = IStatus.ERROR;
    }
    this.logger.log(new Status(status, TuleapCoreActivator.PLUGIN_ID, b.toString()));
}