Example usage for io.netty.handler.codec.http HttpMethod POST

List of usage examples for io.netty.handler.codec.http HttpMethod POST

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpMethod POST.

Prototype

HttpMethod POST

To view the source code for io.netty.handler.codec.http HttpMethod POST.

Click Source Link

Document

The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line.

Usage

From source file:org.wso2.carbon.transport.http.netty.contentaware.test.ContentAwareMessageProcessorTestCase.java

License:Open Source License

@Test(groups = "contentaware", dependsOnMethods = "requestResponseStreamingFromProcessorTestCase")
public void requestResponseTransformStreamingFromProcessorTestCase() {

    String requestValue = "<A><B><C>Test Message</C></B></A>";
    try {//from w w w .  j  a v  a  2s .  c  o m
        CarbonMessageProcessor carbonMessageProcessor = new RequestResponseTransformStreamingProcessor();
        TestUtil.updateMessageProcessor(carbonMessageProcessor, senderConfiguration, listenerConfiguration);
        HttpURLConnection urlConn = TestUtil.request(baseURI, "/", HttpMethod.POST.name(), true);
        TestUtil.writeContent(urlConn, requestValue);
        assertEquals(200, urlConn.getResponseCode());
        String content = TestUtil.getContent(urlConn);
        assertEquals(requestValue, content);
        urlConn.disconnect();
    } catch (IOException e) {
        LOGGER.error("IO Exception occurred", e);
        assertTrue(false);
    }

}

From source file:org.wso2.carbon.transport.http.netty.contentaware.test.ContentAwareMessageProcessorTestCase.java

License:Open Source License

@Test(groups = "contentaware", dependsOnMethods = "requestResponseTransformStreamingFromProcessorTestCase")
public void responseStreamingWithoutBufferingTestCase() {

    String requestValue = "<A><B><C>Test Message</C></B></A>";
    try {//from  w w  w . j  a  v a  2  s .c  o  m
        CarbonMessageProcessor carbonMessageProcessor = new ResponseStreamingWithoutBufferingProcessor();
        TestUtil.updateMessageProcessor(carbonMessageProcessor, senderConfiguration, listenerConfiguration);
        HttpURLConnection urlConn = TestUtil.request(baseURI, "/", HttpMethod.POST.name(), true);
        TestUtil.writeContent(urlConn, requestValue);
        assertEquals(200, urlConn.getResponseCode());
        String content = TestUtil.getContent(urlConn);
        assertEquals(requestValue, content);
        urlConn.disconnect();
    } catch (IOException e) {
        LOGGER.error("IO Exception occurred", e);
        assertTrue(false);
    }

}

From source file:org.wso2.carbon.transport.http.netty.encoding.ContentEncodingTestCase.java

License:Open Source License

@Test
public void messageEchoingFromProcessorTestCase() {
    String testValue = "Test Message";
    try {//from  w w w .  j  a va 2  s.  co  m
        HttpURLConnection urlConn = TestUtil.request(baseURI, "/", HttpMethod.POST.name(), true);
        //TestUtil.setHeader(urlConn, Constants.ACCEPT_ENCODING, Constants.ENCODING_GZIP);
        TestUtil.writeContent(urlConn, testValue);
        assertEquals(200, urlConn.getResponseCode());
        String content = TestUtil.getContent(urlConn);
        urlConn.disconnect();
    } catch (IOException e) {
        TestUtil.handleException("IOException occurred while running the messageEchoingFromProcessorTestCase",
                e);
    }

}

From source file:org.wso2.carbon.transport.http.netty.passthrough.PassThroughHttpTestCase.java

License:Open Source License

@Test
public void passthroughPostTest() {
    try {//from w  w w.jav  a 2s  .  c om
        HttpURLConnection urlConn = TestUtil.request(baseURI, "/", HttpMethod.POST.name(), true);
        String content = TestUtil.getContent(urlConn);
        assertEquals(testValue, content);
        urlConn.disconnect();
    } catch (IOException e) {
        TestUtil.handleException("IOException occurred while running passthroughPostTest", e);
    }
}

From source file:org.wso2.carbon.transport.http.netty.passthrough.test.PassThroughHttpPOSTMethodTestCase.java

License:Open Source License

@Test(groups = "passthroughPost", dependsOnGroups = "passthroughGET")
public void passthroughPOSTTestCase() {
    String testValue = "Test Message";
    try {/*from ww  w  . j  av  a  2 s . c  o m*/
        HttpURLConnection urlConn = TestUtil.request(baseURI, "/", HttpMethod.POST.name(), true);
        TestUtil.writeContent(urlConn, testValue);
        String content = TestUtil.getContent(urlConn);
        assertEquals(testValue, content);
        urlConn.disconnect();
    } catch (IOException e) {
        LOGGER.error("IO Exception occurred", e);
        assertTrue(false);
    }

}

From source file:org.wso2.carbon.transport.http.netty.util.TestUtil.java

License:Open Source License

public static HttpURLConnection request(URI baseURI, String path, String method, boolean keepAlive)
        throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST.name()) || method.equals(HttpMethod.PUT.name())) {
        urlConn.setDoOutput(true);//from  ww  w  . ja va 2 s .co  m
    }
    urlConn.setRequestMethod(method);
    if (!keepAlive) {
        urlConn.setRequestProperty("Connection", "Keep-Alive");
    }

    return urlConn;
}

From source file:org.wso2.extension.siddhi.io.http.source.util.HttpServerUtil.java

License:Open Source License

static HttpURLConnection request(URI baseURI, String path, String method) throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST.name()) || method.equals(HttpMethod.PUT.name())) {
        urlConn.setDoOutput(true);/*from w  ww .j av  a 2s . c  om*/
    }
    urlConn.setRequestMethod(method);
    urlConn.setRequestProperty("Connection", "Keep-Alive");
    return urlConn;
}

From source file:org.wso2.extension.siddhi.io.http.source.util.HttpTestUtil.java

License:Open Source License

public static void httpPublishEventDefault(String event, URI baseURI) {
    try {//from   w ww  .  j  a  v  a  2 s . c  om
        HttpURLConnection urlConn = null;
        try {
            urlConn = HttpServerUtil.request(baseURI, "/TestSiddhiApp/" + "inputStream",
                    HttpMethod.POST.name());
        } catch (IOException e) {
            HttpServerUtil.handleException(e);
        }
        HttpServerUtil.setHeader(urlConn, "Content-Type", "text/xml");
        HttpServerUtil.setHeader(urlConn, "HTTP_METHOD", "POST");
        HttpServerUtil.writeContent(urlConn, event);
        assert urlConn != null;
        logger.info("Event response code " + urlConn.getResponseCode());
        logger.info("Event response message " + urlConn.getResponseMessage());
        urlConn.disconnect();
    } catch (IOException e) {
        HttpServerUtil.handleException(e);
    }
}

From source file:org.wso2.extension.siddhi.map.text.sourcemapper.util.HttpServerUtil.java

License:Open Source License

static HttpURLConnection request(URI baseURI, String path, String method) throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST.name()) || method.equals(HttpMethod.PUT.name())) {
        urlConn.setDoOutput(true);// ww w . j a  v a  2  s. c om
    }
    urlConn.setRequestMethod(method);
    return urlConn;
}

From source file:org.wso2.extension.siddhi.store.rdbms.test.osgi.util.TestUtil.java

License:Open Source License

public static HTTPResponseMessage sendHRequest(String body, URI baseURI, String path, String contentType,
        String methodType, Boolean auth, String userName, String password) {
    try {//from   ww w.  j  a  v  a 2s  .c  o m
        HttpURLConnection urlConn = null;
        try {
            urlConn = TestUtil.generateRequest(baseURI, path, methodType, false);
        } catch (IOException e) {
            TestUtil.handleException("IOException occurred while running the HttpsSourceTestCaseForSSL", e);
        }
        if (auth) {
            TestUtil.setHeader(urlConn, "Authorization", "Basic "
                    + java.util.Base64.getEncoder().encodeToString((userName + ":" + password).getBytes()));
        }
        if (contentType != null) {
            TestUtil.setHeader(urlConn, "Content-Type", contentType);
        }
        TestUtil.setHeader(urlConn, "HTTP_METHOD", methodType);
        if (methodType.equals(HttpMethod.POST.name()) || methodType.equals(HttpMethod.PUT.name())) {
            TestUtil.writeContent(urlConn, body);
        }
        assert urlConn != null;
        HTTPResponseMessage httpResponseMessage = new HTTPResponseMessage(urlConn.getResponseCode(),
                urlConn.getContentType(), urlConn.getResponseMessage());
        urlConn.disconnect();
        return httpResponseMessage;
    } catch (IOException e) {
        TestUtil.handleException("IOException occurred while running the HttpsSourceTestCaseForSSL", e);
    }
    return new HTTPResponseMessage();
}