當前位置: 首頁>>代碼示例>>Java>>正文


Java Response.getHeaders方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:22,代碼來源:RestBaseClient.java

示例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));
}
 
開發者ID:Mercateo,項目名稱:rest-jersey-utils,代碼行數:14,代碼來源:CorsFeatureIntegrationTest.java

示例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;
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:28,代碼來源:RestBaseClient.java

示例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;
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:31,代碼來源:RestBaseClient.java

示例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");
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:16,代碼來源:CorsFilterAddonTest.java

示例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));
}
 
開發者ID:Mercateo,項目名稱:rest-jersey-utils,代碼行數:15,代碼來源:CorsFeatureIntegrationTest.java

示例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));
}
 
開發者ID:prestodb,項目名稱:presto-manager,代碼行數:8,代碼來源:ResponseWrapper.java

示例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();
   
}
 
開發者ID:nmajorov,項目名稱:keycloak_training,代碼行數:51,代碼來源:Application.java


注:本文中的javax.ws.rs.core.Response.getHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。