use of org.simpleframework.http.Response in project sonarqube by SonarSource.
the class DefaultHttpDownloaderTest method startServer.
@BeforeClass
public static void startServer() throws IOException {
socketConnection = new SocketConnection(new Container() {
public void handle(Request req, Response resp) {
try {
if (req.getPath().getPath().contains("/redirect/")) {
resp.setCode(303);
resp.add("Location", "/");
} else {
if (req.getPath().getPath().contains("/timeout/")) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
if (req.getPath().getPath().contains("/gzip/")) {
if (!"gzip".equals(req.getValue("Accept-Encoding"))) {
throw new IllegalStateException("Should accept gzip");
}
resp.set("Content-Encoding", "gzip");
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(resp.getOutputStream());
gzipOutputStream.write("GZIP response".getBytes());
gzipOutputStream.close();
} else {
resp.getPrintStream().append("agent=" + req.getValues("User-Agent").get(0));
}
}
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
try {
resp.close();
} catch (IOException ignored) {
}
}
}
});
SocketAddress address = socketConnection.connect(new InetSocketAddress("localhost", 0));
baseUrl = String.format("http://%s:%d", ((InetSocketAddress) address).getAddress().getHostAddress(), ((InetSocketAddress) address).getPort());
}
use of org.simpleframework.http.Response in project jersey by jersey.
the class SimpleContainer method handle.
@Override
public void handle(final Request request, final Response response) {
final ResponseWriter responseWriter = new ResponseWriter(response, scheduler);
final URI baseUri = getBaseUri(request);
final URI requestUri = getRequestUri(request, baseUri);
try {
final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, request.getMethod(), getSecurityContext(request), new MapPropertiesDelegate());
requestContext.setEntityStream(request.getInputStream());
for (final String headerName : request.getNames()) {
requestContext.headers(headerName, request.getValue(headerName));
}
requestContext.setWriter(responseWriter);
requestContext.setRequestScopedInitializer(injectionManager -> {
injectionManager.<Ref<Request>>getInstance(RequestTYPE).set(request);
injectionManager.<Ref<Response>>getInstance(ResponseTYPE).set(response);
});
appHandler.handle(requestContext);
} catch (final Exception ex) {
throw new RuntimeException(ex);
} finally {
if (!responseWriter.isSuspended()) {
close(response);
}
}
}
Aggregations