List of usage examples for io.vertx.core.http HttpHeaders LOCATION
CharSequence LOCATION
To view the source code for io.vertx.core.http HttpHeaders LOCATION.
Click Source Link
From source file:io.knotx.knot.action.ActionKnotProxyImpl.java
License:Apache License
private KnotContext redirectKnotResponse(KnotContext knotContext, FormEntity form, ClientResponse clientResponse, String redirectLocation) { LOGGER.trace("Request redirected to [{}]", redirectLocation); knotContext.getClientResponse().setStatusCode(HttpResponseStatus.MOVED_PERMANENTLY.code()); MultiMap headers = MultiMap.caseInsensitiveMultiMap(); headers.addAll(getFilteredHeaders(clientResponse.getHeaders(), form.adapter().getAllowedResponseHeaders())); headers.add(HttpHeaders.LOCATION.toString(), redirectLocation); knotContext.getClientResponse().setHeaders(headers); knotContext.clearFragments();/*from w w w. j a v a 2 s. c o m*/ return knotContext; }
From source file:org.eclipse.hono.adapter.http.HonoAuthHandlerImpl.java
License:Open Source License
protected void processException(RoutingContext ctx, Throwable exception) { if (exception != null) { if (exception instanceof HttpStatusException) { final int statusCode = ((HttpStatusException) exception).getStatusCode(); final String payload = ((HttpStatusException) exception).getPayload(); switch (statusCode) { case 302: ctx.response().putHeader(HttpHeaders.LOCATION, payload).setStatusCode(302) .end("Redirecting to " + payload + "."); return; case 401: String header = authenticateHeader(ctx); if (header != null) { ctx.response().putHeader("WWW-Authenticate", header); }/*from w w w. j a va 2 s. c om*/ ctx.fail(401); return; default: ctx.fail(statusCode); return; } } } // fallback 500 ctx.fail(exception); }
From source file:org.eclipse.hono.service.auth.device.HonoAuthHandler.java
License:Open Source License
/** * This method is protected so custom auth handlers can override the default * error handling./* w w w. j a va 2 s . c om*/ * * @param ctx The routing context. * @param exception The cause of failure to process the request. */ protected void processException(final RoutingContext ctx, final Throwable exception) { if (exception != null) { if (exception instanceof HttpStatusException || exception instanceof ServiceInvocationException) { final int statusCode; final String payload; if (exception instanceof HttpStatusException) { statusCode = ((HttpStatusException) exception).getStatusCode(); payload = ((HttpStatusException) exception).getPayload(); } else { statusCode = ((ServiceInvocationException) exception).getErrorCode(); payload = null; } switch (statusCode) { case 302: ctx.response().putHeader(HttpHeaders.LOCATION, payload).setStatusCode(302) .end("Redirecting to " + payload + "."); return; case 401: final String header = authenticateHeader(ctx); if (header != null) { ctx.response().putHeader("WWW-Authenticate", header); } ctx.fail(401); return; default: ctx.fail(statusCode); return; } } } // fallback 500 ctx.fail(exception); }
From source file:org.eclipse.hono.service.credentials.CredentialsHttpEndpoint.java
License:Open Source License
private void addCredentials(final RoutingContext ctx) { final JsonObject payload = (JsonObject) ctx.get(KEY_REQUEST_BODY); final String deviceId = payload.getString(CredentialsConstants.FIELD_PAYLOAD_DEVICE_ID); final String authId = payload.getString(CredentialsConstants.FIELD_AUTH_ID); final String type = payload.getString(CredentialsConstants.FIELD_TYPE); final String tenantId = getTenantParam(ctx); logger.debug("adding credentials [tenant: {}, device-id: {}, auth-id: {}, type: {}]", tenantId, deviceId, authId, type);// w ww . ja v a 2 s.c o m final JsonObject requestMsg = EventBusMessage .forOperation(CredentialsConstants.CredentialsAction.add.toString()).setTenant(tenantId) .setDeviceId(deviceId).setJsonPayload(payload).toJson(); sendAction(ctx, requestMsg, getDefaultResponseHandler(ctx, status -> status == HttpURLConnection.HTTP_CREATED, httpServerResponse -> httpServerResponse.putHeader(HttpHeaders.LOCATION, String.format("/%s/%s/%s/%s", CredentialsConstants.CREDENTIALS_ENDPOINT, tenantId, authId, type)))); }
From source file:org.eclipse.hono.service.registration.RegistrationHttpEndpoint.java
License:Open Source License
private void registerDevice(final RoutingContext ctx, final JsonObject payload) { if (payload == null) { HttpEndpointUtils.badRequest(ctx.response(), "missing body"); } else {// ww w .ja v a2 s. c o m Object deviceId = payload.remove(FIELD_DEVICE_ID); if (deviceId == null) { HttpEndpointUtils.badRequest(ctx.response(), String.format("'%s' param is required", FIELD_DEVICE_ID)); } else if (!(deviceId instanceof String)) { HttpEndpointUtils.badRequest(ctx.response(), String.format("'%s' must be a string", FIELD_DEVICE_ID)); } else { final String tenantId = getTenantParam(ctx); logger.debug("registering data for device [tenant: {}, device: {}, payload: {}]", tenantId, deviceId, payload); final HttpServerResponse response = ctx.response(); final JsonObject requestMsg = RegistrationConstants.getServiceRequestAsJson( RegistrationConstants.ACTION_REGISTER, tenantId, (String) deviceId, payload); doRegistrationAction(ctx, requestMsg, (status, registrationResult) -> { response.setStatusCode(status); switch (status) { case HttpURLConnection.HTTP_CREATED: response.putHeader(HttpHeaders.LOCATION, String.format("/%s/%s/%s", RegistrationConstants.REGISTRATION_ENDPOINT, tenantId, deviceId)); default: response.end(); } }); } } }
From source file:org.eclipse.hono.service.tenant.TenantHttpEndpoint.java
License:Open Source License
private void addTenant(final RoutingContext ctx) { final String tenantId = getTenantIdFromContext(ctx); final String location = String.format("/%s/%s", TenantConstants.TENANT_ENDPOINT, tenantId); doTenantHttpRequest(ctx, tenantId, TenantConstants.TenantAction.add, status -> status == HttpURLConnection.HTTP_CREATED, response -> response.putHeader(HttpHeaders.LOCATION, location)); }
From source file:org.etourdot.vertx.marklogic.http.utils.HttpUtils.java
License:Open Source License
public static String extractDocumentUri(MultiMap headers) { if (headers.contains(HttpHeaders.LOCATION)) { String location = headers.get(HttpHeaders.LOCATION); return location.substring(location.indexOf(DOCUMENT_URI_PREFIX) + DOCUMENT_URI_PREFIX.length()); } else if (headers.contains(HEADER_CONTENT_DISPOSITION)) { String disposition = headers.get(HEADER_CONTENT_DISPOSITION); Matcher regexMatcher = DISPOSITION_REGEX_PATTERN.matcher(disposition); if (regexMatcher.find()) { return regexMatcher.group(2); }/*from w ww .jav a 2 s. com*/ } return null; }