当前位置: 首页>>代码示例>>Java>>正文


Java WebTarget.request方法代码示例

本文整理汇总了Java中javax.ws.rs.client.WebTarget.request方法的典型用法代码示例。如果您正苦于以下问题:Java WebTarget.request方法的具体用法?Java WebTarget.request怎么用?Java WebTarget.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.client.WebTarget的用法示例。


在下文中一共展示了WebTarget.request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makePost

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
/**
 * Wrap the supplied element in a SOAP wrapper and post to the specified end-point
 *
 * @return Response from the remote server
 * @throws SOAPRequestError            if the remote server returns a non-200 status code
 * @throws ResponseProcessingException in case processing of a received HTTP response fails (e.g. in a filter
 *                                     or during conversion of the response entity data to an instance
 *                                     of a particular Java type).
 * @throws ProcessingException         in case the request processing or subsequent I/O operation fails.
 */
protected SoapResponse makePost(URI uri, Element requestElement) throws SOAPRequestError {
    LOG.info(format("Making SOAP request to: {0}", uri));

    Document requestDocument = soapMessageManager.wrapWithSoapEnvelope(requestElement);
    WebTarget target = client.target(uri);
    final Invocation.Builder request = target.request();
    final Response response = request.post(Entity.entity(requestDocument, MediaType.TEXT_XML_TYPE));

    try {
        if (response.getStatus() != 200) {
            LOG.warn(format("Unexpected status code ({0}) when contacting ({1}))", response.getStatus(), uri));
            // let the calling code handle this issue appropriately
            throw new SOAPRequestError(response);
        } else {
            try {
                return giveMeMySoap(response);
            } catch(BadRequestException e) {
                LOG.warn(format("Couldn't parse SOAP response when contacting ({0}))", uri), e);
                throw new SOAPRequestError(response, e);
            }
        }
    } finally {
        // Ensure that response's input stream has been closed.  This may not happen automatically in some cases
        // (e.g. the response body is never read from).
        try {
            response.close();
        } catch (ProcessingException f) {
            LOG.warn("Problem closing Jersey connection.", f);
        }
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:42,代码来源:SoapRequestClient.java

示例2: processRequest

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
public static Response processRequest(
    String url, String method, String payload, String authHeader) {
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(url);
  Builder builder = target.request();
  builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
  if (authHeader != null) {
    builder.header(HttpHeaders.AUTHORIZATION, authHeader);
  }
  return (payload != null)
      ? builder.build(method, Entity.json(payload)).invoke()
      : builder.build(method).invoke();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:14,代码来源:LoginResourceTest.java

示例3: makeConnection

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
/** Make an HTTP connection to the specified URL and pass in the specified payload. */
private static Response makeConnection(
    String method, String urlString, String payload, String jwt)
    throws IOException, GeneralSecurityException {

  // Setup connection
  System.out.println("Creating connection - Method: " + method + ", URL: " + urlString);

  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(urlString);

  Invocation.Builder invoBuild = target.request(MediaType.APPLICATION_JSON_TYPE);

  if (jwt != null) {
    invoBuild.header("Authorization", jwt);
  }
  if (payload != null) {
    System.out.println("Request Payload: " + payload);
    Entity<String> data = Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE);
    return invoBuild.build(method, data).invoke();
  } else {
    return invoBuild.build(method).invoke();
  }
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:25,代码来源:DemoData.java

示例4: sendRequest

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
/**
 * Helper method to send a simple http request without a payload
 *
 * @param url the url to call
 * @param requestType the http method to invoke
 * @return the response from the server
 */
public Response sendRequest(String url, String requestType) {
  String method = "sendRequest";
  logger.entering(clazz, method);
  logger.fine("  url: " + url);
  logger.fine("  requestType: " + requestType);

  String jwt = null;
  try {
    jwt = new JWTVerifier().createJWT("fred");
  } catch (Throwable t) {
    throw new RuntimeException(t);
  }

  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(url);
  Invocation.Builder invoBuild = target.request();

  invoBuild.header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt);
  Response response = invoBuild.build(requestType).invoke();

  logger.exiting(
      clazz, method, "\n\n- - - - - Exiting " + method + " with: " + response + "\n\n");
  return response;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:32,代码来源:OccasionResourceTest.java

示例5: main

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
public static void main(String[] args)
		throws IOException, URISyntaxException {
	Client client = ClientBuilder.newClient();
	// GET http://api.geonames.org/searchJSON?...
	WebTarget target = client.target("http://api.geonames.org/searchJSON")
			.queryParam("q", "kabupaten garut")
			.queryParam("username", "ceefour");
	Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);
	GeonamesSearchResult searchResult = invocationBuilder.get(GeonamesSearchResult.class);
	LOG.info("Body (GeonamesSearchResult): {}", searchResult);
	for (Geoname child : searchResult.getGeonames()) {
		LOG.info("Place: {} ({}, {})",
				child.getToponymName(), child.getLat(), child.getLng());
	}
}
 
开发者ID:ceefour,项目名称:java-web-services-training,代码行数:16,代码来源:GetGeonamesApplication.java

示例6: getRequestForTestCase

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
private Invocation.Builder getRequestForTestCase(RedirectorTestCase redirectorTestCase, String appName) {
    WebTarget webTarget = new ServiceHelper(endpointUrlForApp(appName)).getWebTarget();
    webTarget = webTarget.queryParam(DataParamName.testInfo.name(), redirectorTestCase.getName());
    webTarget = webTarget.queryParam(Context.SESSION_ID, redirectorTestCase.getName());
    for (Parameter parameter : redirectorTestCase.getParameters()) {
        List<Value> values = parameter.getValues();
        Value value = CollectionUtils.isNotEmpty(values) ? values.get(0) : new Value("");
        webTarget = webTarget.queryParam(parameter.getName(), value);
    }

    return webTarget.request();
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:13,代码来源:HttpTestCasesRunner.java

示例7: restGet

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
/**
 * Returns response of the REST get operation with a given additional path.
 *
 * @param path path or null
 * @return response json string
 */
public String restGet(String path) {
    WebTarget wt = client.target(access.endpoint() + baseUrl).path(path);
    Invocation.Builder builder = wt.request(JSON_UTF_8.toString());
    try {
        Response response = builder.get();
        if (response.getStatus() != HTTP_OK) {
            log.warn("Failed to get resource {}", access.endpoint() + baseUrl + path);
            return EMPTY_JSON_STRING;
        }
    } catch (javax.ws.rs.ProcessingException e) {
        return EMPTY_JSON_STRING;
    }
    return builder.get(String.class);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:XosApi.java

示例8: request

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
private Invocation.Builder request(String path, Map<String, String> queryParams) {
	WebTarget target = httpClient.target(getBaseUri() + BASE_PATH).path(path);
	if (queryParams != null && !queryParams.isEmpty()) {
		Set<String> keys = queryParams.keySet();
		for (String key : keys) {
			target = target.queryParam(key, queryParams.get(key));
		}
	}
	return target.request();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:11,代码来源:JsonApiResponseFilterTestBase.java

示例9: sendRequest

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
public Response sendRequest(String url, String requestType) {
    Client client = ClientBuilder.newClient();
    System.out.println("Testing " + url);
    WebTarget target = client.target(url);
    Invocation.Builder invoBuild = target.request();
    Response response = invoBuild.build(requestType).invoke();
    return response;
}
 
开发者ID:technologyfa,项目名称:fa-Istio-Service-Mesh-on-Kubernetes-1,代码行数:9,代码来源:EndpointTest.java

示例10: processRequest

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
public Response processRequest(String url, String method, String payload, String authHeader) {
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(url);
  Builder builder = target.request();
  builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
  if (authHeader != null) {
    builder.header(HttpHeaders.AUTHORIZATION, authHeader);
  }
  return (payload != null)
      ? builder.build(method, Entity.json(payload)).invoke()
      : builder.build(method).invoke();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:13,代码来源:UserResourceTest.java

示例11: processRequest

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
private Response processRequest(String url, String method, String payload, String authHeader) {
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(url);
  Builder builder = target.request();
  builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
  if (authHeader != null) {
    builder.header(HttpHeaders.AUTHORIZATION, authHeader);
  }
  return (payload != null)
      ? builder.build(method, Entity.json(payload)).invoke()
      : builder.build(method).invoke();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:13,代码来源:JWTVerifier.java

示例12: processRequest

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
public static Response processRequest(
    String url, String method, String payload, String authHeader) {
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(url);
  Builder builder = target.request();
  if (payload != null) {
    builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
  }
  if (authHeader != null) {
    builder.header(HttpHeaders.AUTHORIZATION, authHeader);
  }
  return (payload != null)
      ? builder.build(method, Entity.json(payload)).invoke()
      : builder.build(method).invoke();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:16,代码来源:AuthResourceTest.java

示例13: sendRequestJson

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
/**
 * Helper method for sending requests with a json payload.
 *
 * @param url the url to call
 * @param requestType the http method to invoke
 * @param json the json payload to send
 * @return the response from the server
 */
public Response sendRequestJson(String url, String requestType, String json) {
  String method = "sendRequestJson";
  logger.entering(clazz, method);
  logger.fine("  url: " + url);
  logger.fine("  requestType: " + requestType);
  logger.fine("  json: " + json);

  String jwt = null;
  try {
    jwt = new JWTVerifier().createJWT("fred");
  } catch (Throwable t) {
    throw new RuntimeException(t);
  }

  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(url);
  Invocation.Builder invoBuild = target.request(MediaType.APPLICATION_JSON_TYPE);

  // Allowing for null payload to get a 400 response code
  Entity<String> data;
  if (null == json || json.isEmpty()) {
    data = Entity.entity("", MediaType.APPLICATION_JSON_TYPE);
  } else {
    data = Entity.entity(json, MediaType.APPLICATION_JSON_TYPE);
  }

  invoBuild.header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt);
  Response response = invoBuild.build(requestType, data).invoke();

  logger.exiting(
      clazz,
      method,
      "\n\n- - - - - Exiting " + method + " with: " + response.readEntity(String.class) + "\n\n");
  return response;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:44,代码来源:OccasionResourceTest.java

示例14: processRequest

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
public Response processRequest(String url, String method, String payload)
    throws GeneralSecurityException, IOException {
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(url);
  Builder builder = target.request();
  builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
  builder.header(
      HttpHeaders.AUTHORIZATION,
      "Bearer "
          + new JWTVerifier()
              .createJWT("fred", new HashSet<String>(Arrays.asList("orchestrator"))));
  return (payload != null)
      ? builder.build(method, Entity.json(payload)).invoke()
      : builder.build(method).invoke();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:16,代码来源:NotificationTest.java

示例15: playRound

import javax.ws.rs.client.WebTarget; //导入方法依赖的package包/类
@Override
protected RoundResult playRound(Round round) {
	logger.info("Playing round: " + round.getName());
	
	Iterator<GameTicket> itr = getStatus().getTickets().iterator();
	while (itr.hasNext()) {
		GameTicket player = itr.next();
		logger.debug("Requesting cards from " + player.getPlayerName());
		
		// Ask player for cards
		Client client = ClientBuilder.newClient(new ClientConfig().register( LoggingFeature.class ));
		WebTarget webTarget = client.target(player.getPlayerEndpoint()).path("player/round");
		Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
		Response response = invocationBuilder.put(Entity.entity(round, MediaType.APPLICATION_JSON));
		if (response.getStatus() != 200) {
			logger.warn("Response from " + player.getPlayerName() + " indicates a lack of success.");
			String msg = response.readEntity(String.class);
			logger.warn(response.getStatus() + " - " + msg);
		}
		
		PlayedCards cards = response.readEntity(PlayedCards.class);
		round.addCards(player, cards);
	}
	
	RoundResult results = round.getResults();
	logger.info("Round is complete. Results:\n" + results.toString());
	return results;
}
 
开发者ID:Azure,项目名称:acs-demos,代码行数:29,代码来源:Tournament.java


注:本文中的javax.ws.rs.client.WebTarget.request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。