@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); }
@Override public String createApplicationClientUrl(boolean isSecure, String path, ServerHttpConnection connection) { // Create the application path path = this.createApplicationClientPath(path); // Determine if appropriately secure if (connection.isSecure() == isSecure) { // Relative path return path; } else { // Full path back to server return connection.getServerLocation().createClientUrl(isSecure, path); } }
HttpResponse response = connection.getResponse(); ServerWriter writer = response.getEntityWriter(); String path = connection.getRequest().getUri(); int endPathIndex = path.indexOf('?'); if (endPathIndex >= 0) {
/** * Ensures the {@link HttpRequest} has been tokenized. * * @return {@link HttpRequest}. */ private HttpRequest ensureTokenised() { HttpRequest request = this.connection.getRequest(); if (!this.isTokenisedRequest) { // Tokenise out the arguments HttpRequestTokeniser.tokeniseHttpRequest(request, HttpRequestStateManagedObjectSource.this.argumentParsers, this); // Request now tokenised this.isTokenisedRequest = true; } return request; }
boolean isConnectionSecure = connection.isSecure(); if (!isConnectionSecure) { HttpRequest request = connection.getRequest(); String uri = request.getUri(); if (!(this.inputPath.isMatchPath(uri, this.terminatingPathCharacter))) { connection.getResponse().setContentType(this.contentType, this.charset);
if (this.isSecure && (!connection.isSecure())) { redirectLocation = connection.getServerLocation().createClientUrl(this.isSecure, redirectLocation); HttpResponse response = connection.getResponse(); response.setStatus(HttpStatus.SEE_OTHER); response.getHeaders().addHeader(LOCATION, redirectLocation);
@Override public void send(T object, ServerHttpConnection connection) throws IOException { HttpResponse response = connection.getResponse(); response.setContentType(contentType, null); mapper.writeValue(response.getEntity(), object); } };
Serializable connectionMomento = connection.exportState(); Serializable requestStateMomento = HttpRequestStateManagedObjectSource.exportHttpRequestState(requestState); session.setAttribute(ATTRIBUTE_CHALLENGE_REQUEST_MOMENTO, int[] flowIndexes = this.challengeNegotiator.getHandler(connection.getRequest()); if (flowIndexes == null) { throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR, null,
@Override public Object execute(ManagedFunctionContext<Dependencies, None> context) throws Throwable { // Obtain the access control (handles not logged in) context.getObject(Dependencies.ACCESS_CONTROL); // Reinstate request for servicing prior to authentication required ServerHttpConnection connection = (ServerHttpConnection) context.getObject(Dependencies.SERVER_HTTP_CONNECTION); HttpSession session = (HttpSession) context.getObject(Dependencies.HTTP_SESSION); HttpRequestState requestState = (HttpRequestState) context.getObject(Dependencies.REQUEST_STATE); Serializable momento = session .getAttribute(HandleAuthenticationRequiredFunction.ATTRIBUTE_CHALLENGE_REQUEST_MOMENTO); if (momento != null) { // Reinstate the connection and request state ChallengeMomento challenge = (ChallengeMomento) momento; connection.importState(challenge.getServerHttpConnectionMomento()); HttpRequestStateManagedObjectSource.importHttpRequestState(challenge.getHttpRequestStateMomento(), requestState); // Clear the moment session.removeAttribute(HandleAuthenticationRequiredFunction.ATTRIBUTE_CHALLENGE_REQUEST_MOMENTO); } else { // Failure as must reinstate request throw new AuthenticationContinuationException("No previous request state to continue after login"); } // No further functions return null; }
@Override @SuppressWarnings("unchecked") public T parse(ServerHttpConnection connection) throws HttpException { try { return (T) mapper.readValue(connection.getRequest().getEntity(), javaType); } catch (IOException ex) { throw new HttpException(ex); } } };
@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 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 write(ServerWriter writer, boolean isDefaultCharset, Object bean, ServerHttpConnection connection, String templatePath) throws HttpException { // Obtain the link path (determining if require secure link) if (this.isLinkSecure && (!connection.isSecure())) { templatePath = connection.getServerLocation().createClientUrl(this.isLinkSecure, templatePath); } try { // Write the content writer.write(templatePath); writer.write(this.linkPathSuffix); } catch (IOException ex) { throw new HttpException(ex); } }
@Override public String extractApplicationPath(ServerHttpConnection connection) throws HttpException { return WebRouter.transformToApplicationCanonicalPath(connection.getRequest().getUri(), this.contextPath); }
/** * 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<NotFoundDependencies, None> context) throws NotFoundHttpException { // Obtain the request path ServerHttpConnection connection = (ServerHttpConnection) context .getObject(NotFoundDependencies.SERVER_HTTP_CONNECTION); String requestPath = connection.getRequest().getUri(); // Not found throw new NotFoundHttpException(requestPath); }
@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; }
@Override public void loadObjects(ObjectRegistry<Indexed> registry) throws Throwable { this.objectRegistry = registry; // Obtain the server HTTP connection ServerHttpConnection connection = (ServerHttpConnection) registry .getObject(DefaultHttpAuthenticationManagedObjectSource.this.httpSecurityNames.length); // Determine the HTTP authentications to use int[] httpAuthenticationIndexes = DefaultHttpAuthenticationManagedObjectSource.this.negotiator .getHandler(connection.getRequest()); if (httpAuthenticationIndexes == null) { throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR, null, "No " + HttpAuthentication.class.getSimpleName() + " negotiated for default " + HttpAuthentication.class.getSimpleName()); } // Load the HTTP authentications this.httpAuthentications = new HttpAuthentication[httpAuthenticationIndexes.length]; for (int i = 0; i < httpAuthenticationIndexes.length; i++) { int httpAuthenticationIndex = httpAuthenticationIndexes[i]; this.httpAuthentications[i] = (HttpAuthentication<?>) registry.getObject(httpAuthenticationIndex); } }
HttpResponse response = connection.getResponse(); response.setStatus(HttpStatus.METHOD_NOT_ALLOWED); response.getHeaders().addHeader(ALLOW, this.allowedMethods);
@Override public void send(T object) throws HttpException { this.context.run(() -> { // Lazy obtain the content type cache if (this.contentTypeCache == null) { this.contentTypeCache = ObjectResponseManagedObjectSource.this.objectNegotiator .getHandler(this.connection.getRequest()); } // Ensure have acceptable content type if (this.contentTypeCache == null) { throw new HttpException(HttpStatus.NOT_ACCEPTABLE, ObjectResponseManagedObjectSource.this.notAcceptableHeaders, null); } // Handle the object handleObject(object, this.contentTypeCache, OBJECT_RESPONDER_FACTORY, this.connection); return null; }); } }