Search in sources :

Example 1 with Response

use of org.glassfish.grizzly.http.server.Response in project jersey by jersey.

the class GrizzlyHttpContainer method service.

@Override
public void service(final Request request, final Response response) {
    final ResponseWriter responseWriter = new ResponseWriter(response, configSetStatusOverSendError);
    try {
        logger.debugLog("GrizzlyHttpContainer.service(...) started");
        URI baseUri = getBaseUri(request);
        URI requestUri = getRequestUri(request);
        final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, request.getMethod().getMethodString(), getSecurityContext(request), new GrizzlyRequestPropertiesDelegate(request));
        requestContext.setEntityStream(request.getInputStream());
        for (final String headerName : request.getHeaderNames()) {
            requestContext.headers(headerName, request.getHeaders(headerName));
        }
        requestContext.setWriter(responseWriter);
        requestContext.setRequestScopedInitializer(injectionManager -> {
            injectionManager.<Ref<Request>>getInstance(RequestTYPE).set(request);
            injectionManager.<Ref<Response>>getInstance(ResponseTYPE).set(response);
        });
        appHandler.handle(requestContext);
    } finally {
        logger.debugLog("GrizzlyHttpContainer.service(...) finished");
    }
}
Also used : Response(org.glassfish.grizzly.http.server.Response) ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ContainerResponseWriter(org.glassfish.jersey.server.spi.ContainerResponseWriter) Request(org.glassfish.grizzly.http.server.Request) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) URI(java.net.URI)

Example 2 with Response

use of org.glassfish.grizzly.http.server.Response in project ddf by codice.

the class SecureStubServer method stubsToHandler.

private HttpHandler stubsToHandler() {
    return new HttpHandler() {

        @Override
        public void service(Request request, Response response) throws Exception {
            Call call = Call.fromRequest(request);
            CallsHelper.logCall(call);
            boolean processed = false;
            ListIterator<Stub> iterator = stubs.listIterator(stubs.size());
            while (iterator.hasPrevious()) {
                Stub stub = iterator.previous();
                if (!stub.isApplicable(call)) {
                    continue;
                }
                stub.apply(response);
                processed = true;
                break;
            }
            if (!processed) {
                response.setStatus(HttpStatus.NOT_FOUND_404);
                LOGGER.debug("Request {} hasn't been covered by any of {} stubs.", request.getRequestURI(), stubs.size());
            }
            calls.add(call);
        }
    };
}
Also used : Response(org.glassfish.grizzly.http.server.Response) HttpHandler(org.glassfish.grizzly.http.server.HttpHandler) Call(com.xebialabs.restito.semantics.Call) Request(org.glassfish.grizzly.http.server.Request) Stub(com.xebialabs.restito.semantics.Stub)

Aggregations

Request (org.glassfish.grizzly.http.server.Request)2 Response (org.glassfish.grizzly.http.server.Response)2 Call (com.xebialabs.restito.semantics.Call)1 Stub (com.xebialabs.restito.semantics.Stub)1 URI (java.net.URI)1 HttpHandler (org.glassfish.grizzly.http.server.HttpHandler)1 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)1 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)1 ContainerResponseWriter (org.glassfish.jersey.server.spi.ContainerResponseWriter)1