Example usage for org.apache.http.entity StringEntity StringEntity

List of usage examples for org.apache.http.entity StringEntity StringEntity

Introduction

In this page you can find the example usage for org.apache.http.entity StringEntity StringEntity.

Prototype

@Deprecated
    public StringEntity(String str, String str2, String str3) throws UnsupportedEncodingException 

Source Link

Usage

From source file:com.betfair.cougar.client.HttpClientCougarRequestFactory.java

@Override
protected void addPostEntity(HttpUriRequest httpRequest, String postEntity, String contentType) {
    try {/*from   ww w  .  j a  v a2s .  co  m*/
        if (httpRequest instanceof HttpPost) {
            ((HttpPost) httpRequest).setEntity(new StringEntity(postEntity, contentType, UTF8));
        }
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.mule.module.http.functional.listener.HttpListenerContentTypeTestCase.java

@Test
public void rejectsInvalidContentTypeWithBody() throws Exception {
    Request request = Request.Post(getUrl()).body(new StringEntity(TEST_MESSAGE, "application", null));
    testRejectContentType(request, "Could not parse");
}

From source file:org.wso2.carbon.esb.mediator.test.property.PropertyIntegrationForceHttpContentLengthPropertyTestCase.java

@Test(groups = "wso2.esb", description = "Tests when both properties are enabled")
public void testWithEnableFORCE_HTTP_CONTENT_LENGTHAndCOPY_CONTENT_LENGTH_FROM_INCOMINGTest() throws Exception {

    loadESBConfigurationFromClasspath(/*  w ww.j  a  v  a  2  s .  c  o m*/
            "/artifacts/ESB/mediatorconfig/property/EnableFORCE_HTTP_CONTENT_LENGTH.xml");

    wireServer.start();

    HttpClient httpclient = new DefaultHttpClient();

    StringEntity strEntity = new StringEntity("<soapenv:Envelope xmlns:soapenv=\"http://schemas."
            + "xmlsoap.org/soap/envelope/\" xmlns:ser=\"" + "http://services.samples\" xmlns:xsd=\""
            + "http://services.samples/xsd\">\n" + "   <soapenv:Header/>\n" + "   <soapenv:Body>\n"
            + "      <ser:getQuote>\n" + "         <!--Optional:-->\n" + "         <ser:request>\n"
            + "            <!--Optional:-->\n" + "            <xsd:symbol>WSO2</xsd:symbol>\n"
            + "         </ser:request>\n" + "      </ser:getQuote>\n" + "   </soapenv:Body>\n"
            + "</soapenv:Envelope>", "text/xml", "UTF-8");

    HttpPost post = new HttpPost(getProxyServiceURLHttp("Axis2ProxyService"));
    post.setHeader("SOAPAction", "urn:getQuote");
    post.setEntity(strEntity);

    // Execute request
    httpclient.execute(post);

    assertTrue(wireServer.getCapturedMessage().contains("Content-Length"),
            "Content-Length not found in the out-going message");
}

From source file:org.dataconservancy.ui.services.EZIDServiceImpl.java

@Override
public String createID(EZIDMetadata metadata) throws EZIDServiceException {
    setCredentials();// ww  w . ja v a2s .co m

    if (metadata == null) {
        throw new EZIDServiceException("Metadata must be set to create id");
    }

    HttpPost mintID = new HttpPost(buildUrl());

    StringEntity reqBody;
    try {
        reqBody = new StringEntity(metadata.serialize(), "text/plain", "UTF-8");
    } catch (Exception e) {
        throw new EZIDServiceException(e);
    }

    mintID.setEntity(reqBody);

    HttpResponse resp = null;

    try {
        resp = httpClient.execute(mintID);
    } catch (Exception e) {
        throw new EZIDServiceException(e);
    }

    String responseID = requestUrl;
    if (!responseID.endsWith("/")) {
        responseID += "/";
    }

    responseID += "id/";
    if (resp != null) {

        String response = "";
        HttpEntity respEntity = resp.getEntity();
        StringWriter writer = new StringWriter();
        try {
            IOUtils.copy(respEntity.getContent(), writer);
        } catch (IllegalStateException e) {
            throw new EZIDServiceException(e);
        } catch (IOException e) {
            throw new EZIDServiceException(e);
        }

        response = writer.toString();

        if (resp.getStatusLine().getStatusCode() != 201) {
            throw new EZIDServiceException(resp.getStatusLine().getReasonPhrase() + " EZID " + response);
        } else {
            String[] responseParts = response.split("\\s+");
            if (responseParts.length > 1 && responseParts[0].equalsIgnoreCase("success:")) {
                responseID += responseParts[1];
            } else {
                throw new EZIDServiceException("Unexpected response: " + response);
            }
        }
    } else {
        throw new EZIDServiceException("Unexpected null response");
    }

    freeResponse(resp);
    return responseID;
}