/** * Loads the {@link HttpChallenge} to the {@link HttpResponse}. * * @param httpChallengeContext * {@link HttpChallengeContext}. * @param response * {@link HttpResponse}. */ public static void loadHttpChallenge(HttpChallengeContext httpChallengeContext, HttpResponse response) { // Obtain the challenge HttpChallengeContextManagedObject managedObject = (HttpChallengeContextManagedObject) httpChallengeContext; // Determine if challenge and if so send challenge managedObject.processAwareContext.run(() -> { if (managedObject.challenge.length() > 0) { response.setStatus(HttpStatus.UNAUTHORIZED); response.getHeaders().addHeader(CHALLENGE_NAME, managedObject.challenge.toString()); } return null; }); }
@Override public void send(T object, ServerHttpConnection connection) throws IOException { HttpResponse response = connection.getResponse(); response.setContentType(contentType, null); mapper.writeValue(response.getEntity(), object); } };
/** * 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)); }
response.setStatus(HttpStatus.SEE_OTHER); response.getHeaders().addHeader(LOCATION, redirectLocation); response.getCookies().setCookie(REDIRECT_COOKIE_NAME, String.valueOf(serialisable.identifier), (cookie) -> cookie.setPath(applicationPath).setSecure(this.isSecure).setHttpOnly(true));
ServerWriter writer = response.getEntityWriter(); boolean isDefaultCharset = (this.defaultCharset.name().equalsIgnoreCase(response.getContentCharset().name()));
connection.getResponse().setContentType(this.contentType, this.charset);
@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); }
response.setStatus(HttpStatus.METHOD_NOT_ALLOWED); response.getHeaders().addHeader(ALLOW, this.allowedMethods);
@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); } };
@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); }