本文整理汇总了Java中javax.ws.rs.ProcessingException类的典型用法代码示例。如果您正苦于以下问题:Java ProcessingException类的具体用法?Java ProcessingException怎么用?Java ProcessingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProcessingException类属于javax.ws.rs包,在下文中一共展示了ProcessingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
@Override
public void writeTo(CharmAttachmentPost attachment, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext context = JAXBContext.newInstance(CharmAttachmentPost.class);
Marshaller taskMarshaller = context.createMarshaller();
taskMarshaller.marshal(attachment, entityStream);
} catch (JAXBException e) {
throw new ProcessingException("Error serializing Attachment to output stream");
}
}
示例2: testTimer_ConnectionError
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
@Test
public void testTimer_ConnectionError() {
Client client = app.getInstance(HttpClientFactory.class).newClient();
MetricRegistry metrics = app.getInstance(MetricRegistry.class);
Collection<Timer> timers = metrics.getTimers().values();
assertEquals(1, timers.size());
Timer timer = timers.iterator().next();
assertEquals(0, timer.getCount());
// bad request: assuming nothing listens on port=8081
try {
client.target("http://127.0.0.1:8081/get").request().get().close();
fail("Exception expected");
} catch (ProcessingException e) {
// ignore...
}
assertEquals(0, timer.getCount());
// successful request
client.target("http://127.0.0.1:8080/get").request().get().close();
assertEquals(1, timer.getCount());
}
示例3: loadHttpMethod
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
protected void loadHttpMethod(final ClientInvocation request, HttpRequestBase httpMethod)
throws Exception {
if (request.getEntity() != null) {
if (httpMethod instanceof HttpGet) {
throw new ProcessingException("A GET request cannot have a body.");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
request.getDelegatingOutputStream().setDelegate(baos);
try {
HttpEntity entity = buildEntity(request);
HttpPost post = (HttpPost) httpMethod;
commitHeaders(request, httpMethod);
post.setEntity(entity);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else // no body
{
commitHeaders(request, httpMethod);
}
}
示例4: makePost
import javax.ws.rs.ProcessingException; //导入依赖的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);
}
}
}
示例5: makePost_checkProcessingExceptionIsThrown
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
@Test
public void makePost_checkProcessingExceptionIsThrown() throws IOException, SAXException,
ParserConfigurationException, URISyntaxException, SOAPRequestError {
ProcessingException exception = mock(ProcessingException.class);
when(webResourceBuilder.post(any(Entity.class))).thenThrow(exception);
Element matchingServiceRequest = XmlUtils.convertToElement("<someElement/>");
URI matchingServiceUri = new URI("http://heyyeyaaeyaaaeyaeyaa.com/abc1");
try {
soapRequestClient.makeSoapRequest(matchingServiceRequest, matchingServiceUri);
fail("Exception should have been thrown");
}
catch(ProcessingException e) {
assertThat(e).isEqualTo(exception);
}
}
示例6: getEntity
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
/**
* Returns the entity with the specified id. Returns null if it does not exist.
* @param id Id of the entity to find.
* @param client The REST client to use.
* @param <T> Type of entity to handle.
* @throws NotFoundException If 404 was returned.
* @throws TimeoutException If 408 was returned.
* @return The entity; null if it does not exist.
*/
public static <T> T getEntity(RESTClient<T> client, long id) throws NotFoundException, TimeoutException {
Response response = client.getService().path(client.getApplicationURI()).path(client.getEndpointURI()).
path(String.valueOf(id)).request(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
throw new NotFoundException();
} else if (response.getStatus() == Status.REQUEST_TIMEOUT.getStatusCode()) {
throw new TimeoutException();
}
T entity = null;
try {
entity = response.readEntity(client.getEntityClass());
} catch (NullPointerException | ProcessingException e) {
LOG.warn("Response did not conform to expected entity type.");
}
if (response != null) {
response.close();
}
return entity;
}
示例7: getEntities
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
/**
* Returns a list of Entities of the relevant type after filtering using a path param query.
* Example: "category", 2, 1, 3 will return 3 items in Category with ID 2,
* beginning from item with index 1 (skipping item 0).
* Note that the AbstractCRUDEndpoint does not offer this feature by default.
* @param client The REST client to use.
* @param filterURI Name of the objects to filter for. E.g., "category".
* @param filterId Id of the Object to filter for. E.g, 2
* @param startIndex The index of the first entity to return (index, not ID!). -1,
* if you don't want to set an index.
* @param limit Maximum amount of entities to return. -1, for no max.
* @param <T> Type of entity to handle.
* @throws NotFoundException If 404 was returned.
* @throws TimeoutException If 408 was returned.
* @return List of entities; empty list if non were found.
*/
public static <T> List<T> getEntities(RESTClient<T> client, String filterURI,
long filterId, int startIndex, int limit) throws NotFoundException, TimeoutException {
WebTarget target = client.getService().path(client.getApplicationURI())
.path(client.getEndpointURI()).path(filterURI).path(String.valueOf(filterId));
if (startIndex >= 0) {
target = target.queryParam("start", startIndex);
}
if (limit >= 0) {
target = target.queryParam("max", limit);
}
Response response = target.request(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
throw new NotFoundException();
} else if (response.getStatus() == Status.REQUEST_TIMEOUT.getStatusCode()) {
throw new TimeoutException();
}
List<T> entities = new ArrayList<T>();
if (response != null && response.getStatus() == 200) {
try {
entities = response.readEntity(client.getGenericListType());
} catch (ProcessingException e) {
e.printStackTrace();
LOG.warn("Response did not conform to expected entity type. List expected.");
}
}
if (response != null) {
response.close();
}
return entities;
}
示例8: getEntityWithProperty
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
/**
* Returns an Entity of the relevant type by using a unique non-primary-key property.
* Example: Get user with user name.
* Note that the AbstractCRUDEndpoint does not offer this feature by default.
* @param client The REST client to use.
* @param propertyURI Name of the property. E.g., "name".
* @param propertyValue Value of the property, e.g., "user1".
* @param <T> Type of entity to handle.
* @throws NotFoundException If 404 was returned.
* @throws TimeoutException If 408 was returned.
* @return The entity; null if it does not exist.
*/
public static <T> T getEntityWithProperty(RESTClient<T> client, String propertyURI,
String propertyValue) throws NotFoundException, TimeoutException {
WebTarget target = client.getService().path(client.getApplicationURI())
.path(client.getEndpointURI()).path(propertyURI).path(propertyValue);
Response response = target.request(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
throw new NotFoundException();
} else if (response.getStatus() == Status.REQUEST_TIMEOUT.getStatusCode()) {
throw new TimeoutException();
}
T entity = null;
try {
entity = response.readEntity(client.getEntityClass());
} catch (NullPointerException | ProcessingException e) {
//This happens if no entity was found
}
if (response != null) {
response.close();
}
return entity;
}
示例9: getServersForService
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
/**
* Get all servers for a service in the {@link Service} enum from the registry.
* @param targetService The service for which to get the servers.
* @return List of servers.
*/
public List<Server> getServersForService(Service targetService) {
List<String> list = null;
List<Server> serverList = new ArrayList<Server>();
try {
Response response = getRESTClient(5000).target(registryRESTURL)
.path("/" + targetService.getServiceName() + "/")
.request(MediaType.APPLICATION_JSON).get();
list = response.readEntity(new GenericType<List<String>>() { });
} catch (ProcessingException e) {
return null;
}
if (list != null) {
for (String string: list) {
serverList.add(new Server(string));
}
}
return serverList;
}
示例10: isRunningServer
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
private static boolean isRunningServer() {
try {
log.info("Check if server is running ...");
VmidcServerRestClient restClient = new VmidcServerRestClient("localhost", apiPort, VMIDC_DEFAULT_LOGIN, VMIDC_DEFAULT_PASS, true);
ServerStatusResponse res = getServerStatusResponse(restClient);
String oldPid = res.getPid();
log.warn("Current pid:" + ServerUtil.getCurrentPid() + ". Running server (pid:" + oldPid + ") version: "
+ res.getVersion() + " with db version: " + res.getDbVersion());
return true;
} catch (ProcessingException | ConnectException e1) {
log.warn("Fail to connect to running server: "+ e1.getMessage());
} catch (Exception ex) {
log.warn("Fail to connect to running server. Assuming not running: " + ex);
}
return false;
}
示例11: handleAssignment
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
private void handleAssignment(TaskAssignmentDto taskAssignment)
throws CallbackException {
try {
String callbackUrl = taskAssignment.getTask().getCallbackUrl();
Response response = client.target(callbackUrl)
.property(ClientProperties.FOLLOW_REDIRECTS, configuration.getClientFollowRedirects())
.request(MediaType.WILDCARD_TYPE)
.post(Entity.entity(taskAssignment, MediaType.APPLICATION_JSON_TYPE));
if (response.getStatus() == Status.SERVICE_UNAVAILABLE.getStatusCode()) {
// On 503 response we will try again
// TODO Retry-After header?!
throw new CallbackException();
}
} catch (ProcessingException e) {
throw new CallbackException();
}
}
示例12: readFrom
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
@Override
public CharmAttachmentMeta readFrom(Class<CharmAttachmentMeta> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext context = JAXBContext.newInstance(CharmAttachmentMeta.class);
Unmarshaller attachmentUnmarshaller = context.createUnmarshaller();
return (CharmAttachmentMeta) attachmentUnmarshaller.unmarshal(entityStream);
} catch (JAXBException e) {
throw new ProcessingException("Error deserializing Attachment");
}
}
示例13: writeTo
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
@Override
public void writeTo(CharmTask charmTask, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext context = JAXBContext.newInstance(CharmTask.class);
Marshaller taskMarshaller = context.createMarshaller();
taskMarshaller.marshal(charmTask, entityStream);
} catch (JAXBException e) {
throw new ProcessingException("Error serializing Charm Task to output stream");
}
}
示例14: readFrom
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
@Override
public CharmTask readFrom(Class<CharmTask> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext context = JAXBContext.newInstance(CharmTask.class);
Unmarshaller taskUnmarshaller = context.createUnmarshaller();
return (CharmTask) taskUnmarshaller.unmarshal(entityStream);
} catch (JAXBException e) {
throw new ProcessingException("Error deserializing Task");
}
}
示例15: readFrom
import javax.ws.rs.ProcessingException; //导入依赖的package包/类
@Override
public CharmErrorMessage readFrom(Class<CharmErrorMessage> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext context = JAXBContext.newInstance(CharmErrorMessage.class);
Unmarshaller errorUnmarshaller = context.createUnmarshaller();
return (CharmErrorMessage) errorUnmarshaller.unmarshal(entityStream);
} catch (JAXBException e) {
throw new ProcessingException("Error deserializing Error Message");
}
}