本文整理匯總了Java中com.sun.jersey.spi.container.ContainerRequest.getHeaderValue方法的典型用法代碼示例。如果您正苦於以下問題:Java ContainerRequest.getHeaderValue方法的具體用法?Java ContainerRequest.getHeaderValue怎麽用?Java ContainerRequest.getHeaderValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.jersey.spi.container.ContainerRequest
的用法示例。
在下文中一共展示了ContainerRequest.getHeaderValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addResponseHeaders
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
/**
* 全てのレスポンスに共通するレスポンスヘッダーを追加する.
* Access-Control-Allow-Origin, Access-Control-Allow-Headers<br/>
* X-Personium-Version<br/>
* @param request
* @param response
*/
private void addResponseHeaders(final ContainerRequest request, final ContainerResponse response) {
MultivaluedMap<String, Object> mm = response.getHttpHeaders();
String acrh = request.getHeaderValue(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
if (acrh != null) {
mm.putSingle(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, acrh);
} else {
mm.remove(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS);
}
mm.putSingle(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, HttpHeaders.Value.ASTERISK);
// X-Personium-Version
mm.putSingle(HttpHeaders.X_PERSONIUM_VERSION, PersoniumUnitConfig.getCoreVersion());
}
示例2: responseOptionsMethod
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
/**
* 認証なしOPTIONメソッドのレスポンスを返卻する.
* @param request フィルタ前リクエスト
*/
private void responseOptionsMethod(ContainerRequest request) {
String authValue = request.getHeaderValue(org.apache.http.HttpHeaders.AUTHORIZATION);
String methodName = request.getMethod();
if (authValue == null && HttpMethod.OPTIONS.equals(methodName)) {
Response res = PersoniumCoreUtils.responseBuilderForOptions(
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.PUT,
HttpMethod.DELETE,
HttpMethod.HEAD,
io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MERGE,
io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MKCOL,
io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MOVE,
io.personium.common.utils.PersoniumCoreUtils.HttpMethod.PROPFIND,
io.personium.common.utils.PersoniumCoreUtils.HttpMethod.PROPPATCH,
io.personium.common.utils.PersoniumCoreUtils.HttpMethod.ACL
).build();
// 例外を発行することでServletへ製禦を渡さない
throw new WebApplicationException(res);
}
}
示例3: checkRequestHeader
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
/**
* リクエストヘッダーの値をチェックする.
* 現在は、Acceptヘッダーのみ(US-ASCII文字以外かどうか)をチェックする
* @param request フィルター前リクエスト
*/
private void checkRequestHeader(ContainerRequest request) {
// ヘッダーのキー名に全角文字が含まれる場合は、その文字を含めたキー名となるため、実際にはこの指定は無視される。
// Jersey1.10では、Acceptヘッダーのキー名と値にUS-ASCII文字以外が含まれる場合に異常終了するため以下を対処
// (Acceptを含む他のヘッダーにも同様の処理が行われるが、上記理由により動作上は問題ないと判斷)
// -キー名に含まれる場合は、その指定を無効(Accept:*/*)とする(Jerseryで組み込み済み)。
// -値に含まれる場合は、400エラーとする。
InBoundHeaders newHeaders = new InBoundHeaders();
MultivaluedMap<String, String> headers = request.getRequestHeaders();
for (String header : headers.keySet()) {
if (header.contains(org.apache.http.HttpHeaders.ACCEPT)
&& !acceptHeaderValueRegex.matcher(header).matches()) {
continue;
} else {
newHeaders.put(header, request.getRequestHeader(header));
}
}
request.setHeaders(newHeaders);
String acceptValue = request.getHeaderValue(org.apache.http.HttpHeaders.ACCEPT);
if (acceptValue != null && !acceptHeaderValueRegex.matcher(acceptValue).matches()) {
PersoniumCoreException exception = PersoniumCoreException.OData.BAD_REQUEST_HEADER_VALUE.params(
org.apache.http.HttpHeaders.ACCEPT, acceptValue);
throw exception;
}
}
示例4: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response)
{
if (!isCorsNeeded(request))
return response;
MultivaluedMap<String, Object> headers = response.getHttpHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
String acrh = request.getHeaderValue("Access-Control-Request-Headers");
if (acrh != null && !acrh.isEmpty())
headers.add("Access-Control-Allow-Headers", acrh);
return response;
}
示例5: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerRequest filter(ContainerRequest request) {
// Get session id from request header
final String sessionId = request.getHeaderValue("session-id");
SessionUser user = null;
Session session = null;
if (sessionId != null && sessionId.length() > 0) {
// Load session object from repository
// session = sessionRepository.findOne(sessionId);
// Load associated user from session
// if (session != null) {
// // user = userRepository.findOne(session.getUserId());
// }
}
request.setSecurityContext(new ElabSecurityContext(session, user));
return request;
}
示例6: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest req,
ContainerResponse contResp) {
ResponseBuilder resp = Response.fromResponse(contResp.getResponse());
resp.header("Access-Control-Allow-Origin", "*").header(
"Access-Control-Allow-Methods", "GET, POST, OPTIONS");
String reqHead = req.getHeaderValue("Access-Control-Request-Headers");
if (null != reqHead && !reqHead.equals(null)) {
resp.header("Access-Control-Allow-Headers", reqHead);
}
contResp.setResponse(resp.build());
return contResp;
}
示例7: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
String incomingOrigin = request.getHeaderValue(CorsHeaders.ORIGIN);
if (incomingOrigin == null) {
return response;
}
MultivaluedMap<String, Object> h = response.getHttpHeaders();
putIfNotPresent(h, CorsHeaders.ALLOW_ORIGIN, allowOrigin);
putIfNotPresent(h, CorsHeaders.MAX_AGE, Integer.toString(maxAge));
if (!allowMethods.isEmpty()) {
putIfNotPresent(h, CorsHeaders.ALLOW_METHODS, allowMethods);
}
if (!allowHeaders.isEmpty()) {
putIfNotPresent(h, CorsHeaders.ALLOW_HEADERS, allowHeaders);
}
if (allowCredentials) {
putIfNotPresent(h, CorsHeaders.ALLOW_CREDENTIALS, Boolean.toString(allowCredentials));
}
return response;
}
示例8: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
String incomingOrigin = request.getHeaderValue(CorsHeaders.ORIGIN);
if (incomingOrigin == null) {
return response;
}
MultivaluedMap<String, Object> h = response.getHttpHeaders();
putIfNotPresent(h, CorsHeaders.ALLOW_ORIGIN, allowOrigin);
if (!exposeHeaders.isEmpty()) {
putIfNotPresent(h, CorsHeaders.EXPOSE_HEADERS, exposeHeaders);
}
if (allowCredentials) {
putIfNotPresent(h, CorsHeaders.ALLOW_CREDENTIALS, Boolean.toString(allowCredentials));
}
return response;
}
示例9: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request,
ContainerResponse response) {
ResponseBuilder responseBuilder = Response.fromResponse(response
.getResponse());
responseBuilder.header("Access-Control-Allow-Origin", "*").header(
"Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS");
String requestHead = request
.getHeaderValue("Access-Control-Request-Headers");
if (null != requestHead && !requestHead.equals(null)) {
responseBuilder.header("Access-Control-Allow-Headers", requestHead);
}
response.setResponse(responseBuilder.build());
return response;
}
示例10: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest req, ContainerResponse contResp) {
ResponseBuilder resp = Response.fromResponse(contResp.getResponse());
resp.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
String reqHead = req.getHeaderValue("Access-Control-Request-Headers");
if(null != reqHead && !reqHead.equals("")){
resp.header("Access-Control-Allow-Headers", reqHead);
}
contResp.setResponse(resp.build());
return contResp;
}
示例11: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerRequest filter(ContainerRequest containerRequest) throws WebApplicationException {
// String method = containerRequest.getMethod();
// String path = containerRequest.getPath(true);
String auth = containerRequest.getHeaderValue("authorization");
if(auth == null){
throw new WebApplicationException(Status.UNAUTHORIZED);
}
String[] credentials = decode(auth);
if(credentials == null || credentials.length != 2){
throw new WebApplicationException(Status.UNAUTHORIZED);
}
String uid = UserAuthentication.authenticate(credentials[0], credentials[1]);
if(uid == null){
throw new WebApplicationException(Status.UNAUTHORIZED);
}
containerRequest.getRequestHeaders().add("uid", uid);
return containerRequest;
}
示例12: uriOverride
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
/**
* Uriのオーバーライド処理.
* @param request 加工するリクエスト
*/
private void uriOverride(final ContainerRequest request) {
String xForwardedProto = request.getHeaderValue(PersoniumCoreUtils.HttpHeaders.X_FORWARDED_PROTO);
String xForwardedHost = request.getHeaderValue(PersoniumCoreUtils.HttpHeaders.X_FORWARDED_HOST);
String xForwardedPath = request.getHeaderValue(PersoniumCoreUtils.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());
}
示例13: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerResponse filter(final ContainerRequest req, final ContainerResponse cres) {
Response.ResponseBuilder resp = Response.fromResponse(cres.getResponse());
resp.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
String reqHead = req.getHeaderValue("Access-Control-Request-Headers");
System.out.println("Head:" + reqHead);
if(null != reqHead && !reqHead.equals("")){
resp.header("Access-Control-Allow-Headers", reqHead);
}
cres.setResponse(resp.build());
return cres;
}
示例14: supportsRequestedVersion
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public boolean supportsRequestedVersion(boolean headerRequired, float minVersion, float maxVersion, ContainerRequest request) {
boolean isSupported = true;
String versionHeader = request.getHeaderValue(versionHeaderName);
if (headerRequiredButNotPresent(headerRequired, versionHeader) || headerPresentButNotSupported(minVersion, maxVersion, versionHeader)) {
isSupported = false;
}
return isSupported;
}
示例15: filter
import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
@Override
public ContainerRequest filter(ContainerRequest request) {
// OPTIONS calls don't need authorization, apparently
if ("OPTIONS".equals(request.getMethod())) {
return request;
}
// Authentication via header or cookie
String authentication = request.getHeaderValue(HEADER);
if (StringUtils.isBlank(authentication)) {
Cookie cookie = request.getCookies().get(HEADER);
if (cookie != null) {
authentication = cookie.getValue();
}
}
// Log.info("authentication={}", authentication);
if (StringUtils.isNotBlank(authentication)) {
List<String> parts = Lists.newArrayList(Splitter.on(" ").split(authentication));
if (parts.size() == 2) {
String scheme = parts.get(0);
String key = parts.get(1);
try {
SecurityContext securityContext = sessionService.getSecurityContext(scheme, key);
if (securityContext != null) {
request.setSecurityContext(securityContext);
return request;
}
} catch (nl.knaw.huygens.security.client.UnauthorizedException e) {
throw new UnauthorizedException(e.getMessage());
}
}
} else {
}
throw new UnauthorizedException("No valid " + HEADER + " header in request");
}