本文整理汇总了Java中javax.ws.rs.client.Invocation类的典型用法代码示例。如果您正苦于以下问题:Java Invocation类的具体用法?Java Invocation怎么用?Java Invocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Invocation类属于javax.ws.rs.client包,在下文中一共展示了Invocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClientBuilder
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
/**
* Gets a client web resource builder.
*
* @param localUrl the URL to access remote resource
* @return web resource builder
*/
public Invocation.Builder getClientBuilder(String localUrl) {
log.info("URL: {}", localUrl);
Client client = ClientBuilder.newClient();
WebTarget wt = client.target(localUrl);
return wt.request(UTF_8);
}
示例2: 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
示例3: evaluate
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
public Evaluation evaluate(String agentId, boolean meta, Map<String, Integer> inputMap) {
String url = String.format("%1$s/agent/%2$s", root, agentId);
WebTarget webTarget = client.target(url);
Invocation.Builder builder = webTarget
.request(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", String.format("Bearer %s", key))
.header("User-Agent", "fuzzy.ai-java/" + version);
if (meta) {
builder.header("meta", "true");
}
Response response = builder.post(Entity.json(inputMap));
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String evaluationId = response.getHeaderString("X-Evaluation-ID");
@SuppressWarnings("unchecked")
Map<String, Double> map = response.readEntity(Map.class);
return new Evaluation(evaluationId, map);
}
示例4: getExcelTestQueryInvocation
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
private Invocation getExcelTestQueryInvocation(String filePath, String sheet, boolean extractHeader,
boolean hasMergedCells) throws Exception {
ExcelFileConfig fileConfig = new ExcelFileConfig();
fileConfig.setSheetName(sheet);
if (extractHeader) {
fileConfig.setExtractHeader(true);
} // false is the default value
if (hasMergedCells) {
fileConfig.setHasMergedCells(true);
} // false is the default value
return getBuilder(getAPIv2().path("/source/dacfs_test/file_preview" + filePath))
.buildPost(Entity.json(fileConfig));
}
示例5: getPorts
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
/**
* Returns port information stored in Neutron.
*
* @return List of OpenstackPort
*/
public Collection<OpenstackPort> getPorts() {
Invocation.Builder builder = getClientBuilder(neutronUrl + URI_PORTS);
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackPort> openstackPorts = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode portList = (ArrayNode) node.path(PATH_PORTS);
OpenstackPortCodec portCodec = new OpenstackPortCodec();
portList.forEach(p -> openstackPorts.add(portCodec.decode((ObjectNode) p, null)));
} catch (IOException e) {
log.warn("getPorts()", e);
}
log.debug("port response:" + response);
openstackPorts.forEach(n -> log.debug("port ID: {}", n.id()));
return openstackPorts;
}
示例6: getRouters
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
public Collection<OpenstackRouter> getRouters() {
Invocation.Builder builder = getClientBuilder(neutronUrl + PATH_ROUTERS);
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackRouter> openstackRouters = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode routerList = (ArrayNode) node.path(PATH_ROUTERS);
OpenstackRouterCodec openstackRouterCodec = new OpenstackRouterCodec();
routerList.forEach(r -> openstackRouters
.add(openstackRouterCodec.decode((ObjectNode) r, null)));
} catch (IOException e) {
log.warn("getRouters()", e);
}
log.debug("router response:" + response);
openstackRouters.forEach(r -> log.debug("router ID: {}", r.id()));
return openstackRouters;
}
示例7: getNetworks
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
/**
* Returns network information stored in Neutron.
*
* @return List of OpenstackNetwork
*/
public Collection<OpenstackNetwork> getNetworks() {
Invocation.Builder builder = getClientBuilder(neutronUrl + URI_NETWORKS);
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
log.debug("networks response:" + response);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackNetwork> openstackNetworks = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode networkList = (ArrayNode) node.path(PATH_NETWORKS);
OpenstackNetworkCodec networkCodec = new OpenstackNetworkCodec();
networkList.forEach(n -> openstackNetworks.add(networkCodec.decode((ObjectNode) n, null)));
} catch (IOException e) {
log.warn("getNetworks()", e);
}
openstackNetworks.removeAll(Collections.singleton(null));
openstackNetworks.forEach(n -> log.debug("network ID: {}", n.id()));
return openstackNetworks;
}
示例8: getConcept
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
/**
* Return the concept with the supplied URI with pref label, uri and type fields populated
* @param conceptUri - the concept to be returned
* @return - the requested concept
* @throws OEClientException - an error has occurred contacting the server
*/
public Concept getConcept(String conceptUri) throws OEClientException {
logger.info("getConcept entry: {}", conceptUri);
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", basicProperties);
queryParameters.put("path", getPathParameter(conceptUri));
Invocation.Builder invocationBuilder = getInvocationBuilder(getApiURL(), queryParameters);
Date startDate = new Date();
logger.info("getConcept making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getConcept call complete: {}", startDate.getTime());
logger.info("getConceptDetails - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isDebugEnabled()) logger.debug("getConceptDetails: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
return new Concept(this, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例9: getConceptByIdentifier
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
/**
* Return the concept with the supplied identifier
* @param identifier - the unique identifier for the concept (not the URI)
* @return - the requested concept
* @throws OEClientException - an error has occurred contacting the server
*/
public Concept getConceptByIdentifier(Identifier identifier) throws OEClientException {
logger.info("getConceptByIdentifier entry: {}", identifier);
String url = getModelURL() + "/skos:Concept/meta:transitiveInstance";
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", basicProperties);
queryParameters.put("filters", String.format("subject(exists %s \"%s\")", getWrappedUri(identifier.getUri()), identifier.getValue()));
Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);
Date startDate = new Date();
logger.info("getConceptByIdentifier making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getConceptByIdentifier call complete: {}", startDate.getTime());
logger.info("getConceptByIdentifier - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isDebugEnabled()) logger.debug("getConceptByIdentifier: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
return new Concept(this, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例10: populateMetadata
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
public void populateMetadata(String metadataUri, Concept concept) throws OEClientException {
logger.info("populateMetadata entry: {}", concept.getUri());
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", getWrappedUri(metadataUri));
Invocation.Builder invocationBuilder = getInvocationBuilder(getResourceURL(concept.getUri()), queryParameters);
Date startDate = new Date();
logger.info("populateMetadata making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("populateMetadata call complete: {}", startDate.getTime());
logger.info("populateMetadata - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isDebugEnabled()) logger.debug("populateNarrowerConceptURIs: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
concept.populateMetadata(metadataUri, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例11: deleteModel
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
/**
* Delete model
* @param model - the model to be deleted
* @throws OEClientException - an error has occurred contacting the server
*/
public void deleteModel(Model model) throws OEClientException {
logger.info("deleteModel entry: {}", model.getLabel());
String url = getApiURL() + "/sys/" + model.getUri();
logger.info("deleteModel URL: {}", url);
Invocation.Builder invocationBuilder = getInvocationBuilder(url);
logger.info("deleteModel - about to call");
Response response = invocationBuilder.delete();
logger.info("deleteModel - call returned");
int status = response.getStatus();
logger.info("deleteModel response status: {}", status);
if (status != 200) {
throw new OEClientException("Status: %d return deleting model at URL: %s. \n%s", status, url, response.readEntity(String.class));
}
}
示例12: commitTask
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
public void commitTask(Task task) {
logger.info("commitTask entry: {}", task);
String url = getTaskSysURL(task) + "/teamwork:Change/rdf:instance";
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("action", "commit");
queryParameters.put("filter", "subject(teamwork:status = teamwork:Uncommitted)");
Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);
Date startDate = new Date();
logger.info("commitTask making call : {}", startDate.getTime());
Response response = invocationBuilder.post(null);
logger.info("commitTask call complete: {}", startDate.getTime());
/*
* Possible response codes are: - 204 in case of success - 409 in case
* of constraint violation (if e. g. concept scheme already exists)
*/
logger.info("commitTask status: {}", response.getStatus());
if (logger.isDebugEnabled()) {
logger.debug("commitTask response: {}", response.readEntity(String.class));
}
}
示例13: getSecurityGroup
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
/**
* Extracts OpenstackSecurityGroup information for the ID.
*
* @param id Security Group ID
* @return OpenstackSecurityGroup object or null if fails
*/
public OpenstackSecurityGroup getSecurityGroup(String id) {
Invocation.Builder builder = getClientBuilder(neutronUrl + URI_SECURITY_GROUPS + "/" + id);
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
ObjectMapper mapper = new ObjectMapper();
OpenstackSecurityGroup securityGroup = null;
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
OpenstackSecurityGroupCodec sgCodec = new OpenstackSecurityGroupCodec();
securityGroup = sgCodec.decode(node, null);
} catch (IOException e) {
log.warn("getSecurityGroup()", e);
}
return securityGroup;
}
示例14: deleteConcept
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
public void deleteConcept(Concept concept) throws OEClientException {
logger.info("deleteConcept entry: {} {} {}", concept.getUri());
String url = getResourceURL(concept.getUri());
logger.info("deleteConcept - URL: {}", url);
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("mode", "empty");
Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);
Response response = invocationBuilder.delete();
if (response.getStatus() == 204) {
return;
}
logger.warn(response.readEntity(String.class));
throw new OEClientException(
String.format("%s Response received\n%s", response.getStatus(), response.getEntity().toString()));
}
示例15: testCanGETJobSummaries
import javax.ws.rs.client.Invocation; //导入依赖的package包/类
@Test
public void testCanGETJobSummaries() throws IOException {
final Invocation.Builder builder =
generateAuthenticatedRequest(RULE, HTTP_JOBS_PATH);
for (int i = 0; i < 10; i++) {
builder.post(json(REQUEST_AGAINST_SECOND_SPEC), APIJobCreatedResponse.class);
}
final Response jobSummariesResponse =
generateAuthenticatedRequest(RULE, HTTP_JOBS_PATH).get();
assertThat(jobSummariesResponse.getStatus()).isEqualTo(OK);
final APIJobDetailsCollection jobSummaries =
readJSON(jobSummariesResponse.readEntity(String.class), APIJobDetailsCollection.class);
assertThat(jobSummaries.getEntries().isEmpty()).isFalse();
}