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();
}
}
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();
}
Aggregations