下面列出了javax.ws.rs.core.UriBuilder#replacePath() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Uriのオーバーライド処理.
* @param request 加工するリクエスト
*/
private void uriOverride(final ContainerRequest request) {
String xForwardedProto = request.getHeaderValue(DcCoreUtils.HttpHeaders.X_FORWARDED_PROTO);
String xForwardedHost = request.getHeaderValue(DcCoreUtils.HttpHeaders.X_FORWARDED_HOST);
String xForwardedPath = request.getHeaderValue(DcCoreUtils.HttpHeaders.X_FORWARDED_PATH);
UriBuilder bub = request.getBaseUriBuilder();
UriBuilder rub = request.getRequestUriBuilder();
if (xForwardedProto != null) {
bub.scheme(xForwardedProto);
rub.scheme(xForwardedProto);
}
if (xForwardedHost != null) {
bub.host(xForwardedHost);
rub.host(xForwardedHost);
}
if (xForwardedPath != null) {
bub.replacePath("/");
// クエリを含んでいる場合は、クエリを削除してリクエストパスに設定する
if (xForwardedPath.contains("?")) {
xForwardedPath = xForwardedPath.substring(0, xForwardedPath.indexOf("?"));
}
rub.replacePath(xForwardedPath);
}
request.setUris(bub.build(), rub.build());
}
private static URI removeDeviceProxyPrefix(URI uri) {
if (uri == null) {
return null;
}
UriBuilder builder = UriBuilder.fromUri(uri);
String newPath = rmDeviceStr(uri.getRawPath());
builder.replacePath(newPath);
return builder.build();
}
/**
* Removes the last path segment from the given URI. That is, returns
* the parent of the given URI.
*
* @param uri given URI
* @return parent URI
*/
public static URI rmLastPathSegment(URI uri) {
if (uri == null) {
return null;
}
UriBuilder builder = UriBuilder.fromUri(uri);
String newPath = rmLastPathSegmentStr(uri.getRawPath());
builder.replacePath(newPath);
return builder.build();
}
private UriBuilder initUriBuilder(UriBuilder b) {
b.scheme(scheme);
b.host(hostname);
b.port(port);
b.replacePath(contextPath);
return b;
}
private String createPreviewUrlLinkValue(UriBuilder uriBuilder, Command command) {
UriBuilder previewUriBuilder =
uriBuilder.clone().host(command.getAttributes().get(PREVIEW_URL_ATTRIBUTE));
previewUriBuilder.replacePath(null);
return previewUriBuilder.build().toString();
}
/**
* @param request request
* @return Get the content request context based on the specified request
*/
@SuppressWarnings("deprecation")
private ContentRequestContext getContentRequest(final HttpServletRequest request) {
final String ref = request.getParameter("ref");
final String clientId = request.getParameter("clientId");
final UriBuilder refUriBuilder = UriBuilder.fromUri(ref);
// base the data ref on the request parameter but ensure the scheme is based off the incoming request...
// this is necessary for scenario's where the NiFi instance is behind a proxy running a different scheme
refUriBuilder.scheme(request.getScheme());
// If there is path context from a proxy, remove it since this request will be used inside the cluster
final String proxyContextPath = getFirstHeaderValue(request, PROXY_CONTEXT_PATH_HTTP_HEADER, FORWARDED_CONTEXT_HTTP_HEADER, FORWARDED_PREFIX_HTTP_HEADER);
if (StringUtils.isNotBlank(proxyContextPath)) {
refUriBuilder.replacePath(StringUtils.substringAfter(UriBuilder.fromUri(ref).build().getPath(), proxyContextPath));
}
final URI refUri = refUriBuilder.build();
final String query = refUri.getQuery();
String rawClusterNodeId = null;
if (query != null) {
final String[] queryParameters = query.split("&");
for (int i = 0; i < queryParameters.length; i++) {
if (queryParameters[0].startsWith("clusterNodeId=")) {
rawClusterNodeId = StringUtils.substringAfterLast(queryParameters[0], "clusterNodeId=");
}
}
}
final String clusterNodeId = rawClusterNodeId;
return new ContentRequestContext() {
@Override
public String getDataUri() {
return refUri.toString();
}
@Override
public String getClusterNodeId() {
return clusterNodeId;
}
@Override
public String getClientId() {
return clientId;
}
@Override
public String getProxiedEntitiesChain() {
return null;
}
};
}