Java Code Examples for javax.ws.rs.core.UriBuilder#matrixParam()

The following examples show how to use javax.ws.rs.core.UriBuilder#matrixParam() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestUtil.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private static URI buildBaseUri(final HttpServletRequest request, final javax.ws.rs.core.UriInfo uriInfo, final List<PathSegment> precedingPathSegments) throws ODataException {
  try {
    UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
    for (final PathSegment ps : precedingPathSegments) {
      uriBuilder = uriBuilder.path(ps.getPath());
      for (final String key : ps.getMatrixParameters().keySet()) {
        final Object[] v = ps.getMatrixParameters().get(key).toArray();
        uriBuilder = uriBuilder.matrixParam(key, v);
      }
    }

    /*
     * workaround because of host name is cached by uriInfo
     */
    uriBuilder.host(request.getServerName());

    String uriString = uriBuilder.build().toString();
    if (!uriString.endsWith("/")) {
      uriString = uriString + "/";
    }

    return new URI(uriString);
  } catch (final URISyntaxException e) {
    throw new ODataException(e);
  }
}
 
Example 2
Source File: RestUtil.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static URI buildBaseUri(final UriInfo uriInfo, final HttpServletRequest request,
    final List<PathSegment> precedingPathSegments) throws ODataException {
  try {
    String path = uriInfo.getBaseUri().getPath();
    UriBuilder uriBuilder = UriBuilder.fromUri(path);
    for (final PathSegment ps : precedingPathSegments) {
      uriBuilder = uriBuilder.path(ps.getPath());
      for (final String key : ps.getMatrixParameters().keySet()) {
        final Object[] v = ps.getMatrixParameters().get(key).toArray();
        uriBuilder = uriBuilder.matrixParam(key, v);
      }
    }

    /*
     * workaround because of host name is cached by uriInfo
     */
    uriBuilder.host(request.getServerName()).port(request.getServerPort());
    uriBuilder.scheme(request.getScheme());

    String uriString = uriBuilder.build().toString();
    if (!uriString.endsWith("/")) {
      uriString = uriString + "/";
    }

    return new URI(uriString);
  } catch (final URISyntaxException e) {
    throw new ODataException(e);
  }
}
 
Example 3
Source File: AbstractClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addMatrixOrQueryToBuilder(UriBuilder ub,
                                       String paramName,
                                       ParameterType pt,
                                       Object... pValue) {
    if (pt == ParameterType.MATRIX) {
        ub.matrixParam(paramName, pValue);
    } else {
        ub.queryParam(paramName, pValue);
    }
}
 
Example 4
Source File: ClientImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public WebTarget matrixParam(String name, Object... values) {
    checkClosed();
    checkNullValues(name, values);

    UriBuilder thebuilder = getUriBuilder();
    if (values == null || values.length == 1 && values[0] == null) {
        thebuilder.replaceMatrixParam(name, (Object[])null);
    } else {
        thebuilder.matrixParam(name, values);
    }
    return newWebTarget(thebuilder);
}