Search in sources :

Example 1 with ByteArrayBuffer

use of org.eclipse.jetty.io.ByteArrayBuffer in project elastic-job by dangdangdotcom.

the class RestfulServerTest method sentRequest.

private static ContentExchange sentRequest(final String content) throws Exception {
    HttpClient httpClient = new HttpClient();
    try {
        httpClient.start();
        ContentExchange result = new ContentExchange();
        result.setMethod("POST");
        result.setRequestContentType(MediaType.APPLICATION_JSON);
        result.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
        result.setURL(URL);
        httpClient.send(result);
        result.waitForDone();
        return result;
    } finally {
        httpClient.stop();
    }
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) ContentExchange(org.eclipse.jetty.client.ContentExchange) ByteArrayBuffer(org.eclipse.jetty.io.ByteArrayBuffer)

Example 2 with ByteArrayBuffer

use of org.eclipse.jetty.io.ByteArrayBuffer in project processdash by dtuma.

the class LocalConnector method getResponse.

public ByteArrayBuffer getResponse(String uri, int port, Map extraEnv) throws Exception {
    // get the current, previously active connection if one exists
    AbstractHttpConnection conn = AbstractHttpConnection.getCurrentConnection();
    // Identify the effective server name for this request
    Request parentRequest = (conn == null ? null : conn.getRequest());
    String host = (//
    parentRequest == null ? //
    "localhost:" + port : parentRequest.getHeader("Host"));
    // construct an HTTP request for this data
    StringBuilder requestHeader = new StringBuilder();
    requestHeader.append("GET ").append(uri).append(" HTTP/1.0\r\n").append("Host: ").append(host).append("\r\n").append("Connection: close\r\n").append("Content-Length: 0\r\n\r\n");
    // execute the request and retrieve the responses
    ByteArrayBuffer requestBuffer = new ByteArrayBuffer(requestHeader.toString(), StringUtil.__ISO_8859_1);
    LocalRequest request = new LocalRequest(requestBuffer, extraEnv, parentRequest, false);
    AccessController.doPrivileged(request);
    return request.getResponsesBuffer();
}
Also used : Request(org.eclipse.jetty.server.Request) AbstractHttpConnection(org.eclipse.jetty.server.AbstractHttpConnection) ByteArrayBuffer(org.eclipse.jetty.io.ByteArrayBuffer)

Aggregations

ByteArrayBuffer (org.eclipse.jetty.io.ByteArrayBuffer)2 ContentExchange (org.eclipse.jetty.client.ContentExchange)1 HttpClient (org.eclipse.jetty.client.HttpClient)1 AbstractHttpConnection (org.eclipse.jetty.server.AbstractHttpConnection)1 Request (org.eclipse.jetty.server.Request)1