use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class EmptyEntityTest method testReceiveEmptyInteger.
@Test
public void testReceiveEmptyInteger() {
WebTarget target = target("empty/getempty");
final Response response = target.request("text/plain").get();
assertEquals(200, response.getStatus());
try {
response.readEntity(Integer.class);
fail("ProcessingException expected.");
} catch (ProcessingException ex) {
assertSame(NoContentException.class, ex.getCause().getClass());
}
try {
target.request("text/plain").get(Integer.class);
fail("ResponseProcessingException expected.");
} catch (ResponseProcessingException ex) {
assertSame(NoContentException.class, ex.getCause().getClass());
}
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class ItemStoreResourceITCase method testItemsStore.
/**
* Test the item addition, addition event broadcasting and item retrieval from {@link ItemStoreResource}.
*
* @throws Exception in case of a test failure.
*/
@Test
public void testItemsStore() throws Exception {
final List<String> items = Collections.unmodifiableList(Arrays.asList("foo", "bar", "baz"));
final WebTarget itemsTarget = target("items");
// countdown on all events
final CountDownLatch latch = new CountDownLatch(items.size() * MAX_LISTENERS * 2);
final List<Queue<Integer>> indexQueues = new ArrayList<Queue<Integer>>(MAX_LISTENERS);
final EventSource[] sources = new EventSource[MAX_LISTENERS];
final AtomicInteger sizeEventsCount = new AtomicInteger(0);
for (int i = 0; i < MAX_LISTENERS; i++) {
final int id = i;
final EventSource es = EventSource.target(itemsTarget.path("events")).named("SOURCE " + id).build();
sources[id] = es;
final Queue<Integer> indexes = new ConcurrentLinkedQueue<Integer>();
indexQueues.add(indexes);
es.register(new EventListener() {
@Override
@SuppressWarnings("MagicNumber")
public void onEvent(InboundEvent inboundEvent) {
try {
if (inboundEvent.getName() == null) {
final String data = inboundEvent.readData();
LOGGER.info("[-i-] SOURCE " + id + ": Received event id=" + inboundEvent.getId() + " data=" + data);
indexes.add(items.indexOf(data));
} else if ("size".equals(inboundEvent.getName())) {
sizeEventsCount.incrementAndGet();
}
} catch (ProcessingException ex) {
LOGGER.log(Level.SEVERE, "[-x-] SOURCE " + id + ": Error getting event data.", ex);
indexes.add(-999);
} finally {
latch.countDown();
}
}
});
}
try {
open(sources);
for (String item : items) {
postItem(itemsTarget, item);
}
assertTrue("Waiting to receive all events has timed out.", latch.await((1000 + MAX_LISTENERS * EventSource.RECONNECT_DEFAULT) * getAsyncTimeoutMultiplier(), TimeUnit.MILLISECONDS));
// need to force disconnect on server in order for EventSource.close(...) to succeed with HttpUrlConnection
sendCommand(itemsTarget, "disconnect");
} finally {
close(sources);
}
String postedItems = itemsTarget.request().get(String.class);
for (String item : items) {
assertTrue("Item '" + item + "' not stored on server.", postedItems.contains(item));
}
int queueId = 0;
for (Queue<Integer> indexes : indexQueues) {
for (int i = 0; i < items.size(); i++) {
assertTrue("Event for '" + items.get(i) + "' not received in queue " + queueId, indexes.contains(i));
}
assertEquals("Not received the expected number of events in queue " + queueId, items.size(), indexes.size());
queueId++;
}
assertEquals("Number of received 'size' events does not match.", items.size() * MAX_LISTENERS, sizeEventsCount.get());
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class ParameterValueHelper method getParameterValues.
/**
* Get the array of parameter values.
*
* @param valueProviders a list of value providers.
* @return array of parameter values provided by the value providers.
*/
public static Object[] getParameterValues(List<ParamValueFactoryWithSource<?>> valueProviders) {
final Object[] params = new Object[valueProviders.size()];
try {
int entityProviderIndex = -1;
int index = 0;
for (ParamValueFactoryWithSource<?> paramValProvider : valueProviders) {
// entity provider has to be called last; see JERSEY-2642
if (paramValProvider.getSource().equals(Parameter.Source.ENTITY)) {
entityProviderIndex = index++;
continue;
}
params[index++] = paramValProvider.get();
}
if (entityProviderIndex != -1) {
params[entityProviderIndex] = valueProviders.get(entityProviderIndex).get();
}
return params;
} catch (WebApplicationException e) {
throw e;
} catch (MessageBodyProviderNotFoundException e) {
throw new NotSupportedException(e);
} catch (ProcessingException e) {
throw e;
} catch (RuntimeException e) {
if (e.getCause() instanceof WebApplicationException) {
throw (WebApplicationException) e.getCause();
}
throw new MappableException("Exception obtaining parameters", e);
}
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class WadlGeneratorConfig method createWadlGenerator.
/**
* Create a new instance of {@link org.glassfish.jersey.server.wadl.WadlGenerator}, based on the {@link WadlGeneratorDescription}s
* provided by {@link #configure()}.
*
* @return the initialized {@link org.glassfish.jersey.server.wadl.WadlGenerator}
*/
public WadlGenerator createWadlGenerator(InjectionManager injectionManager) {
final WadlGenerator wadlGenerator;
final List<WadlGeneratorDescription> wadlGeneratorDescriptions;
try {
wadlGeneratorDescriptions = configure();
} catch (final Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_GENERATOR_CONFIGURE(), e);
}
for (final WadlGeneratorDescription desc : wadlGeneratorDescriptions) {
desc.setConfiguratorClass(this.getClass());
}
try {
wadlGenerator = WadlGeneratorLoader.loadWadlGeneratorDescriptions(injectionManager, wadlGeneratorDescriptions);
} catch (final Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_GENERATOR_LOAD(), e);
}
return wadlGenerator;
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class WadlBuilder method generateMethod.
private com.sun.research.ws.wadl.Method generateMethod(final org.glassfish.jersey.server.model.Resource parentResource, final Map<String, Param> wadlResourceParams, final org.glassfish.jersey.server.model.ResourceMethod resourceMethod) {
try {
if (!detailedWadl && resourceMethod.isExtended()) {
return null;
}
com.sun.research.ws.wadl.Method wadlMethod = _wadlGenerator.createMethod(parentResource, resourceMethod);
// generate the request part
Request wadlRequest = generateRequest(parentResource, resourceMethod, wadlResourceParams);
if (wadlRequest != null) {
wadlMethod.setRequest(wadlRequest);
}
// generate the response part
final List<Response> responses = generateResponses(parentResource, resourceMethod);
if (responses != null) {
wadlMethod.getResponse().addAll(responses);
}
return wadlMethod;
} catch (Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_METHOD(resourceMethod, parentResource), e);
}
}
Aggregations