當前位置: 首頁>>代碼示例>>Java>>正文


Java ContainerRequestContext.getUriInfo方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:stevespringett,項目名稱:Alpine,代碼行數:9,代碼來源:PrettyPrintFilter.java

示例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());
}
 
開發者ID:dotwebstack,項目名稱:dotwebstack-framework,代碼行數:23,代碼來源:HostPreMatchingRequestFilter.java

示例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);
}
 
開發者ID:AdamBien,項目名稱:SpanEE,代碼行數:22,代碼來源:SpanEEContainerRequestFilter.java

示例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;

    }
 
開發者ID:xujiajun,項目名稱:tastjava,代碼行數:18,代碼來源:ResourceAuthFilter.java

示例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();
    }
}
 
開發者ID:skjolber,項目名稱:json-log-domain,代碼行數:14,代碼來源:LogFilter.java

示例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());
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:13,代碼來源:JaxrsRequestContext.java

示例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;
        }
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:43,代碼來源:AuthUtil.java

示例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;
    }

}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:14,代碼來源:AuthUtil.java

示例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;
}
 
開發者ID:dotwebstack,項目名稱:dotwebstack-framework,代碼行數:31,代碼來源:RequestParameterExtractor.java

示例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);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:13,代碼來源:MediaTypeFilter.java

示例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()));
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:11,代碼來源:JSONPrettyPrintFilter.java

示例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());
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:14,代碼來源:NoUserFilter.java


注:本文中的javax.ws.rs.container.ContainerRequestContext.getUriInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。