javax.ws.rs.core.UriBuilder.queryParam()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中javax.ws.rs.core.UriBuilder.queryParam()方法的一些代码示例,展示了UriBuilder.queryParam()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UriBuilder.queryParam()方法的具体详情如下:
包路径:javax.ws.rs.core.UriBuilder
类名称:UriBuilder
方法名:queryParam

UriBuilder.queryParam介绍

[英]Append a query parameter to the existing set of query parameters. If multiple values are supplied the parameter will be added once per value.
[中]将查询参数附加到现有的查询参数集。如果提供了多个值,则每个值将添加一次参数。

代码示例

代码示例来源:origin: opentripplanner/OpenTripPlanner

private URL getYahooGeocoderUrl(String address) throws IOException {
  UriBuilder uriBuilder = UriBuilder.fromUri("http://where.yahooapis.com/geocode");
  uriBuilder.queryParam("location", address);
  uriBuilder.queryParam("flags", "J");
  uriBuilder.queryParam("appid", appId);
  if (locale != null) {
    uriBuilder.queryParam("locale", locale);
    uriBuilder.queryParam("gflags", "L");
  }
  URI uri = uriBuilder.build();
  return new URL(uri.toString());
}

代码示例来源:origin: prestodb/presto

private String rewriteUri(UriInfo uriInfo, String uri)
{
  return uriInfo.getAbsolutePathBuilder()
      .replacePath("/v1/proxy")
      .queryParam("uri", uri)
      .queryParam("hmac", hmac.hashString(uri, UTF_8))
      .build()
      .toString();
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

private URL getGoogleGeocoderUrl(String address) throws IOException {
  UriBuilder uriBuilder = UriBuilder.fromUri("http://maps.google.com/maps/api/geocode/json");
  uriBuilder.queryParam("sensor", false);
  uriBuilder.queryParam("address", address);
  URI uri = uriBuilder.build();
  return new URL(uri.toString());
}

代码示例来源:origin: jersey/jersey

@Override
public String start() {
  final UriBuilder uriBuilder = UriBuilder.fromUri(authorizationUri);
  for (final Map.Entry<String, String> entry : authorizationProperties.entrySet()) {
    uriBuilder.queryParam(entry.getKey(), entry.getValue());
  }
  return uriBuilder.build().toString();
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

private URL getGeocoderURL(String geocoderBaseUrl, String address) throws MalformedURLException {
  UriBuilder builder = UriBuilder.fromUri(geocoderBaseUrl);
  builder.queryParam("address", address);
  URI uri = builder.build();
  return new URL(uri.toString());
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

private URL getBanoGeocoderUrl(String address, Envelope bbox) throws IOException {
    UriBuilder uriBuilder = UriBuilder.fromUri(BANO_URL);
    uriBuilder.queryParam("q", address);
    uriBuilder.queryParam("limit", CLAMP_RESULTS);
    if (bbox != null) {
      uriBuilder.queryParam("lat", bbox.centre().y);
      uriBuilder.queryParam("lon", bbox.centre().x);
    }
    URI uri = uriBuilder.build();
    return new URL(uri.toString());
  }
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

private URL getNominatimGeocoderUrl(String address, Envelope bbox) throws IOException {
  UriBuilder uriBuilder = UriBuilder.fromUri(nominatimUrl);
  uriBuilder.queryParam("q", address);
  uriBuilder.queryParam("format", "json");
  if (bbox != null) {
    uriBuilder.queryParam("viewbox", bbox.getMinX() + "," + bbox.getMinY() + "," + bbox.getMaxX() + "," + bbox.getMaxY());
    uriBuilder.queryParam("bounded", 1);
  } else if (viewBox != null) {
    uriBuilder.queryParam("viewbox", viewBox);
    uriBuilder.queryParam("bounded", 1);
  }
  if (resultLimit != null) {
    uriBuilder.queryParam("limit", resultLimit);
  }
  if (emailAddress != null) {
    uriBuilder.queryParam("email", emailAddress);
  }
  
  URI uri = uriBuilder.build();
  return new URL(uri.toString());
}

代码示例来源:origin: jersey/jersey

@GET
public ItemsRepresentation query(
    @Context javax.ws.rs.core.UriInfo info,
    @QueryParam("offset") @DefaultValue("-1") int offset, @DefaultValue("-1") @QueryParam("limit") int limit) {
  if (offset == -1 || limit == -1) {
    offset = offset == -1 ? 0 : offset;
    limit = limit == -1 ? 10 : limit;
    throw new WebApplicationException(
        Response.seeOther(info.getRequestUriBuilder().queryParam("offset", offset)
            .queryParam("limit", limit).build())
            .build()
    );
  }
  return new ItemsRepresentation(itemsModel, offset, limit);
}

代码示例来源:origin: jersey/jersey

public String start() {
  final Response response = addProperties(client.target(requestTokenUri).request())
      .post(null);
  if (response.getStatus() != 200) {
    throw new RuntimeException(LocalizationMessages.ERROR_REQUEST_REQUEST_TOKEN(response.getStatus()));
  }
  final MultivaluedMap<String, String> formParams = response.readEntity(Form.class).asMap();
  parameters.token(formParams.getFirst(OAuth1Parameters.TOKEN));
  secrets.tokenSecret(formParams.getFirst(OAuth1Parameters.TOKEN_SECRET));
  return UriBuilder.fromUri(authorizationUri).queryParam(OAuth1Parameters.TOKEN, parameters.getToken())
      .build().toString();
}

代码示例来源:origin: jersey/jersey

private void addHint(Application wadlApplication) {
  // TODO: this not-null check is here only because of unit tests
  if (uriInfo != null) {
    Doc d = new Doc();
    String message;
    if (detailedWadl) {
      final String uriWithoutQueryParam = UriBuilder.fromUri(uriInfo.getRequestUri()).replaceQuery("").build()
          .toString();
      message = LocalizationMessages.WADL_DOC_EXTENDED_WADL(WadlUtils.DETAILED_WADL_QUERY_PARAM, uriWithoutQueryParam);
    } else {
      final String uriWithQueryParam = UriBuilder.fromUri(uriInfo.getRequestUri())
          .queryParam(WadlUtils.DETAILED_WADL_QUERY_PARAM, "true").build().toString();
      message = LocalizationMessages.WADL_DOC_SIMPLE_WADL(WadlUtils.DETAILED_WADL_QUERY_PARAM, uriWithQueryParam);
    }
    d.getOtherAttributes().put(new QName(WadlApplicationContextImpl.WADL_JERSEY_NAMESPACE, "hint", "jersey"), message);
    wadlApplication.getDoc().add(d);
  }
}

代码示例来源:origin: jersey/jersey

private void addHint(Application wadlApplication) {
  // TODO: this not-null check is here only because of unit tests
  if (uriInfo != null) {
    Doc d = new Doc();
    String message;
    if (detailedWadl) {
      final String uriWithoutQueryParam = UriBuilder.fromUri(uriInfo.getRequestUri()).replaceQuery("").build()
          .toString();
      message = LocalizationMessages.WADL_DOC_EXTENDED_WADL(WadlUtils.DETAILED_WADL_QUERY_PARAM, uriWithoutQueryParam);
    } else {
      final String uriWithQueryParam = UriBuilder.fromUri(uriInfo.getRequestUri())
          .queryParam(WadlUtils.DETAILED_WADL_QUERY_PARAM, "true").build().toString();
      message = LocalizationMessages.WADL_DOC_SIMPLE_WADL(WadlUtils.DETAILED_WADL_QUERY_PARAM, uriWithQueryParam);
    }
    d.getOtherAttributes().put(new QName(WadlApplicationContextImpl.WADL_JERSEY_NAMESPACE, "hint", "jersey"), message);
    wadlApplication.getDoc().add(d);
  }
}

代码示例来源:origin: apache/nifi

@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.WILDCARD)
@Path("oidc/logout")
@ApiOperation(
    value = "Performs a logout in the OpenId Provider.",
    notes = NON_GUARANTEED_ENDPOINT
)
public void oidcLogout(@Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse) throws Exception {
  if (!httpServletRequest.isSecure()) {
    throw new IllegalStateException("User authentication/authorization is only supported when running over HTTPS.");
  }
  if (!oidcService.isOidcEnabled()) {
    throw new IllegalStateException("OpenId Connect is not configured.");
  }
  URI endSessionEndpoint = oidcService.getEndSessionEndpoint();
  String postLogoutRedirectUri = generateResourceUri("..", "nifi");
  if (endSessionEndpoint == null) {
    // handle the case, where the OpenID Provider does not have an end session endpoint
    httpServletResponse.sendRedirect(postLogoutRedirectUri);
  } else {
    URI logoutUri = UriBuilder.fromUri(endSessionEndpoint)
        .queryParam("post_logout_redirect_uri", postLogoutRedirectUri)
        .build();
    httpServletResponse.sendRedirect(logoutUri.toString());
  }
}

代码示例来源:origin: glyptodon/guacamole-client

/**
 * Returns the "otpauth" URI for the secret key used to generate TOTP codes
 * for the current user. If the secret key is not being exposed to
 * facilitate enrollment, null is returned.
 *
 * @return
 *     The "otpauth" URI for the secret key used to generate TOTP codes
 *     for the current user, or null is the secret ket is not being exposed
 *     to facilitate enrollment.
 *
 * @throws GuacamoleException
 *     If the configuration information required for generating the key URI
 *     cannot be read from guacamole.properties.
 */
@JsonProperty("keyUri")
public URI getKeyURI() throws GuacamoleException {
  // Do not generate a key URI if no key is being exposed
  if (key == null)
    return null;
  // Format "otpauth" URL (see https://github.com/google/google-authenticator/wiki/Key-Uri-Format)
  String issuer = confService.getIssuer();
  return UriBuilder.fromUri("otpauth://totp/")
      .path(issuer + ":" + key.getUsername())
      .queryParam("secret", BASE32.encode(key.getSecret()))
      .queryParam("issuer", issuer)
      .queryParam("algorithm", confService.getMode())
      .queryParam("digits", confService.getDigits())
      .queryParam("period", confService.getPeriod())
      .build();
}

代码示例来源:origin: apache/nifi

@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.WILDCARD)
@Path("knox/request")
@ApiOperation(
    value = "Initiates a request to authenticate through Apache Knox.",
    notes = NON_GUARANTEED_ENDPOINT
)
public void knoxRequest(@Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse) throws Exception {
  // only consider user specific access over https
  if (!httpServletRequest.isSecure()) {
    forwardToMessagePage(httpServletRequest, httpServletResponse, "User authentication/authorization is only supported when running over HTTPS.");
    return;
  }
  // ensure knox is enabled
  if (!knoxService.isKnoxEnabled()) {
    forwardToMessagePage(httpServletRequest, httpServletResponse, "Apache Knox SSO support is not configured.");
    return;
  }
  // build the originalUri, and direct back to the ui
  final String originalUri = generateResourceUri("access", "knox", "callback");
  // build the authorization uri
  final URI authorizationUri = UriBuilder.fromUri(knoxService.getKnoxUrl())
      .queryParam("originalUrl", originalUri.toString())
      .build();
  // generate the response
  httpServletResponse.sendRedirect(authorizationUri.toString());
}

代码示例来源:origin: apache/nifi

.queryParam("client_id", oidcService.getClientId())
.queryParam("response_type", "code")
.queryParam("scope", oidcService.getScope().toString())
.queryParam("state", state.getValue())
.queryParam("redirect_uri", getOidcCallback())
.build();

代码示例来源:origin: apache/drill

@Override
 public void filter(ContainerRequestContext requestContext)
   throws IOException {
  final SecurityContext sc = requestContext.getSecurityContext();
  if (!isUserLoggedIn(sc)) {
   try {
    final String destResource = URLEncoder.encode(
      requestContext.getUriInfo().getRequestUri().toString(), "UTF-8");
    final URI loginURI = requestContext.getUriInfo().getBaseUriBuilder()
      .path(LogInLogOutPages.LOGIN_RESOURCE)
      .queryParam(LogInLogOutPages.REDIRECT_QUERY_PARM, destResource)
      .build();
    requestContext
      .abortWith(Response.temporaryRedirect(loginURI).build());
   } catch (final Exception ex) {
    final String errMsg = String.format(
      "Failed to forward the request to login page: %s",
      ex.getMessage());
    LOG.error(errMsg, ex);
    requestContext
      .abortWith(Response.serverError().entity(errMsg).build());
   }
  }
 }
}

代码示例来源:origin: com.sun.jersey/jersey-server

Form f = request.getFormParameters();
for (Map.Entry<String, List<String>> param : f.entrySet()) {
  ub.queryParam(param.getKey(), param.getValue().toArray());
request.setUris(request.getBaseUri(), ub.build());

代码示例来源:origin: jersey/jersey

final Form f = ((ContainerRequest) request).readEntity(Form.class);
for (final Map.Entry<String, List<String>> param : f.asMap().entrySet()) {
  ub.queryParam(param.getKey(), param.getValue().toArray());
request.setRequestUri(request.getUriInfo().getBaseUri(), ub.build());

代码示例来源:origin: jersey/jersey

final Form f = ((ContainerRequest) request).readEntity(Form.class);
for (final Map.Entry<String, List<String>> param : f.asMap().entrySet()) {
  ub.queryParam(param.getKey(), param.getValue().toArray());
request.setRequestUri(request.getUriInfo().getBaseUri(), ub.build());

代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common

private URI getRequestUri(String absoluteUriWithoutExtension, Map<String, List<String>> queryParams) {
  final UriBuilder requestUriBuilder = UriBuilder.fromUri(absoluteUriWithoutExtension);
  for (Map.Entry<String, List<String>> queryParamEntry : queryParams.entrySet()) {
    for (String value : queryParamEntry.getValue()) {
      requestUriBuilder.queryParam(queryParamEntry.getKey(), value);
    }
  }
  return requestUriBuilder.build();
}

相关文章