本文整理匯總了Java中javax.ws.rs.container.ContainerRequestContext.getUriInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java ContainerRequestContext.getUriInfo方法的具體用法?Java ContainerRequestContext.getUriInfo怎麽用?Java ContainerRequestContext.getUriInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.ws.rs.container.ContainerRequestContext
的用法示例。
在下文中一共展示了ContainerRequestContext.getUriInfo方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext reqCtx, ContainerResponseContext respCtx) throws IOException {
final UriInfo uriInfo = reqCtx.getUriInfo();
final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
if (queryParameters.containsKey("pretty")) {
ObjectWriterInjector.set(new IndentingModifier());
}
}
示例2: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
UriInfo uriInfo = requestContext.getUriInfo();
UriBuilder hostUriBuilder = uriInfo.getRequestUriBuilder();
// get host from header forwarded host if set
String forwardedHost = requestContext.getHeaderString(HttpHeaders.X_FORWARDED_HOST);
LOG.debug("x-forwarded-host: {}", forwardedHost);
URI builtRequestUri = hostUriBuilder.build();
String replacementUri = builtRequestUri.getHost() + builtRequestUri.getPath();
if (forwardedHost != null) {
UriBuilder forwardedHostUriBuilder =
UriBuilder.fromUri("http://" + forwardedHost.split(",")[0]);
replacementUri = forwardedHostUriBuilder.build().getHost() + builtRequestUri.getPath();
}
hostUriBuilder.replacePath(replacementUri);
LOG.debug("Set new request path to {} (was {})", hostUriBuilder, uriInfo.getAbsolutePath());
requestContext.setRequestUri(hostUriBuilder.build());
}
示例3: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
System.out.println("Response = " + requestContext + " " + responseContext);
Long start = concurrentRequests.get(requestContext);
concurrentRequests.remove(requestContext);
long duration = (System.nanoTime() - start);
System.out.println("Duration: " + duration);
UriInfo uriInfo = requestContext.getUriInfo();
String ipv4 = extractIpAddress(uriInfo);
System.out.println("ipv4 = " + ipv4);
String serviceName = extractServiceName(uriInfo);
System.out.println("serviceName = " + serviceName);
String spanName = extractSpanName(uriInfo);
System.out.println("spanName = " + spanName);
Optional<String> traceId = extractTraceId(requestContext);
String spanId = traceId.map(id -> this.tracee.saveChildSpan(id, spanName, serviceName, ipv4, 0)).
orElseGet(() -> this.tracee.saveParentSpan(spanName, serviceName, ipv4, duration));
System.out.println("Storing span id: " + spanId);
storeSpandId(responseContext, spanId);
}
示例4: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
UriInfo info = containerRequestContext.getUriInfo();
if (info.getPath().contains("user/login")) {
return;
}
if (!isAuthTokenValid(containerRequestContext)) {
// throw new NotAuthorizedException("You Don't Have Permission");
containerRequestContext.abortWith(Response
.seeOther(URI.create("/tastjava/user/login")).build());
}
return;
}
示例5: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext context ) throws IOException {
UriInfo uriInfo = context.getUriInfo();
List<PathSegment> pathSegments = uriInfo.getPathSegments();
if(pathSegments != null && !pathSegments.isEmpty()) {
// http://memorynotfound.com/jaxrs-path-segments-matrix-parameters/
DomainMarker marker = mdc.createMarker();
for(int i = 0; i < indexes.length; i++) {
marker.parseAndSetKey(keys[i], pathSegments.get(indexes[i]).toString());
}
marker.pushContext();
}
}
示例6: JaxrsRequestContext
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
JaxrsRequestContext(ContainerRequestContext requestContext, CrnkFeature feature) {
this.feature = feature;
this.requestContext = requestContext;
UriInfo uriInfo = requestContext.getUriInfo();
this.path = buildPath(uriInfo);
this.parameters = getParameters(uriInfo);
ObjectMapper objectMapper = feature.getBoot().getObjectMapper();
requestParameterProvider =
new JaxrsParameterProvider(objectMapper, requestContext, feature.getParameterProviderRegistry());
}
示例7: authenticate
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
/**
* Checks if the request contains the username password combination from the given map of username and password.
*
*/
public void authenticate(ContainerRequestContext request, Map<String, String> usernamePasswordMap) {
String authHeader = request.getHeaderString("Authorization");
WebApplicationException wae = new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED)
.header("WWW-Authenticate", "Basic").entity("not authorized").build());
String requestUri = request.getUriInfo()!=null?request.getUriInfo().getBaseUri().toString():"";
if (authHeader == null) {
log.warn("Authentication of " + requestUri + " failed as auth header was null");
throw wae;
} else {
String[] tokens = authHeader.trim().split("\\s+");
if (tokens.length != 2 || !tokens[0].equalsIgnoreCase("BASIC")) {
log.warn("Authentication of " + requestUri + " failed as auth header does not have the right tokens");
throw wae;
}
// valid auth header format, now need to authenticate the right user
byte[] decodedBytes = Base64.getDecoder().decode(tokens[1]);
String credString = new String(decodedBytes);
String[] credentials = credString.split(":");
if (credentials.length != 2) {
log.warn("Authentication of " + this.logging.removeCRLF(requestUri) + " failed - invalid credentials format");
throw wae;
}
String loginName = credentials[0];
String password = credentials[1];
if (!validateUserAndPassword(loginName, password, usernamePasswordMap)) {
log.warn("Authentication of " + this.logging.removeCRLF(requestUri) + " failed - user password mismatch");
throw wae;
}
}
}
示例8: authenticateLocalRequest
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
public void authenticateLocalRequest(ContainerRequestContext request) {
WebApplicationException wae = new WebApplicationException(
Response.status(Response.Status.UNAUTHORIZED).entity("not authorized").build());
if(request.getUriInfo()!=null && request.getUriInfo().getRequestUri()!=null) {
String remoteAddr = request.getUriInfo().getRequestUri().getHost();
if (remoteAddr == null || !(remoteAddr.equals("127.0.0.1") || remoteAddr.equals("localhost"))) {
throw wae;
}
} else {
throw wae;
}
}
示例9: extract
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
static RequestParameters extract(@NonNull ApiOperation apiOperation, @NonNull Swagger swagger,
@NonNull ContainerRequestContext containerRequestContext) {
UriInfo uriInfo = containerRequestContext.getUriInfo();
RequestParameters parameters = new RequestParameters();
parameters.putAll(uriInfo.getPathParameters());
parameters.putAll(uriInfo.getQueryParameters());
parameters.putAll(containerRequestContext.getHeaders());
try {
Optional<Parameter> parameter =
apiOperation.getOperation().getParameters().stream().filter(parameterBody -> {
if ((parameterBody instanceof BodyParameter)) {
ModelImpl parameterModel = getBodyParameter(swagger, (BodyParameter) parameterBody);
return "object".equalsIgnoreCase(parameterModel.getType())
&& "body".equalsIgnoreCase(parameterBody.getIn());
}
return false;
}).findFirst();
extractBodyParameter(parameters, containerRequestContext, parameter);
} catch (IOException ioe) {
throw new InternalServerErrorException("Error processing request body.", ioe);
}
LOG.info("Extracted parameters: {}", parameters);
return parameters;
}
示例10: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext)
throws IOException {
final UriInfo info = requestContext.getUriInfo();
MultivaluedMap<String, String> parameters = info.getQueryParameters();
String format = parameters.getFirst("format");
if (format == null) {
return;
}
requestContext.getHeaders().putSingle(HttpHeaders.ACCEPT, format);
}
示例11: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
UriInfo info = requestContext.getUriInfo();
if (!info.getQueryParameters().containsKey("pretty")) {
return;
}
ObjectWriterInjector.set(new PrettyPrintWriter(ObjectWriterInjector.getAndClear()));
}
示例12: handle
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
public static void handle(ContainerRequestContext requestContext) {
final UriInfo info = requestContext.getUriInfo();
final String path = info.getPath();
final boolean openUrl = path.startsWith("bootstrap/firstuser") || path.startsWith("test/create");
if(openUrl){
return;
}
requestContext.abortWith(Response.status(Response.Status.FORBIDDEN)
.entity(new GenericErrorMessage(GenericErrorMessage.NO_USER_MSG))
.build());
}