response.setDate("Date", System.currentTimeMillis()); if ("GET".equalsIgnoreCase(request.getMethod())) {
@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); } } }
/** * This can be used to get the HTTP method for this request. The * HTTP specification RFC 2616 specifies the HTTP request methods * in section 9, Method Definitions. Typically this will be a * GET, POST or a HEAD method, although any string is possible. * * @return the request method for this request message */ public String getMethod() { return request.getMethod(); }
/** * This can be used to get the HTTP method for this request. The * HTTP specification RFC 2616 specifies the HTTP request methods * in section 9, Method Definitions. Typically this will be a * GET, POST or a HEAD method, although any string is possible. * * @return the request method for this request message */ public String getMethod() { return request.getMethod(); }
/** * This can be used to get the HTTP method for this request. The * HTTP specification RFC 2616 specifies the HTTP request methods * in section 9, Method Definitions. Typically this will be a * GET, POST or a HEAD method, although any string is possible. * * @return the request method for this request message */ public String getMethod() { return request.getMethod(); }
/** * Returns the request method. * * @return The request method. */ @Override public String getMethod() { return this.request.getMethod(); }
@Override public String getHttpMethod() { return request.getMethod(); }
@Override public String method() { return request.getMethod(); }
@Override public String getHttpMethod() { return request.getMethod(); }
public String getMethod() { return request.getMethod(); }
public String getMethod() { return request.getMethod(); }
public void processIo(Request req, Response rsp, String path) throws IOException { String[] tokens = path.split("/"); switch (req.getMethod()) { case Method.PUT: this.handlePut(req, rsp, tokens); break; case Method.GET: this.handleGet(req, rsp, tokens); break; case Method.DELETE: this.handleDelete(req, rsp, tokens); break; default: throw new IOException("method not implemented " + req.getMethod()); } }
@Override public Method getMethod() { String s = baseRequest.getMethod().toUpperCase(); try { return Method.valueOf(s); } catch (IllegalArgumentException e) { String ua = getUserAgentHeader(); String ip = getRemoteAddr(); throw new RuntimeException("No such method: " + s + " Requested by user-agent: " + ua + " from remote address: " + ip); } }
@Override public String toString() { return request.getMethod() + " " + request.getAddress().toString(); }
public OutputStream writeStatusAndHeaders(long contentLength, ContainerResponse cResponse) throws IOException { int code = cResponse.getStatus(); String text = Status.getDescription(code); String method = request.getMethod(); response.setCode(code); response.setDescription(text); if (!method.equalsIgnoreCase("HEAD") && contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) { for (Object value : e.getValue()) { response.setValue(e.getKey(), ContainerResponse.getHeaderValue(value)); } } return response.getOutputStream(); }
public ResolvedRequest resolve(Request request) { ResolvedRequest resolved = new ResolvedRequest(); String method = request.getMethod(); String path = RequestUtils.getUndecodedPath(request); ContentType requestContentType = request.getContentType(); /* get the route and the handler for this request */ Route route = router.route(path); if (route == null) { logger.error("could not find a route for " + path); resolved.errorStatus = Status.NOT_FOUND; return resolved; } String contentType = requestContentType != null ? requestContentType.getType() : null; HandlerKey key = new HandlerKey(method, route, contentType); RequestHandlerImpl handler = handlerMap.get(key); if (handler == null) { logger.error("could not find a handler for " + method + " - " + path + " - " + contentType); resolved.errorStatus = Status.METHOD_NOT_ALLOWED; return resolved; } resolved.handler = handler; resolved.route = route; resolved.key = key; return resolved; }
public void handle(Request request, Response response) { WebApplication target = application; final URI baseUri = getBaseUri(request); final URI requestUri = baseUri.resolve(request.getTarget()); try { final ContainerRequest cRequest = new ContainerRequest( target, request.getMethod(), baseUri, requestUri, getHeaders(request), request.getInputStream()); target.handleRequest(cRequest, new Writer(request, response)); } catch (Exception ex) { throw new RuntimeException(ex); } finally { close(response); } }
public static FullHttpRequest convert(final Request request) { byte[] data = null; try { final InputStream inputStream = request.getInputStream(); try { data = IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } } catch (final IOException e) { LOGGER.error("IOException when getting request content.", e); } final FullHttpRequestImpl httpRequest = new FullHttpRequestImpl(); httpRequest.domain(request.getAddress().getDomain()); httpRequest.port(request.getAddress().getPort()); httpRequest.method(Method.valueOf(request.getMethod())); httpRequest.path(request.getPath().getPath()); if (data.length > 0) { httpRequest.content(data); } for (final String headerField : request.getNames()) { for (final String headerFieldValue : request.getValues(headerField)) { httpRequest.httpMessageHeader(headerField, headerFieldValue); } } for (final Entry<String, String> entry : request.getQuery().entrySet()) { httpRequest.queryParameter(entry.getKey(), entry.getValue()); } return httpRequest; }
@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); } } }