Search in sources :

Example 66 with MessageFactory

use of javax.xml.soap.MessageFactory in project jbossws-cxf by jbossws.

the class JBWS3945TestCase method testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ.

@Test
@RunAsClient
public void testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ() throws Exception {
    try {
        // <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:throwSoapFaultException xmlns:ns2="http://server.exception.samples.jaxws.ws.test.jboss.org/"/></soap:Body></soap:Envelope>
        SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
        SOAPConnection con = conFac.createConnection();
        MessageFactory msgFactory = MessageFactory.newInstance();
        SOAPMessage msg = msgFactory.createMessage();
        msg.getSOAPBody().addBodyElement(new QName(targetNS, "throwSoapFaultException"));
        SOAPMessage response = con.call(msg, new URL(targetEndpoint + "Servlet"));
        Element el = (Element) response.getSOAPBody().getChildElements().next();
        assertEquals("Fault", el.getLocalName());
    } catch (Exception e) {
        fail(e);
    }
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 67 with MessageFactory

use of javax.xml.soap.MessageFactory in project iaf by ibissource.

the class SoapProviderTest method createMessage.

private SOAPMessage createMessage(String filename, boolean addAttachment, boolean isSoap1_1) throws IOException, SOAPException {
    MessageFactory factory = MessageFactory.newInstance(isSoap1_1 ? SOAPConstants.SOAP_1_1_PROTOCOL : SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage soapMessage = factory.createMessage();
    StreamSource streamSource = new StreamSource(getFile(filename));
    soapMessage.getSOAPPart().setContent(streamSource);
    if (addAttachment) {
        InputStream fis = new ByteArrayInputStream(ATTACHMENT_CONTENT.getBytes());
        DataHandler dataHander = new DataHandler(new ByteArrayDataSource(fis, ATTACHMENT_MIMETYPE));
        AttachmentPart part = soapMessage.createAttachmentPart(dataHander);
        soapMessage.addAttachmentPart(part);
    }
    return soapMessage;
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) AttachmentPart(javax.xml.soap.AttachmentPart) DataHandler(javax.activation.DataHandler) SOAPMessage(javax.xml.soap.SOAPMessage) ByteArrayDataSource(org.apache.soap.util.mime.ByteArrayDataSource)

Example 68 with MessageFactory

use of javax.xml.soap.MessageFactory in project iaf by ibissource.

the class SoapWrapper method signMessage.

public Message signMessage(Message soapMessage, String user, String password, boolean passwordDigest) {
    try {
        // We only support signing for soap1_1 ?
        // Create an empty message and populate it later. createMessage(MimeHeaders, InputStream) requires proper headers to be set which we do not have...
        MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        SOAPMessage msg = factory.createMessage();
        SOAPPart part = msg.getSOAPPart();
        part.setContent(new StreamSource(soapMessage.asInputStream()));
        // create unsigned envelope
        SOAPEnvelope unsignedEnvelope = part.getEnvelope();
        Document doc = unsignedEnvelope.getOwnerDocument();
        // create security header and insert it into unsigned envelope
        WSSecHeader secHeader = new WSSecHeader(doc);
        secHeader.insertSecurityHeader();
        // add a UsernameToken
        WSSecUsernameToken tokenBuilder = new WSSecUsernameToken(secHeader);
        tokenBuilder.setIdAllocator(idAllocator);
        if (passwordDigest) {
            tokenBuilder.setPasswordType(WSConstants.PASSWORD_DIGEST);
        } else {
            tokenBuilder.setPasswordType(WSConstants.PASSWORD_TEXT);
        }
        tokenBuilder.setPrecisionInMilliSeconds(false);
        tokenBuilder.setUserInfo(user, password);
        WSTimeSource timesource = tokenBuilder.getWsTimeSource();
        tokenBuilder.addNonce();
        tokenBuilder.addCreated();
        tokenBuilder.prepare(null);
        Element element = tokenBuilder.getUsernameTokenElement();
        String nonce = XmlUtils.getChildTagAsString(element, "wsse:Nonce");
        byte[] decodedNonce = org.apache.xml.security.utils.XMLUtils.decode(nonce);
        String created = XmlUtils.getChildTagAsString(element, "wsu:Created");
        WSSecSignature sign = new WSSecSignature(secHeader);
        sign.setIdAllocator(idAllocator);
        sign.setCustomTokenValueType(WSConstants.WSS_USERNAME_TOKEN_VALUE_TYPE);
        sign.setCustomTokenId(tokenBuilder.getId());
        sign.setSigCanonicalization(WSConstants.C14N_EXCL_OMIT_COMMENTS);
        sign.setAddInclusivePrefixes(false);
        // conform WS-Trust spec
        String signatureValue = UsernameTokenUtil.doPasswordDigest(decodedNonce, created, password);
        sign.setSecretKey(signatureValue.getBytes(StreamUtil.DEFAULT_CHARSET));
        // UT_SIGNING no longer exists since v1.5.11
        sign.setKeyIdentifierType(WSConstants.CUSTOM_SYMM_SIGNING);
        sign.setSignatureAlgorithm(WSConstants.HMAC_SHA1);
        sign.build(null);
        tokenBuilder.prependToHeader();
        // add a Timestamp
        WSSecTimestamp timestampBuilder = new WSSecTimestamp(secHeader);
        timestampBuilder.setWsTimeSource(timesource);
        timestampBuilder.setTimeToLive(300);
        timestampBuilder.setIdAllocator(idAllocator);
        timestampBuilder.build();
        return new Message(doc);
    } catch (Exception e) {
        throw new RuntimeException("Could not sign message", e);
    }
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) Message(nl.nn.adapterframework.stream.Message) SOAPMessage(javax.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Element(org.w3c.dom.Element) WSSecSignature(org.apache.wss4j.dom.message.WSSecSignature) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage) WSSecTimestamp(org.apache.wss4j.dom.message.WSSecTimestamp) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException) WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) SOAPPart(javax.xml.soap.SOAPPart) WSSecUsernameToken(org.apache.wss4j.dom.message.WSSecUsernameToken) WSTimeSource(org.apache.wss4j.common.util.WSTimeSource)

Example 69 with MessageFactory

use of javax.xml.soap.MessageFactory in project iaf by ibissource.

the class SoapWrapperTest method toSoapMessage.

private Message toSoapMessage(URL url) throws Exception {
    MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
    SOAPMessage msg = factory.createMessage();
    SOAPPart part = msg.getSOAPPart();
    part.setContent(new StreamSource(url.openStream()));
    // create unsigned envelope
    SOAPEnvelope unsignedEnvelope = part.getEnvelope();
    Document doc = unsignedEnvelope.getOwnerDocument();
    return new Message(doc);
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) Message(nl.nn.adapterframework.stream.Message) SOAPMessage(javax.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) SOAPPart(javax.xml.soap.SOAPPart) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 70 with MessageFactory

use of javax.xml.soap.MessageFactory in project iaf by ibissource.

the class XmlUtils method getVersionInfo.

public static Map<String, String> getVersionInfo() {
    Map<String, String> map = new LinkedHashMap<>();
    SAXParserFactory spFactory = getSAXParserFactory();
    map.put("SAXParserFactory-class", spFactory.getClass().getName());
    DocumentBuilderFactory domFactory1 = getDocumentBuilderFactory(false);
    map.put("DocumentBuilderFactory1-class", domFactory1.getClass().getName());
    DocumentBuilderFactory domFactory2 = getDocumentBuilderFactory(true);
    map.put("DocumentBuilderFactory2-class", domFactory2.getClass().getName());
    TransformerFactory tFactory1 = getTransformerFactory(1);
    map.put("TransformerFactory1-class", tFactory1.getClass().getName());
    TransformerFactory tFactory2 = getTransformerFactory(2);
    map.put("TransformerFactory2-class", tFactory2.getClass().getName());
    XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance();
    map.put("XMLEventFactory-class", xmlEventFactory.getClass().getName());
    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    map.put("XMLInputFactory-class", xmlInputFactory.getClass().getName());
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    map.put("XMLOutputFactory-class", xmlOutputFactory.getClass().getName());
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        map.put("MessageFactory-class", messageFactory.getClass().getName());
    } catch (SOAPException e) {
        log.warn("unable to create MessageFactory", e);
        map.put("MessageFactory-class", "unable to create MessageFactory (" + e.getClass().getName() + "): " + e.getMessage() + ")");
    }
    try {
        map.put("Xerces-Version", org.apache.xerces.impl.Version.getVersion());
    } catch (Throwable t) {
        log.warn("could not get Xerces version", t);
        map.put("Xerces-Version", "not found (" + t.getClass().getName() + "): " + t.getMessage() + ")");
    }
    try {
        String xalanVersion = org.apache.xalan.Version.getVersion();
        map.put("Xalan-Version", xalanVersion);
    } catch (Throwable t) {
        log.warn("could not get Xalan version", t);
        map.put("Xalan-Version", "not found (" + t.getClass().getName() + "): " + t.getMessage() + ")");
    }
    try {
        String saxonVersion = net.sf.saxon.Version.getProductTitle();
        map.put("Saxon-Version", saxonVersion);
    } catch (Throwable t) {
        log.warn("could not get Saxon version", t);
        map.put("Saxon-Version", "not found (" + t.getClass().getName() + "): " + t.getMessage() + ")");
    }
    try {
        if (xmlInputFactory instanceof WstxInputFactory) {
            ReaderConfig woodstoxConfig = ((WstxInputFactory) xmlInputFactory).createPrivateConfig();
            String woodstoxVersion = ReaderConfig.getImplName() + " " + ReaderConfig.getImplVersion() + "; xml1.1 " + (woodstoxConfig.isXml11() ? "" : "not ") + "enabled";
            map.put("Woodstox-Version", woodstoxVersion);
        }
    } catch (Throwable t) {
        log.warn("could not get Woodstox version", t);
        map.put("Woodstox-Version", "not found (" + t.getClass().getName() + "): " + t.getMessage() + ")");
    }
    return map;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) MessageFactory(javax.xml.soap.MessageFactory) XMLEventFactory(javax.xml.stream.XMLEventFactory) WstxInputFactory(com.ctc.wstx.stax.WstxInputFactory) LinkedHashMap(java.util.LinkedHashMap) SOAPException(javax.xml.soap.SOAPException) ReaderConfig(com.ctc.wstx.api.ReaderConfig) XMLInputFactory(javax.xml.stream.XMLInputFactory) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

MessageFactory (javax.xml.soap.MessageFactory)70 SOAPMessage (javax.xml.soap.SOAPMessage)65 URL (java.net.URL)24 InputStream (java.io.InputStream)22 QName (javax.xml.namespace.QName)22 SOAPException (javax.xml.soap.SOAPException)22 Test (org.junit.Test)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 SOAPBody (javax.xml.soap.SOAPBody)18 SOAPPart (javax.xml.soap.SOAPPart)17 StreamSource (javax.xml.transform.stream.StreamSource)14 SOAPConnection (javax.xml.soap.SOAPConnection)13 IOException (java.io.IOException)11 SOAPElement (javax.xml.soap.SOAPElement)11 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)10 JBossWSTest (org.jboss.wsf.test.JBossWSTest)10 NodeList (org.w3c.dom.NodeList)9 AttachmentPart (javax.xml.soap.AttachmentPart)8 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)8 Element (org.w3c.dom.Element)8