本文整理汇总了Java中javax.ws.rs.client.Invocation.Builder类的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Builder类属于javax.ws.rs.client.Invocation包,在下文中一共展示了Builder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldProvideActionDefinition
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
@Test
public void shouldProvideActionDefinition() {
@SuppressWarnings({"unchecked", "rawtypes"})
final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class;
final ArgumentCaptor<Entity<Map<String, Object>>> entity = ArgumentCaptor.forClass(entityType);
final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder().putProperty("sObjectName",
Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Account", "Account"),
DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact")))
.build();
when(invocationBuilder.post(entity.capture(), eq(DynamicActionMetadata.class))).thenReturn(suggestions);
final ConnectorDescriptor definition = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE,
Collections.emptyMap());
final ConnectorDescriptor enrichedDefinitioin = new ConnectorDescriptor.Builder()
.createFrom(createOrUpdateSalesforceObjectDescriptor)
.replaceConfigurationProperty("sObjectName",
c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Account", "Account"),
ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact")))
.build();
assertThat(definition).isEqualTo(enrichedDefinitioin);
}
示例2: createWorkFrom
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
/** Publishes the object (its MODS) as a new "work" in the ORCID profile */
MCRWork createWorkFrom(MCRObjectID objectID)
throws IOException, JDOMException, SAXException {
WebTarget target = orcid.getWebTarget().path("work");
Builder builder = buildInvocation(target);
Document workXML = buildWorkXMLFrom(objectID);
Entity<InputStream> input = buildRequestEntity(workXML);
LOGGER.info("post (create){} at {}", objectID, target.getUri());
Response response = builder.post(input);
expect(response, Response.Status.CREATED);
String putCode = getPutCode(response);
MCRWork work = new MCRWork(orcid, putCode);
work.fetchDetails();
return work;
}
示例3: getConcept
import javax.ws.rs.client.Invocation.Builder; //导入依赖的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()));
}
}
示例4: getConceptByIdentifier
import javax.ws.rs.client.Invocation.Builder; //导入依赖的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()));
}
}
示例5: populateRelatedConceptUris
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
public void populateRelatedConceptUris(String relationshipUri, Concept concept) throws OEClientException {
logger.info("populateNarrowerConceptURIs entry: {}", concept.getUri());
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", getWrappedUri(relationshipUri));
Invocation.Builder invocationBuilder = getInvocationBuilder(getResourceURL(concept.getUri()), queryParameters);
Date startDate = new Date();
logger.info("populateNarrowerConceptURIs making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("populateNarrowerConceptURIs call complete: {}", startDate.getTime());
logger.info("populateNarrowerConceptURIs - 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.populateRelatedConceptUris(relationshipUri, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例6: populateMetadata
import javax.ws.rs.client.Invocation.Builder; //导入依赖的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()));
}
}
示例7: processRequest
import javax.ws.rs.client.Invocation.Builder; //导入依赖的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();
}
示例8: request
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
private <R> R request(String path, Function<Builder, Response> method,
Class<R> responseType, int status) throws ServiceException {
Builder builder = target.path(path) //
.request() //
.accept(mediaType);
Response response = null;
try {
response = method.apply(builder);
if (response.getStatus() != status) {
throw new ConnectionException(Messages.ERROR_BAD_RESPONSE,
response.readEntity(String.class));
}
return response.readEntity(responseType);
} catch (ProcessingException e) {
throw new ConnectionException(Messages.ERROR_CONNECTION_FAILURE, e);
} finally {
if (response != null) {
response.close();
}
}
}
示例9: shouldProvideActionDefinition
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
@Test
public void shouldProvideActionDefinition() {
@SuppressWarnings({"unchecked", "rawtypes"})
final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class;
final ArgumentCaptor<Entity<Map<String, Object>>> entity = ArgumentCaptor.forClass(entityType);
final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder().putProperty("sObjectName",
Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Account", "Account"),
DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact")))
.build();
when(invocationBuilder.post(entity.capture(), eq(DynamicActionMetadata.class))).thenReturn(suggestions);
final ActionDefinition definition = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE,
Collections.emptyMap());
final ActionDefinition enrichedDefinitioin = new ActionDefinition.Builder()
.createFrom(createOrUpdateSalesforceObjectDefinition)
.replaceConfigurationProperty("sObjectName",
c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Account", "Account"),
ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact")))
.build();
assertThat(definition).isEqualTo(enrichedDefinitioin);
}
示例10: getResponse
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
private String getResponse(String rel) {
CallContext callContext = resolve(rel);
if (callContext == null) {
return null;
}
Builder b = callContext.target.request(callContext.getMediaType());
javax.ws.rs.core.Response response;
if (requestObject != null && bodyIsAllowed(callContext.method)) {
response = b.method(callContext.method, Entity.entity(requestObject, callContext.getMediaType()));
} else {
response = b.method(callContext.method);
}
if (response.getStatus() >= 300) {
throw new WebApplicationException(response);
}
String responseString = response.readEntity(String.class);
return responseString;
}
示例11: obtainAgenteSrv
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
/**
* This method makes a GET request to the Agente Rest API. Obtain and
* AgentDto.java object. If the call is successfully the object status is
* OK, otherwise it will contain the HTTP error code obtained.
*
* @param pTarget
* Targe URL.
* (http://xxx.xxx.xxx.xxx:xxxx/t-factory-agent/api)
* @return AgentDto object.
*/
public AgentDto obtainAgenteSrv(String pTarget){
AgentDto objAgentDto;
try {
WebTarget myTarget = client.target(pTarget+"/agent/");
Invocation.Builder invocationBuilder = myTarget.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.get();
if( response.getStatus() == 200){
objAgentDto = response.readEntity(AgentDto.class);
}else{
objAgentDto = new AgentDto();
objAgentDto.setStatus( String.valueOf( response.getStatus()));
}
} catch (Exception e) {
System.out.println("Error trying consume the service: "+pTarget);
//e.printStackTrace();
objAgentDto = new AgentDto();
objAgentDto.setStatus("Invalid URL.");
}
return objAgentDto;
}
示例12: updateStatusReturn
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
@Override
public StatusResult updateStatusReturn(WebTarget webClient, final T object,
final String idName, final Long id,
final Map<String, Object> pathParams, final Map<String, Object> queryParams, final Map<String, Object> builderProperties)
throws Exception {
if (queryParams != null)
webClient = applyQuery(webClient, queryParams);
if (id != null && idName != null)
webClient = webClient.resolveTemplate(idName, id);
if (pathParams != null)
webClient = webClient.resolveTemplates(pathParams);
Builder builder = acceptMediaType(webClient.request());
if (builderProperties != null){
addBuilderProperties(builder, builderProperties);
}
Response resp = builder.put(Entity.entity(object, acceptMediaType()));
return getStatusResult(resp);
}
示例13: getDruidTables
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Set<String> getDruidTables(WebTarget webTarget) {
WebTarget dataSourceRs = webTarget.path(DATASOURCE);
Builder builder = dataSourceRs.request(MediaType.APPLICATION_JSON_TYPE);
builder.accept(MediaType.APPLICATION_JSON);
Response response = builder.get();
int statusCode = response.getStatus();
Set<String> result = null;
if (statusCode == Status.OK.getStatusCode()) {
result = response.readEntity(Set.class);
} else {
String errorMsg = "Druid HTTP Status Code - " + statusCode + "; Response - " + response.readEntity(String.class) + "; GET - " + webTarget.getUri();
logger.warn (errorMsg);
throw new DataSourceException(errorMsg);
}
return result;
}
示例14: post
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
/**
* Generic POST call.
*/
public <T> T post(final String path, final String bodyContent,
final String contentType, final Class<T> type,
final RestParameter... parameters) throws ImClientException {
try {
// Avoid sending null as body content
String normalizedBodyContent = normalizeBodyContent(bodyContent);
logCallInfo(HttpMethods.POST, path);
logCallContent(HttpMethods.POST, normalizedBodyContent);
Entity<String> content =
Entity.entity(normalizedBodyContent, contentType);
Builder clientConfigured = configureClient(path, parameters);
return clientConfigured.post(content, type);
} catch (WebApplicationException exception) {
throw new ImClientErrorException(createReponseError(exception));
}
}
示例15: prepareGETInvocationBuilder
import javax.ws.rs.client.Invocation.Builder; //导入依赖的package包/类
/**
* @param baseUri
*
* @return
*
* @throws UnsupportedEncodingException
* @throws UriBuilderException
* @throws IllegalArgumentException
*/
private Invocation prepareGETInvocationBuilder(final String mimeType, final String query)
throws IllegalArgumentException, UriBuilderException, UnsupportedEncodingException {
final UriBuilder baseBuilder = UriBuilder.fromUri(HOST).port(PORT);
final URI targetUri = baseBuilder.path(QueryExecutor.ENDPOINT_NAME)
.queryParam(QUERY_PARAM, URLEncoder.encode(query, "UTF-8").replace("+", "%20")).build();
final Client client = ClientBuilder.newClient();
final WebTarget resourceTarget = client.target(targetUri);
final Builder invocationBuilder = resourceTarget.request(mimeType);
final Invocation invocation = invocationBuilder.buildGet();
return invocation;
}