Search in sources :

Example 16 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project OpenAM by OpenRock.

the class SAXUnmarshallerHandlerImpl method handleEvent.

public void handleEvent(ValidationEvent event, boolean canRecover) throws SAXException {
    ValidationEventHandler eventHandler;
    try {
        eventHandler = parent.getEventHandler();
    } catch (JAXBException e) {
        // impossible.
        throw new JAXBAssertionError();
    }
    boolean recover = eventHandler.handleEvent(event);
    // from the unmarshaller.getResult()
    if (!recover)
        aborted = true;
    if (!canRecover || !recover)
        throw new SAXException(new UnmarshalException(event.getMessage(), event.getLinkedException()));
}
Also used : ValidationEventHandler(javax.xml.bind.ValidationEventHandler) JAXBAssertionError(com.sun.xml.bind.JAXBAssertionError) UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException)

Example 17 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project cxf by apache.

the class ClientServerRPCLitTest method testComplexType.

@Test
public void testComplexType() throws Exception {
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    assertNotNull(service);
    GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
    updateAddressPort(greeter, PORT);
    MyComplexStruct in = new MyComplexStruct();
    in.setElem1("elem1");
    in.setElem2("elem2");
    in.setElem3(45);
    try {
        ((BindingProvider) greeter).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
        MyComplexStruct out = greeter.sendReceiveData(in);
        assertNotNull("no response received from service", out);
        assertEquals(in.getElem1(), out.getElem1());
        assertEquals(in.getElem2(), out.getElem2());
        assertEquals(in.getElem3(), out.getElem3());
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
    try {
        in.setElem2("invalid");
        greeter.sendReceiveData(in);
    } catch (SOAPFaultException f) {
        assertTrue(f.getCause() instanceof UnmarshalException);
    }
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) UnmarshalException(javax.xml.bind.UnmarshalException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) MyComplexStruct(org.apache.hello_world_rpclit.types.MyComplexStruct) Test(org.junit.Test)

Example 18 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project Payara by payara.

the class PipeHelper method authorize.

public void authorize(Packet request) throws Exception {
    // SecurityContext constructor should set initiator to
    // unathenticated if Subject is null or empty
    Subject s = (Subject) request.invocationProperties.get(PipeConstants.CLIENT_SUBJECT);
    if (s == null || (s.getPrincipals().isEmpty() && s.getPublicCredentials().isEmpty())) {
        SecurityContext.setUnauthenticatedContext();
    } else {
        SecurityContext sC = new SecurityContext(s);
        SecurityContext.setCurrent(sC);
    }
    if (isEjbEndpoint) {
        if (invManager == null) {
            throw new RuntimeException(localStrings.getLocalString("enterprise.webservice.noEjbInvocationManager", "Cannot validate request : invocation manager null for EJB WebService"));
        }
        ComponentInvocation inv = (ComponentInvocation) invManager.getCurrentInvocation();
        // consumed
        if (ejbDelegate != null) {
            ejbDelegate.setSOAPMessage(request.getMessage(), inv);
        }
        Exception ie;
        Method m = null;
        if (seiModel != null) {
            JavaMethod jm = request.getMessage().getMethod(seiModel);
            m = (jm != null) ? jm.getMethod() : null;
        } else {
            // WebServiceProvider
            WebServiceEndpoint endpoint = (WebServiceEndpoint) map.get(PipeConstants.SERVICE_ENDPOINT);
            EjbDescriptor ejbDescriptor = endpoint.getEjbComponentImpl();
            if (ejbDescriptor != null) {
                final String ejbImplClassName = ejbDescriptor.getEjbImplClassName();
                if (ejbImplClassName != null) {
                    try {
                        m = (Method) AppservAccessController.doPrivileged(new PrivilegedExceptionAction() {

                            @Override
                            public Object run() throws Exception {
                                ClassLoader loader = Thread.currentThread().getContextClassLoader();
                                Class clazz = Class.forName(ejbImplClassName, true, loader);
                                return clazz.getMethod("invoke", new Class[] { Object.class });
                            }
                        });
                    } catch (PrivilegedActionException pae) {
                        throw new RuntimeException(pae.getException());
                    }
                }
            }
        }
        if (m != null) {
            if (ejbDelegate != null) {
                try {
                    if (!ejbDelegate.authorize(inv, m)) {
                        throw new Exception(localStrings.getLocalString("enterprise.webservice.methodNotAuth", "Client not authorized for invocation of {0}", new Object[] { m }));
                    }
                } catch (UnmarshalException e) {
                    String errorMsg = localStrings.getLocalString("enterprise.webservice.errorUnMarshalMethod", "Error unmarshalling method for ejb {0}", new Object[] { ejbName() });
                    ie = new UnmarshalException(errorMsg);
                    ie.initCause(e);
                    throw ie;
                } catch (Exception e) {
                    ie = new Exception(localStrings.getLocalString("enterprise.webservice.methodNotAuth", "Client not authorized for invocation of {0}", new Object[] { m }));
                    ie.initCause(e);
                    throw ie;
                }
            }
        }
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) PrivilegedActionException(java.security.PrivilegedActionException) JavaMethod(com.sun.xml.ws.api.model.JavaMethod) Method(java.lang.reflect.Method) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Subject(javax.security.auth.Subject) PrivilegedActionException(java.security.PrivilegedActionException) UnmarshalException(javax.xml.bind.UnmarshalException) AuthException(javax.security.auth.message.AuthException) WebServiceException(javax.xml.ws.WebServiceException) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint) UnmarshalException(javax.xml.bind.UnmarshalException) ClientSecurityContext(com.sun.enterprise.security.common.ClientSecurityContext) SecurityContext(com.sun.enterprise.security.SecurityContext) JavaMethod(com.sun.xml.ws.api.model.JavaMethod)

Example 19 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project BIMserver by opensourceBIM.

the class VersionChecker method getOnlineVersion.

public synchronized SVersion getOnlineVersion() {
    if (lastCheck == null || lastCheck.before(getReferenceDate())) {
        LOGGER.info("Fetching online version info");
        try {
            URL url = new URL("http://www.bimserver.org/version/versionv2.xml");
            JAXBContext jaxbContext = JAXBContext.newInstance(SVersion.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            onlineVersion = (SVersion) unmarshaller.unmarshal(url);
            lastCheck = new GregorianCalendar();
            return onlineVersion;
        } catch (UnmarshalException e) {
            LOGGER.error("", e);
        } catch (MalformedURLException e) {
            LOGGER.error("", e);
        } catch (JAXBException e) {
            LOGGER.error("", e);
        }
        if (onlineVersion == null) {
            onlineVersion = new SVersion();
            onlineVersion.setDownloadUrl("unknown");
            onlineVersion.setMajor(-1);
            onlineVersion.setMinor(-1);
            onlineVersion.setRevision(-1);
            onlineVersion.setSupportEmail("unknown");
            onlineVersion.setSupportUrl("unknown");
            onlineVersion.setDate(new Date(0));
            lastCheck = new GregorianCalendar();
        }
    }
    return onlineVersion;
}
Also used : MalformedURLException(java.net.MalformedURLException) UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) JAXBContext(javax.xml.bind.JAXBContext) SVersion(org.bimserver.interfaces.objects.SVersion) Unmarshaller(javax.xml.bind.Unmarshaller) URL(java.net.URL) Date(java.util.Date)

Example 20 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project phoenix by apache.

the class XMLConfigParserTest method testDTDInScenario.

@Test
public void testDTDInScenario() throws Exception {
    URL scenarioUrl = XMLConfigParserTest.class.getResource("/scenario/malicious_scenario_with_dtd.xml");
    assertNotNull(scenarioUrl);
    Path p = Paths.get(scenarioUrl.toURI());
    try {
        XMLConfigParser.readDataModel(p);
        fail("The scenario should have failed to parse because it contains a DTD");
    } catch (UnmarshalException e) {
        // If we don't parse the DTD, the variable 'name' won't be defined in the XML
        LOG.warn("Caught expected exception", e);
        Throwable cause = e.getLinkedException();
        assertTrue("Cause was a " + cause.getClass(), cause instanceof XMLStreamException);
    }
}
Also used : Path(java.nio.file.Path) XMLStreamException(javax.xml.stream.XMLStreamException) UnmarshalException(javax.xml.bind.UnmarshalException) URL(java.net.URL) Test(org.junit.Test)

Aggregations

UnmarshalException (javax.xml.bind.UnmarshalException)24 JAXBException (javax.xml.bind.JAXBException)15 IOException (java.io.IOException)6 JAXBAssertionError (com.sun.xml.bind.JAXBAssertionError)5 ValidationEventHandler (javax.xml.bind.ValidationEventHandler)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 Test (org.junit.Test)5 SAXException (org.xml.sax.SAXException)5 Unmarshaller (javax.xml.bind.Unmarshaller)4 File (java.io.File)3 URL (java.net.URL)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 StringReader (java.io.StringReader)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 ArrayList (java.util.ArrayList)2 BadRequestException (javax.ws.rs.BadRequestException)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NoContentException (javax.ws.rs.core.NoContentException)2 JAXBContext (javax.xml.bind.JAXBContext)2 XmlType (javax.xml.bind.annotation.XmlType)2