@Override public void send(T object, ServerHttpConnection connection) throws IOException { HttpResponse response = connection.getResponse(); response.setContentType(contentType, null); mapper.writeValue(response.getEntity(), object); } };
@Override public void send(E escalation, ServerHttpConnection connection) throws IOException { HttpResponse response = connection.getResponse(); response.setContentType(contentType, null); ServerOutputStream output = response.getEntity(); output.write(ERROR_MESSAGE_PREFIX); // Write the error detail String message = escalation.getMessage(); if ((message == null) || (message.trim().length() == 0)) { message = escalation.getClass().getSimpleName(); } mapper.writeValue(output, message); output.write(ERROR_MESSAGE_SUFFIX); } };
/** * Adds the Session Id {@link HttpCookie} to the {@link HttpResponse}. * * @param sessionId * Session Id. * @param expireTime * Time that the {@link HttpCookie} is to expire. */ private void setSessionIdCookieToHttpResponse(String sessionId, Instant expireTime) { this.connection.getResponse().getCookies().setCookie(this.sessionIdCookieName, sessionId, (cookie) -> cookie.setExpires(expireTime)); }
@Override public Object execute(ManagedFunctionContext<Dependencies, None> context) throws Throwable { // Obtain the dependencies HttpChallengeContext httpChallengeContext = (HttpChallengeContext) context .getObject(Dependencies.HTTP_CHALLENGE_CONTEXT); ServerHttpConnection connection = (ServerHttpConnection) context.getObject(Dependencies.SERVER_HTTP_CONNECTION); // Send the challenge HttpChallengeContextManagedObjectSource.loadHttpChallenge(httpChallengeContext, connection.getResponse()); // Nothing further return null; }
HttpResponse response = connection.getResponse(); ServerWriter writer = response.getEntityWriter();
HttpResponse response = connection.getResponse(); response.setStatus(HttpStatus.METHOD_NOT_ALLOWED); response.getHeaders().addHeader(ALLOW, this.allowedMethods);
@Override public Object execute(ManagedFunctionContext<HttpRouteDependencies, Indexed> context) { // Obtain the server HTTP connection ServerHttpConnection connection = (ServerHttpConnection) context .getObject(HttpRouteDependencies.SERVER_HTTP_CONNECTION); // Load the escalation handler if (this.escalationHandler != null) { connection.getResponse().setEscalationHandler(this.escalationHandler); } // Determine if potentially redirect HttpRequestCookie cookie = connection.getRequest().getCookies() .getCookie(HttpRedirectFunction.REDIRECT_COOKIE_NAME); if (cookie != null) { // Redirect, so trigger flow to import previous state context.doFlow(this.handleRedirectFlowIndex, cookie, null); return null; // serviced by redirect } // No redirect, so route the request return this.router.route(connection, context); }
@Override public void handle(HttpArgument pathArguments, ServerHttpConnection connection, ManagedFunctionContext<?, Indexed> context) { // Determine if secure connection is required if (this.isRequireSecure && (!connection.isSecure())) { // Non-secure, requiring secure - so redirect String path = connection.getRequest().getUri(); String securePath = connection.getServerLocation().createClientUrl(this.isRequireSecure, path); // Send redirect response to secure path HttpResponse response = connection.getResponse(); response.setStatus(HttpStatus.TEMPORARY_REDIRECT); response.getHeaders().addHeader(LOCATION, securePath); return; } // Undertake flow to service route context.doFlow(this.flowIndex, pathArguments, null); }
connection.getResponse().setContentType(this.contentType, this.charset);
HttpResponse response = connection.getResponse(); response.setStatus(HttpStatus.SEE_OTHER); response.getHeaders().addHeader(LOCATION, redirectLocation);