@Override protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException { try { return super.doInvokeMethod(method, properties); } catch (RuntimeCamelException e) { if (e.getCause() instanceof WebApplicationException) { final WebApplicationException cause = (WebApplicationException) e.getCause(); final Response response = cause.getResponse(); if (response.hasEntity()) { // try and convert it to LinkedInException final org.apache.camel.component.linkedin.api.model.Error error = response.readEntity(Error.class); throw new RuntimeCamelException( String.format("Error invoking %s: %s", method.getName(), error.getMessage()), new LinkedInException(error, response)); } } throw e; } } }
@Override protected Object doInvokeMethod(Map<String, Object> args) { try { return super.doInvokeMethod(args); } catch (RuntimeCamelException e) { if (e.getCause() instanceof WebApplicationException) { WebApplicationException cause = (WebApplicationException) e.getCause(); final Response response = cause.getResponse(); if (response.hasEntity()) { // try and convert it to LinkedInException final org.apache.camel.component.linkedin.api.model.Error error = response.readEntity(Error.class); throw new RuntimeCamelException( String.format("Error invoking %s: %s", method.getName(), error.getMessage()), new LinkedInException(error, response)); } } throw e; } } }
@Override protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException { try { return super.doInvokeMethod(method, properties); } catch (RuntimeCamelException e) { if (e.getCause() instanceof WebApplicationException) { final WebApplicationException cause = (WebApplicationException) e.getCause(); final Response response = cause.getResponse(); if (response.hasEntity()) { // try and convert it to LinkedInException final org.apache.camel.component.linkedin.api.model.Error error = response.readEntity(Error.class); throw new RuntimeCamelException( String.format("Error invoking %s: %s", method.getName(), error.getMessage()), new LinkedInException(error, response)); } } throw e; } } }
@Override protected Object doInvokeMethod(Map<String, Object> args) { try { return super.doInvokeMethod(args); } catch (RuntimeCamelException e) { if (e.getCause() instanceof WebApplicationException) { WebApplicationException cause = (WebApplicationException) e.getCause(); final Response response = cause.getResponse(); if (response.hasEntity()) { // try and convert it to LinkedInException final org.apache.camel.component.linkedin.api.model.Error error = response.readEntity(Error.class); throw new RuntimeCamelException( String.format("Error invoking %s: %s", method.getName(), error.getMessage()), new LinkedInException(error, response)); } } throw e; } } }
@Test public void testGlobal() throws Exception { output.expectedMessageCount(0); inter.expectedMessageCount(1); error.expectedMessageCount(0); try { producerTemplate.sendBody("direct:input-1", "blah"); fail("failure not reported"); } catch (RuntimeCamelException e) { assertEquals("message rejected", e.getCause().getMessage()); } output.assertIsSatisfied(); inter.assertIsSatisfied(); error.assertIsSatisfied(); }
@Test public void testError2() throws Exception { error1.expectedMessageCount(0); error2.expectedMessageCount(1); error3.expectedMessageCount(0); success.expectedMessageCount(0); try { producerTemplate.sendBody("direct:input", "blub"); } catch (RuntimeCamelException e) { assertEquals(Exception2.class, e.getCause().getClass()); } error1.assertIsSatisfied(); error2.assertIsSatisfied(); error3.assertIsSatisfied(); success.assertIsSatisfied(); }
@Test public void testError3() throws Exception { error1.expectedMessageCount(0); error2.expectedMessageCount(0); error3.expectedMessageCount(1); success.expectedMessageCount(0); try { producerTemplate.sendBody("direct:input", "oink"); } catch (RuntimeCamelException e) { assertEquals(Exception3.class, e.getCause().getClass()); } error1.assertIsSatisfied(); error2.assertIsSatisfied(); error3.assertIsSatisfied(); success.assertIsSatisfied(); }
@Test public void testLocal() throws Exception { output.expectedMessageCount(0); inter.expectedMessageCount(1); check.expectedMessageCount(3); error.expectedMessageCount(1); try { producerTemplate.sendBody("direct:input-2", "blah"); fail("failure not reported"); } catch (RuntimeCamelException e) { assertEquals("message rejected", e.getCause().getMessage()); } output.assertIsSatisfied(); inter.assertIsSatisfied(); check.assertIsSatisfied(); error.assertIsSatisfied(); }
@Test public void testError1() throws Exception { error1.expectedMessageCount(1); error2.expectedMessageCount(0); error3.expectedMessageCount(0); success.expectedMessageCount(0); try { producerTemplate.sendBody("direct:input", "blah"); fail("failure not reported"); } catch (RuntimeCamelException e) { assertEquals(Exception1.class, e.getCause().getClass()); } error1.assertIsSatisfied(); error2.assertIsSatisfied(); error3.assertIsSatisfied(); success.assertIsSatisfied(); }