本文整理汇总了Java中javax.ws.rs.core.Response.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getHeaders方法的具体用法?Java Response.getHeaders怎么用?Java Response.getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response
的用法示例。
在下文中一共展示了Response.getHeaders方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putResource
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public <I> void putResource(String resourcePath, final I input, Cookie cookie) throws Exception {
Response response = null;
try {
final Invocation.Builder requestBuilder = getRequestBuilder(resourcePath);
response = requestBuilder.async().put(Entity.entity(input, this.mediaType), new InvocationLogCallback())
.get(REQUEST_THREAD_TIMEOUT, TimeUnit.MILLISECONDS);
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status == Response.Status.OK || status == Response.Status.NO_CONTENT) {
this.lastRequestHeaders = response.getHeaders();
} else {
throw new ClientResponseNotOkException();
}
} catch (Exception ex) {
RestClientException restClientException = createRestClientException("PUT", this.webTarget.getUri() + "/"
+ resourcePath, input, response, ex);
log.debug("Error invoking putResource", restClientException);
throw restClientException;
}
}
示例2: getWithoutOriginSet
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void getWithoutOriginSet() {
requestGoneThrough = false;
Response resp = target("/").request().get();
assertTrue(requestGoneThrough);
assertEquals(204, resp.getStatus());
MultivaluedMap<String, Object> headers = resp.getHeaders();
assertEquals("orgin, content-type, accept, authorization", headers.get("Access-Control-Allow-Headers").get(0));
assertEquals("true", headers.get("Access-Control-Allow-Credentials").get(0));
assertEquals("GET, POST, PUT, DELETE, OPTIONS", headers.get("Access-Control-Allow-Methods").get(0));
}
示例3: getResource
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public <T> T getResource(String resourcePath, final Class<T> clazz, MultivaluedMap<String, String> params,
MultivaluedMap<String, String> headers) throws Exception {
Response response = null;
try {
final Invocation.Builder requestBuilder = getRequestBuilder(resourcePath, params, headers);
response = requestBuilder.async().get(new InvocationLogCallback())
.get(REQUEST_THREAD_TIMEOUT, TimeUnit.MILLISECONDS);
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status == Response.Status.OK) {
this.lastRequestHeaders = response.getHeaders();
if (response.hasEntity()) {
return response.readEntity(clazz);
}
return null;
} else {
throw new ClientResponseNotOkException();
}
} catch (Exception ex) {
RestClientException restClientException = createRestClientException("GET", this.webTarget.getUri() + "/"
+ resourcePath, null, response, ex);
log.debug("Error invoking getResources", restClientException);
throw restClientException;
}
}
示例4: postResource
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <I, O> O postResource(String resourcePath, Class<O> resClazz, final I input,
MultivaluedMap<String, String> params, MultivaluedMap<String, String> headers) throws Exception {
Response response = null;
try {
final Invocation.Builder requestBuilder = getRequestBuilder(resourcePath, params, headers);
response = requestBuilder.async().post(Entity.entity(input, this.mediaType),new InvocationLogCallback())
.get(REQUEST_THREAD_TIMEOUT, TimeUnit.MILLISECONDS);
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status == Response.Status.OK || status == Response.Status.CREATED) {
this.lastRequestHeaders = response.getHeaders();
if (response.hasEntity()) {
return response.readEntity(resClazz);
}
return (O) response;
} else if (status == Response.Status.NO_CONTENT) {
return null;
} else {
throw new ClientResponseNotOkException();
}
} catch (Exception ex) {
RestClientException restClientException = createRestClientException("POST", this.webTarget.getUri() + "/"
+ resourcePath, input, response, ex);
log.debug("Error invoking postResource", restClientException);
throw restClientException;
}
}
示例5: tolerant_options
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void tolerant_options() {
ServiceConfig serviceConfig = TestService.config
.addon(CorsFilterAddon.defaults);
Response call = testServiceRunnerJettyWithDefaults(serviceConfig)
.oneShot(target -> target
.path("api")
.path(TestService.PATH)
.request()
.options()
);
MultivaluedMap<String, Object> headers = call.getHeaders();
assertThat(headers.getFirst(ALLOW_CREDENTIALS)).isEqualTo("true");
}
示例6: getWithoutRightOriginSet
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void getWithoutRightOriginSet() {
requestGoneThrough = false;
Response resp = target("/").request().header("Origin", "http://localhost:8080").get();
assertTrue(requestGoneThrough);
assertEquals(204, resp.getStatus());
MultivaluedMap<String, Object> headers = resp.getHeaders();
assertEquals("orgin, content-type, accept, authorization", headers.get("Access-Control-Allow-Headers").get(0));
assertEquals("true", headers.get("Access-Control-Allow-Credentials").get(0));
assertEquals("GET, POST, PUT, DELETE, OPTIONS", headers.get("Access-Control-Allow-Methods").get(0));
}
示例7: wrapResponse
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public WrappedResponse wrapResponse(Response response)
{
return new WrappedResponse(response.getStatus(),
response.getStatusInfo().getReasonPhrase(),
response.getHeaders(),
parseEntity(response));
}
示例8: toResponse
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public Response toResponse(WebApplicationException exception) {
LOGGER.error("WebApplicationException:", exception);
LOGGER.debug("Constructing Error Response for: [{}]", exception.toString());
ErrorResponse errorResponse = new ErrorResponse();
Response exceptionResponse = exception.getResponse();
Response.StatusType statusInfo = exceptionResponse.getStatusInfo();
errorResponse.setCode(statusInfo.getStatusCode());
errorResponse.setStatus(statusInfo.getReasonPhrase());
errorResponse.setMessage(exception.getMessage());
Response.ResponseBuilder responseBuilder = Response.status(statusInfo)
.entity(errorResponse)
.type(MediaType.APPLICATION_JSON);
MultivaluedMap<String, Object> headers = exceptionResponse.getHeaders();
if (headers.size() > 0) {
LOGGER.debug("Adding headers:");
for (Map.Entry<String, List<Object>> entry : headers.entrySet()) {
String headerKey = entry.getKey();
List<Object> headerValues = entry.getValue();
LOGGER.debug(" {} -> {}", headerKey, headerValues);
if (headerValues.size() == 1) {
responseBuilder.header(headerKey, headerValues.get(0));
} else {
responseBuilder.header(headerKey, headerValues);
}
}
}
return responseBuilder.build();
}
开发者ID:durimkryeziu,项目名称:jersey-2.x-webapp-for-servlet-container,代码行数:36,代码来源:WebApplicationExceptionMapper.java
示例9: main
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public static final void main (String[] args) throws Exception {
String TOKEN_URL="http://10.42.0.5:8080/auth/realms/quickstart/protocol/openid-connect/token";
//String TOKEN_URL="http://127.0.0.1:8081/auth/realms/quickstart/protocol/openid-connect/token";
String url = args[0];
LOG.info("run calls to server url: " + url);
if (url== null || url.isEmpty()){
throw new RuntimeException("server url is not specified.");
}
Client client = new ResteasyClientBuilder().register(MessageProvider.class).build();
Invocation.Builder request = client.target(url).request();
if (url.contains("secured")){
OpenIDClient openIDclient = new OpenIDClient(TOKEN_URL,CLIENT_ID);
AccessToken accessToken = openIDclient.getAccessToken("alice", "alice");
String token = accessToken.getAccessToken();
request.header("Authorization", "Bearer " +token);
}
Response response =request.get();
int status = response.getStatus();
LOG.info("response status: " + status);
LOG.info("response headers:");
MultivaluedMap<String, Object> headers = response.getHeaders();
for (Iterator<String> iterator = headers.keySet().iterator(); iterator.hasNext();) {
String key= iterator.next();
LOG.info(key + ": " + headers.get(key));
}
if (status == 200) {
Message message = response.readEntity(Message.class);
LOG.info("got response: " + message);
}
response.close();
}