Search in sources :

Example 76 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project j2objc by google.

the class UndeclaredThrowableExceptionTests method test_getCause.

/**
     * java.lang.reflect.UndeclaredThrowableException#getCause()
     */
public void test_getCause() throws Exception {
    UndeclaredThrowableException ute = new UndeclaredThrowableException(throwable);
    assertSame("Wrong cause returned", throwable, ute.getCause());
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 77 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project j2objc by google.

the class UndeclaredThrowableExceptionTests method test_Constructor_Throwable_String.

/**
     * java.lang.reflect.UndeclaredThrowableException#UndeclaredThrowableException(java.lang.Throwable, java.lang.String)
     */
public void test_Constructor_Throwable_String() throws Exception {
    UndeclaredThrowableException e = new UndeclaredThrowableException(throwable, msg);
    assertEquals("Wrong cause returned", throwable, e.getCause());
    assertEquals("Wrong throwable returned", throwable, e.getUndeclaredThrowable());
    assertEquals("Wrong message returned", msg, e.getMessage());
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 78 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project jersey by jersey.

the class AbstractJavaResourceMethodDispatcher method invoke.

/**
     * Use the underlying invocation handler to invoke the underlying Java method
     * with the supplied input method argument values on a given resource instance.
     *
     * @param containerRequest container request.
     * @param resource         resource class instance.
     * @param args             input argument values for the invoked Java method.
     * @return invocation result.
     * @throws ProcessingException (possibly {@link MappableException mappable})
     *                             container exception in case the invocation failed.
     */
final Object invoke(final ContainerRequest containerRequest, final Object resource, final Object... args) throws ProcessingException {
    try {
        // Validate resource class & method input parameters.
        if (validator != null) {
            validator.validateResourceAndInputParams(resource, resourceMethod, args);
        }
        final PrivilegedAction invokeMethodAction = new PrivilegedAction() {

            @Override
            public Object run() {
                final TracingLogger tracingLogger = TracingLogger.getInstance(containerRequest);
                final long timestamp = tracingLogger.timestamp(ServerTraceEvent.METHOD_INVOKE);
                try {
                    return methodHandler.invoke(resource, method, args);
                } catch (IllegalAccessException | IllegalArgumentException | UndeclaredThrowableException ex) {
                    throw new ProcessingException(LocalizationMessages.ERROR_RESOURCE_JAVA_METHOD_INVOCATION(), ex);
                } catch (InvocationTargetException ex) {
                    throw mapTargetToRuntimeEx(ex.getCause());
                } catch (Throwable t) {
                    throw new ProcessingException(t);
                } finally {
                    tracingLogger.logDuration(ServerTraceEvent.METHOD_INVOKE, timestamp, resource, method);
                }
            }
        };
        final SecurityContext securityContext = containerRequest.getSecurityContext();
        final Object invocationResult = (securityContext instanceof SubjectSecurityContext) ? ((SubjectSecurityContext) securityContext).doAsSubject(invokeMethodAction) : invokeMethodAction.run();
        // Validate response entity.
        if (validator != null) {
            validator.validateResult(resource, resourceMethod, invocationResult);
        }
        return invocationResult;
    } catch (ValidationException ex) {
        // handle validation exceptions -> potentially mappable
        throw new MappableException(ex);
    }
}
Also used : MappableException(org.glassfish.jersey.server.internal.process.MappableException) ValidationException(javax.validation.ValidationException) TracingLogger(org.glassfish.jersey.message.internal.TracingLogger) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubjectSecurityContext(org.glassfish.jersey.server.SubjectSecurityContext) PrivilegedAction(java.security.PrivilegedAction) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SecurityContext(javax.ws.rs.core.SecurityContext) SubjectSecurityContext(org.glassfish.jersey.server.SubjectSecurityContext) ProcessingException(javax.ws.rs.ProcessingException)

Example 79 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project jersey by jersey.

the class SubResourceLocatorRouter method getResource.

private Object getResource(final RequestProcessingContext context) {
    final Object resource = context.routingContext().peekMatchedResource();
    final Method handlingMethod = locatorModel.getInvocable().getHandlingMethod();
    final Object[] parameterValues = ParameterValueHelper.getParameterValues(valueProviders);
    context.triggerEvent(RequestEvent.Type.LOCATOR_MATCHED);
    final PrivilegedAction invokeMethodAction = new PrivilegedAction() {

        @Override
        public Object run() {
            try {
                return handlingMethod.invoke(resource, parameterValues);
            } catch (IllegalAccessException | IllegalArgumentException | UndeclaredThrowableException ex) {
                throw new ProcessingException(LocalizationMessages.ERROR_RESOURCE_JAVA_METHOD_INVOCATION(), ex);
            } catch (final InvocationTargetException ex) {
                final Throwable cause = ex.getCause();
                if (cause instanceof WebApplicationException) {
                    throw (WebApplicationException) cause;
                }
                // handle all exceptions as potentially mappable (incl. ProcessingException)
                throw new MappableException(cause);
            } catch (final Throwable t) {
                throw new ProcessingException(t);
            }
        }
    };
    final SecurityContext securityContext = context.request().getSecurityContext();
    return (securityContext instanceof SubjectSecurityContext) ? ((SubjectSecurityContext) securityContext).doAsSubject(invokeMethodAction) : invokeMethodAction.run();
}
Also used : MappableException(org.glassfish.jersey.server.internal.process.MappableException) WebApplicationException(javax.ws.rs.WebApplicationException) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubjectSecurityContext(org.glassfish.jersey.server.SubjectSecurityContext) PrivilegedAction(java.security.PrivilegedAction) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SecurityContext(javax.ws.rs.core.SecurityContext) SubjectSecurityContext(org.glassfish.jersey.server.SubjectSecurityContext) ProcessingException(javax.ws.rs.ProcessingException)

Example 80 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project camel by apache.

the class CxfSoapMessageProviderTest method testSOAPMessageModeDocLit.

@Test
public void testSOAPMessageModeDocLit() throws Exception {
    JaxwsTestHandler fromHandler = getMandatoryBean(JaxwsTestHandler.class, "fromEndpointJaxwsHandler");
    fromHandler.reset();
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    String response1 = new String("TestSOAPOutputPMessage");
    String response2 = new String("Bonjour");
    try {
        Greeter greeter = service.getPort(portName, Greeter.class);
        ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port + "/CxfSoapMessageProviderTest/SoapContext/SoapProviderPort");
        for (int idx = 0; idx < 2; idx++) {
            String greeting = greeter.greetMe("Milestone-" + idx);
            assertNotNull("no response received from service", greeting);
            assertEquals(response1, greeting);
            String reply = greeter.sayHi();
            assertNotNull("no response received from service", reply);
            assertEquals(response2, reply);
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
    assertEquals("Can't get the right message count", fromHandler.getMessageCount(), 8);
    assertEquals("Can't get the right fault count", fromHandler.getFaultCount(), 0);
//From CXF 2.2.7 the soap handler's getHeader() method will not be called if the SOAP message don't have headers
//assertEquals("Can't get the right headers count", fromHandler.getGetHeadersCount(), 4);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) QName(javax.xml.namespace.QName) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) JaxwsTestHandler(org.apache.camel.wsdl_first.JaxwsTestHandler) URL(java.net.URL) Test(org.junit.Test)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)121 IOException (java.io.IOException)36 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 Test (org.junit.Test)12 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PollStatus (org.opennms.netmgt.poller.PollStatus)9 HashMap (java.util.HashMap)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)7 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)7 Method (java.lang.reflect.Method)6 AccessControlException (java.security.AccessControlException)6 SQLException (java.sql.SQLException)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)6