下面列出了javax.ws.rs.core.UriBuilder#matrixParam() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
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);
}
}
private void addMatrixOrQueryToBuilder(UriBuilder ub,
String paramName,
ParameterType pt,
Object... pValue) {
if (pt == ParameterType.MATRIX) {
ub.matrixParam(paramName, pValue);
} else {
ub.queryParam(paramName, pValue);
}
}
@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);
}