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


Java Invocation.invoke方法代码示例

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


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

示例1: testAbort

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testAbort() throws Exception {
	logger.info("Registering Client Abort Filters");
	Client client = newClient();
	client.register(new MyClientResponseFilter());
	client.register(new MyClientRequestFilter());
	client.register(new BlockChainFilter());
	WebTarget target = client.target(url + "myjaxrs/simple/");

	WebTarget resourceTarget = target.path("/valuesget");
	resourceTarget = resourceTarget.queryParam("OrderID", "111").queryParam("UserName", "Luke");

	logger.info("Invoking REST Service: " + resourceTarget.getUri().toString());
	Invocation invocation = resourceTarget.request().buildGet();
	Response response = invocation.invoke();

	assertEquals(
			"MyClientRequestFilter is not executed because BlockChainFilter blocks it. So no header is saved: ", "",
			response.getHeaderString(CONTENT_TYPE_STRING));
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:22,代码来源:ComponentTestCase.java

示例2: testGet

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testGet() throws Exception {
	logger.info("Registering Client Level Filters");
	Client client = newClient();
	client.register(new OtherClientResponseFilter());
	WebTarget target = client.target(url + "myjaxrs/simple/");
	target.register(new OtherClientRequestFilter());

	WebTarget resourceTarget = target.path("/valuesget");
	resourceTarget = resourceTarget.queryParam("OrderID", "111").queryParam("UserName", "Luke");
	resourceTarget.register(new MyClientResponseFilter());
	resourceTarget.register(new MyClientRequestFilter());

	logger.info("Invoking REST Service: " + resourceTarget.getUri().toString());
	Invocation invocation = resourceTarget.request().buildGet();
	Response response = invocation.invoke();
	String respContent = "";

	if (response.hasEntity())
		respContent = response.readEntity(String.class);

	assertEquals("Response--> ", "111-Luke", respContent);
	assertEquals("Content Type after changing in ClientResponseFilter: ", TEXT_HTML,
			response.getHeaderString(CONTENT_TYPE_STRING));
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:27,代码来源:ComponentTestCase.java

示例3: expect

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
protected Response expect(ResponseExpectation expectation, Invocation i) {
  try (Timer.TimedBlock b = Timer.time("request")) {
    Response response = i.invoke();
    response.bufferEntity();
    try {
      expectation.validate(response);
    } catch (AssertionError e) {
      // this will show the body of the response in the error message
      // if an error occurred it will show the server side error.
      // response.toString() does not show the content
      String body = response.readEntity(String.class);
      throw new AssertionError(String.format("%s\n%s\n%s", e.getMessage(), response.toString(), body), e);
    }
    return response;
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:BaseClientUtils.java

示例4: createRelationship

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void createRelationship(String relationshipTypeUri, Concept sourceConcept, Concept targetConcept)
		throws OEClientException {
	logger.info("createRelationship entry: {} {} {}", relationshipTypeUri, sourceConcept.getUri(),
			targetConcept.getUri());

	String url = getResourceURL(sourceConcept.getUri());
	logger.info("createRelationship - URL: {}", url);
	Invocation.Builder invocationBuilder = getInvocationBuilder(url);

	JSONArray operationList = new JSONArray();
	JSONObject addOperation = new JSONObject();
	addOperation.put("op", "add");
	addOperation.put("path", String.format("@graph/0/%s/-", getTildered(relationshipTypeUri)));
	JSONArray targetArray = new JSONArray();
	JSONObject targetObject = new JSONObject();
	targetObject.put("@id", targetConcept.getUri());
	targetArray.add(targetObject);
	addOperation.put("value", targetArray);

	operationList.add(addOperation);

	String createRelationshipPayload = operationList.toJSONString().replaceAll("\\/", "/");
	logger.info("createRelationship payload: {}", createRelationshipPayload);
	Invocation invocation = invocationBuilder.build("PATCH",
			Entity.entity(createRelationshipPayload, "application/json-patch+json"));
	Response response = invocation.invoke();

	if (response.getStatus() == 200) {
		return;
	}

	throw new OEClientException(
			String.format("%s Response received\n%s", response.getStatus(), response.getEntity().toString()));
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:36,代码来源:OEClientReadWrite.java

示例5: createMetadata

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void createMetadata(Concept concept, String metadataType, String metadataValue, String metadataLanguage)
		throws OEClientException {
	logger.info("createMetadata entry: {} {} {} {}", concept.getUri(), metadataType, metadataValue,
			metadataLanguage);

	String url = getResourceURL(concept.getUri());
	logger.info("createMetadata - URL: {}", url);
	Invocation.Builder invocationBuilder = getInvocationBuilder(url);

	JSONArray operationList = new JSONArray();
	JSONObject addOperation = new JSONObject();
	addOperation.put("op", "add");
	addOperation.put("path", String.format("@graph/0/%s/-", getTildered(metadataType)));

	if ((metadataLanguage == null) || (metadataLanguage.trim().length() == 0)) {
		addOperation.put("value", metadataValue);
	} else {
		JSONObject valueObject = new JSONObject();
		valueObject.put("@value", metadataValue);
		valueObject.put("@language", metadataLanguage);
		addOperation.put("value", valueObject);
	}
	operationList.add(addOperation);

	String createMetadataPayload = operationList.toJSONString().replaceAll("\\/", "/");
	logger.info("createMetadata payload: {}", createMetadataPayload);
	Invocation invocation = invocationBuilder.build("PATCH",
			Entity.entity(createMetadataPayload, "application/json-patch+json"));
	Response response = invocation.invoke();

	if (response.getStatus() == 200) {
		return;
	}

	throw new OEClientException(
			String.format("%s Response received\n%s", response.getStatus(), response.getEntity().toString()));
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:39,代码来源:OEClientReadWrite.java

示例6: deleteRelationship

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void deleteRelationship(String relationshipTypeUri, Concept concept1, Concept concept2)
		throws OEClientException {
	logger.info("deleteRelationship entry: {} {} {}", relationshipTypeUri, concept1.getUri(), concept2.getUri());

	String url = getResourceURL(concept1.getUri());
	logger.info("deleteRelationship - URL: {}", url);
	Invocation.Builder invocationBuilder = getInvocationBuilder(url);

	JSONArray operationList = new JSONArray();

	JSONObject testOperation = new JSONObject();
	testOperation.put("op", "test");
	testOperation.put("path", String.format("@graph/0/%s/0", getTildered(relationshipTypeUri)));
	JSONObject valueObject1 = new JSONObject();
	valueObject1.put("@id", concept2.getUri());
	testOperation.put("value", valueObject1);
	operationList.add(testOperation);

	JSONObject removeOperation = new JSONObject();
	removeOperation.put("op", "remove");
	removeOperation.put("path", String.format("@graph/0/%s/0", getTildered(relationshipTypeUri)));
	operationList.add(removeOperation);

	String deleteRelationshipPayload = operationList.toJSONString().replaceAll("\\/", "/");
	logger.info("deleteRelationship payload: {}", deleteRelationshipPayload);
	Invocation invocation = invocationBuilder.build("PATCH",
			Entity.entity(deleteRelationshipPayload, "application/json-patch+json"));
	Response response = invocation.invoke();

	if (response.getStatus() == 200) {
		return;
	}

	logger.warn(response.readEntity(String.class));
	throw new OEClientException(
			String.format("%s Response received\n%s", response.getStatus(), response.getEntity().toString()));
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:39,代码来源:OEClientReadWrite.java

示例7: getTextResponse

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
/**
 * Send a GET request and get the plain text in the response
 * 
 * @param webResource
 *            a web resource
 * @return the text from the response
 * @throws BillingException
 *             if the GET request fails
 */
public String getTextResponse(WebTarget webResource)
        throws BillingException {

    Invocation invocation = webResource
            .request(MediaType.TEXT_PLAIN_TYPE).buildGet();
    try {
        return invocation.invoke(String.class);
    } catch (RuntimeException e) {
        throw new BillingException(
                "Error when processing response from File Billing Application",
                e);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:RestDAO.java

示例8: getFileResponse

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
/**
 * Send a GET request and get the file content, which is contained in the
 * response as octet stream
 * 
 * @param webResource
 *            a web resource
 * @return the file content
 * @throws BillingException
 *             if the GET request fails
 */
public byte[] getFileResponse(WebTarget webResource)
        throws BillingException {

    Invocation invocation = webResource
        .request(MediaType.APPLICATION_OCTET_STREAM).buildGet();

    try {
        InputStream is = invocation.invoke(InputStream.class);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        int next = is.read();
        while (next > -1) {
            bos.write(next);
            next = is.read();
        }
        bos.flush();

        byte[] result = bos.toByteArray();
        if (result.length > 0) {
            return result;
        } else {
            return null;
        }
    } catch (Exception e) {
        throw new BillingException(
                "Error when processing file response from File Billing Application",
                e);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:40,代码来源:RestDAO.java

示例9: send

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
/**
 * Send this request to the given base URI.
 * <p>
 * The path should contain no components besides user-info, host, and port.
 * <p>
 * This method is thread-safe.
 */
// TODO: The uri should be validated to not conflict with the uriTemplate
// If the uriTemplate contains a path, and the given URI has a path (even
// just a single trailing slash, the template's path will be replaced).
public Response send(URI uri)
{
    Invocation invocation = createInvocation(uri);
    return invocation.invoke();
}
 
开发者ID:prestodb,项目名称:presto-manager,代码行数:16,代码来源:ApiRequester.java

示例10: readEntity

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
private static <T> T readEntity(Class<T> entityClazz, Invocation invocation) throws IOException {
  Response response = invocation.invoke();
  try {
    response.bufferEntity();
    if (response.getStatus() != Response.Status.OK.getStatusCode()) {
      if (response.hasEntity()) {
        // Try to parse error message as generic error message JSON type
        try {
          GenericErrorMessage message = response.readEntity(GenericErrorMessage.class);
          throw new IOException(format("Status %d (%s): %s (more info: %s)",
              response.getStatus(),
              response.getStatusInfo().getReasonPhrase(),
              message.getErrorMessage(),
              message.getMoreInfo()));
        } catch (ProcessingException e) {
          // Fallback to String if unparsing is unsuccessful
          throw new IOException(format("Status %d (%s)",
              response.getStatus(),
              response.getStatusInfo().getReasonPhrase(),
              response.readEntity(String.class)));
        }
      }
      throw new IOException(format("Status %d (%s)",
          response.getStatus(),
          response.getStatusInfo().getReasonPhrase()));
    }
    return response.readEntity(entityClazz);
  } finally {
    response.close();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:32,代码来源:Backup.java

示例11: execute

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
public <T> T execute(ElasticAction2<T> action){
  final ContextListenerImpl listener = new ContextListenerImpl();
  final Invocation invocation = action.buildRequest(target, listener);
  try {
    return invocation.invoke(action.getResponseClass());
  } catch (Exception e){
    throw handleException(e, action, listener);
  }

}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:11,代码来源:ElasticConnectionPool.java

示例12: addListener

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
/**
 * addListener - create a task within the current model
 * @param listenerUri - the identifier (within the model) for the listener being added
 * @param listenerUrl - where the listener is to be found 
 */
public void addListener(String listenerUri, String listenerUrl) {
	logger.info("addListener entry: {} {}", listenerUri, listenerUrl);

	String url = getModelSysURL();
	logger.info("addListener URL: {}", url);
	Invocation.Builder invocationBuilder = getInvocationBuilder(url);
	
	JsonArray requestArray = new JsonArray();
	
	JsonObject requestObject = new JsonObject();
	requestObject.put("op", "add");
	requestObject.put("path", "@graph/0/semlisteners:hasListener/-");

	JsonObject valueObject = new JsonObject();
	valueObject.put("@id", listenerUri);
	valueObject.put("@type", "semlisteners:Listener");
	
	JsonArray listenerURLArray = new JsonArray();
	listenerURLArray.add(listenerUrl);
	valueObject.put("semlisteners:listenerUrl", listenerURLArray);
	
	requestObject.put("value",  valueObject);
	requestArray.add(requestObject);
	
	String payload = requestArray.toString();

	Invocation invocation = invocationBuilder.build("PATCH",
			Entity.entity(payload, "application/json-patch+json"));
	
	Date startDate = new Date();
	logger.info("addListener making call  : {} {}", payload, startDate.getTime());
	Response response = invocation.invoke();
	logger.info("addListener call complete: {}", startDate.getTime());

	/*
	 * Possible response codes are: - 201 in case of success - 409 in case
	 * of constraint violation (if e. g. concept scheme already exists)
	 */
	logger.info("addListener status: {}", response.getStatus());
	if (logger.isDebugEnabled()) {
		logger.debug("addListener response: {}", response.readEntity(String.class));
	}
	
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:50,代码来源:OEClientReadWrite.java

示例13: updateLabel

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
/**
 * Update a label object
 *
 * @param label
 *            - the label to be updated. The URI, language and value of this
 *            label must be defined. The value and language code must match
 *            the values in the Ontology.
 * @param newLabelLanguage
 *            - the new language for the label
 * @param newLabelValue
 *            - the new value for the label
 * @throws OEClientException - an error has occurred contacting the server
 */
@SuppressWarnings({ "unchecked" })
public void updateLabel(Label label, String newLabelLanguage, String newLabelValue) throws OEClientException {
	logger.info("updateLabel entry: {}", label.getUri());

	if (label.getUri() == null) {
		throw new OEClientException("Attemping to update label with null URI");
	}
	String processedLabelUri = FmtUtils.stringForURI(label.getUri());
	String escapedLabelUri = getEscapedUri(processedLabelUri);

	String url = String.format("%s/%s", getModelURL(), escapedLabelUri);
	logger.info("updateLabel - URL: {}", url);
	Invocation.Builder invocationBuilder = getInvocationBuilder(url);
	JSONArray operationList = new JSONArray();
	JSONObject testOperation = new JSONObject();
	JSONObject replaceOperation = new JSONObject();

	testOperation.put("op", "test");
	testOperation.put("path", "@graph/0/skosxl:literalForm/0");
	JSONObject oldLabelObject = new JSONObject();
	oldLabelObject.put("@value", label.getValue());
	oldLabelObject.put("@language", label.getLanguageCode());
	testOperation.put("value", oldLabelObject);

	replaceOperation.put("op", "replace");
	replaceOperation.put("path", "@graph/0/skosxl:literalForm/0");
	JSONObject newLabelObject = new JSONObject();
	newLabelObject.put("@value", newLabelValue);
	newLabelObject.put("@language", newLabelLanguage);
	replaceOperation.put("value", newLabelObject);

	operationList.add(testOperation);
	operationList.add(replaceOperation);

	String conceptSchemePayload = operationList.toJSONString();

	Invocation invocation = invocationBuilder.build("PATCH",
			Entity.entity(conceptSchemePayload, "application/json-patch+json"));
	Response response = invocation.invoke();

	if (response.getStatus() == 200) {
		label.setValue(newLabelValue);
		label.setLanguage(newLabelLanguage);
		return;
	}

	throw new OEClientException(
			String.format("%s Response recieved\n%s", response.getStatus(), response.getEntity().toString()));
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:63,代码来源:OEClientReadWrite.java

示例14: createLabel

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void createLabel(Concept concept, String relationshipTypeUri, Label label) throws OEClientException {
	logger.info("createLabel entry: {} {} {}", concept.getUri(), relationshipTypeUri, label);

	String url = getResourceURL(concept.getUri());
	logger.info("createRelationship - URL: {}", url);
	Invocation.Builder invocationBuilder = getInvocationBuilder(url);

	JSONArray operationList = new JSONArray();
	JSONObject addOperation = new JSONObject();
	addOperation.put("op", "add");
	addOperation.put("path", String.format("@graph/0/%s/-", getTildered(relationshipTypeUri)));

	JSONObject labelObject = new JSONObject();
	if ((label.getUri() != null) && (label.getUri().trim().length() > 0))
		labelObject.put("@id", label.getUri());
	else
		labelObject.put("@id", concept.getUri() + "_" + (new Date()).getTime());

	JSONArray typeArray = new JSONArray();
	typeArray.add("skosxl:Label");
	labelObject.put("@type", typeArray);

	JSONObject literalFormObject = new JSONObject();
	literalFormObject.put("@value", label.getValue());
	literalFormObject.put("@language", label.getLanguageCode());
	JSONArray literalFormArray = new JSONArray();
	literalFormArray.add(literalFormObject);
	labelObject.put("skosxl:literalForm", literalFormArray);

	JSONArray valueArray = new JSONArray();
	valueArray.add(labelObject);
	addOperation.put("value", valueArray);

	operationList.add(addOperation);

	String createLabelPayload = operationList.toJSONString().replaceAll("\\/", "/");
	logger.info("createLabel payload: {}", createLabelPayload);
	Invocation invocation = invocationBuilder.build("PATCH",
			Entity.entity(createLabelPayload, "application/json-patch+json"));
	Response response = invocation.invoke();

	if (response.getStatus() == 200) {
		return;
	}

	throw new OEClientException(
			String.format("%s Response received\n%s", response.getStatus(), response.getEntity().toString()));

}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:51,代码来源:OEClientReadWrite.java

示例15: deleteMetadata

import javax.ws.rs.client.Invocation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void deleteMetadata(String metadataTypeUri, Concept concept, String value, String languageCode)
		throws OEClientException {
	logger.info("deleteMetadata entry: {} {} {} {}", metadataTypeUri, concept.getUri(), value, languageCode);

	String url = getResourceURL(concept.getUri());
	logger.info("deleteMetadata - URL: {}", url);
	Invocation.Builder invocationBuilder = getInvocationBuilder(url);

	JSONArray operationList = new JSONArray();

	JSONObject testOperation1 = new JSONObject();
	testOperation1.put("op", "test");
	testOperation1.put("path", "@graph/1");
	JSONObject valueObject1 = new JSONObject();
	valueObject1.put("@id", concept.getUri());
	testOperation1.put("value", valueObject1);
	operationList.add(testOperation1);
	
	JSONObject testOperation2 = new JSONObject();
	testOperation2.put("op", "test");
	testOperation2.put("path", String.format("@graph/1/%s/0", getTildered(metadataTypeUri)));
	JSONObject valueObject2 = new JSONObject();
	valueObject2.put("@value", value);
	valueObject2.put("@language", languageCode);
	testOperation2.put("value", valueObject2);
	operationList.add(testOperation2);
			
	JSONObject removeOperation = new JSONObject();
	removeOperation.put("op", "remove");
	removeOperation.put("path", String.format("@graph/0/%s/0", getTildered(metadataTypeUri)));
	operationList.add(removeOperation);

	String deleteMetadataPayload = operationList.toJSONString().replaceAll("\\/", "/");
	logger.info("deleteMetadata payload: {}", deleteMetadataPayload);
	Invocation invocation = invocationBuilder.build("PATCH",
			Entity.entity(deleteMetadataPayload, "application/json-patch+json"));
	Response response = invocation.invoke();

	if (response.getStatus() == 200) {
		return;
	}

	logger.warn(response.readEntity(String.class));
	throw new OEClientException(
			String.format("%s Response received\n%s", response.getStatus(), response.getEntity().toString()));
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:48,代码来源:OEClientReadWrite.java


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