Search in sources :

Example 96 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class AnnotationHandlerChainBuilder method processHandlerChainElement.

private void processHandlerChainElement(Element el, List<Handler> chain, QName portQName, QName serviceQName, String bindingID) {
    Node node = el.getFirstChild();
    while (node != null) {
        Node cur = node;
        node = node.getNextSibling();
        if (cur instanceof Element) {
            el = (Element) cur;
            if (!el.getNamespaceURI().equals("http://java.sun.com/xml/ns/javaee")) {
                String xml = StaxUtils.toString(el);
                throw new WebServiceException(BundleUtils.getFormattedString(BUNDLE, "NOT_VALID_ELEMENT_IN_HANDLER", xml));
            }
            String name = el.getLocalName();
            if ("port-name-pattern".equals(name)) {
                if (!patternMatches(el, portQName)) {
                    return;
                }
            } else if ("service-name-pattern".equals(name)) {
                if (!patternMatches(el, serviceQName)) {
                    return;
                }
            } else if ("protocol-bindings".equals(name)) {
                if (!protocolMatches(el, bindingID)) {
                    return;
                }
            } else if ("handler".equals(name)) {
                processHandlerElement(el, chain);
            }
        }
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 97 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class HandlerChainBuilder method buildHandlerChain.

protected List<Handler> buildHandlerChain(PortComponentHandlerType ht, ClassLoader classLoader) {
    List<Handler> handlerChain = new ArrayList<>();
    try {
        final boolean fineLog = LOG.isLoggable(Level.FINE);
        if (fineLog) {
            LOG.log(Level.FINE, "loading handler", trimString(ht.getHandlerName().getValue()));
        }
        Class<? extends Handler> handlerClass = Class.forName(trimString(ht.getHandlerClass().getValue()), true, classLoader).asSubclass(Handler.class);
        Handler<?> handler = handlerClass.newInstance();
        if (fineLog) {
            LOG.fine("adding handler to chain: " + handler);
        }
        configureHandler(handler, ht);
        handlerChain.add(handler);
    } catch (Exception e) {
        throw new WebServiceException(BUNDLE.getString("HANDLER_INSTANTIATION_EXC"), e);
    }
    return handlerChain;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException)

Example 98 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class LogicalMessageImpl method getPayload.

public Object getPayload(JAXBContext arg0) {
    try {
        Source s = getPayload();
        if (s instanceof DOMSource) {
            DOMSource ds = (DOMSource) s;
            ds.setNode(org.apache.cxf.helpers.DOMUtils.getDomElement(ds.getNode()));
            Node parent = ds.getNode().getParentNode();
            Node next = ds.getNode().getNextSibling();
            if (parent instanceof DocumentFragment) {
                parent.removeChild(ds.getNode());
            }
            try {
                return JAXBUtils.unmarshall(arg0, ds);
            } finally {
                if (parent instanceof DocumentFragment) {
                    parent.insertBefore(ds.getNode(), next);
                }
            }
        }
        return JAXBUtils.unmarshall(arg0, getPayload());
    } catch (JAXBException e) {
        throw new WebServiceException(e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) WebServiceException(javax.xml.ws.WebServiceException) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) DataSource(javax.activation.DataSource) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 99 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class SOAPMessageContextImpl method getHeaders.

public Object[] getHeaders(QName name, JAXBContext context, boolean allRoles) {
    SOAPMessage msg = getMessage();
    SOAPHeader header;
    try {
        header = msg.getSOAPPart().getEnvelope().getHeader();
        if (header == null || !header.hasChildNodes()) {
            return new Object[0];
        }
        List<Object> ret = new ArrayList<>();
        Iterator<SOAPHeaderElement> it = CastUtils.cast(header.examineAllHeaderElements());
        while (it.hasNext()) {
            SOAPHeaderElement she = it.next();
            if ((allRoles || roles.contains(she.getActor())) && name.equals(she.getElementQName())) {
                ret.add(JAXBUtils.unmarshall(context, she));
            }
        }
        return ret.toArray(new Object[ret.size()]);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    } catch (JAXBException e) {
        throw new WebServiceException(e);
    }
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 100 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class EndpointReferenceTest method testEndpointGetEndpointReferenceInvalid.

@Test
public void testEndpointGetEndpointReferenceInvalid() throws Exception {
    GreeterImpl greeter = new GreeterImpl();
    try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String) null)) {
        endpoint.publish("http://localhost:8080/test");
        try {
            InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml");
            Document doc = StaxUtils.read(is);
            Element referenceParameters = fetchElementByNameAttribute(doc.getDocumentElement(), "wsa:ReferenceParameters", "");
            endpoint.getEndpointReference(MyEndpointReference.class, referenceParameters);
            fail("Did not get expected WebServiceException");
        } catch (WebServiceException e) {
        // do nothing
        }
        endpoint.stop();
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)120 Test (org.junit.Test)50 URL (java.net.URL)37 BindingProvider (javax.xml.ws.BindingProvider)25 Service (javax.xml.ws.Service)22 QName (javax.xml.namespace.QName)14 IOException (java.io.IOException)10 Message (org.apache.cxf.common.i18n.Message)9 JAXBException (javax.xml.bind.JAXBException)8 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)8 Bus (org.apache.cxf.Bus)7 Packet (com.sun.xml.ws.api.message.Packet)6 AuthStatus (javax.security.auth.message.AuthStatus)6 SOAPException (javax.xml.soap.SOAPException)6 SOAPMessage (javax.xml.soap.SOAPMessage)6 ArrayList (java.util.ArrayList)5 WebService (javax.jws.WebService)5 Subject (javax.security.auth.Subject)5 HttpSession (javax.servlet.http.HttpSession)5 Handler (javax.xml.ws.handler.Handler)5