Search in sources :

Example 46 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project coprhd-controller by CoprHD.

the class WinRMTarget method getSOAPFault.

protected SOAPFault getSOAPFault(String content) {
    try {
        Document doc = XmlUtils.parseXml(content);
        SOAPEnvelope e = (SOAPEnvelope) SOAPFactory.newInstance().createElement(doc.getDocumentElement());
        SOAPFault fault = e.getBody().getFault();
        return fault;
    } catch (Exception e) {
        return null;
    }
}
Also used : SOAPFault(javax.xml.soap.SOAPFault) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Document(org.w3c.dom.Document) HttpException(org.apache.http.HttpException) MalformedURLException(java.net.MalformedURLException)

Example 47 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope 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 48 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope 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 49 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project csb-sdk by aliyun.

the class SOAPHeaderHandler method handleMessage.

@Override
public boolean handleMessage(SOAPMessageContext context) {
    try {
        Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (outboundProperty.booleanValue()) {
            SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
            SOAPHeader header = envelope.getHeader();
            if (header == null)
                header = envelope.addHeader();
            if (wsParams.getAk() != null) {
                Map<String, String> headers = SignUtil.newParamsMap(null, wsParams.getApi(), wsParams.getVersion(), wsParams.getAk(), wsParams.getSk(), wsParams.isTimestamp(), wsParams.isNonce(), WSClientSDK.genExtHeader(wsParams.getFingerPrinter()));
                for (Entry<String, String> kv : headers.entrySet()) {
                    header.addHeaderElement(new QName(HEADER_NS, kv.getKey())).setTextContent(kv.getValue());
                    dumpHeaders(kv.getKey(), kv.getValue());
                }
            }
            if (wsParams.isMockRequest()) {
                header.addHeaderElement(new QName(HEADER_NS, HEADER_MOCK));
                dumpHeaders(HEADER_MOCK, "");
            }
        } else {
        // remove the unnecessary response headers
        // SOAPEnvelope envelope =
        // context.getMessage().getSOAPPart().getEnvelope();
        }
    } catch (Exception e) {
        throw new WSClientException("failed to add soap header", e);
    }
    return true;
}
Also used : QName(javax.xml.namespace.QName) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) WSClientException(com.alibaba.csb.ws.sdk.WSClientException) SOAPHeader(javax.xml.soap.SOAPHeader) WSClientException(com.alibaba.csb.ws.sdk.WSClientException)

Example 50 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project arctic-sea by 52North.

the class AbstractSoapEncoder method addAndRemoveSchemaLocationForSOAP.

/**
 * Check SOS response for xsi:schemaLocation, remove attribute and add attribute to SOAP message
 *
 * @param xmlObject           the document
 * @param soapResponseMessage SOAP response message
 *
 * @throws SOAPException If an error occurs
 */
private void addAndRemoveSchemaLocationForSOAP(XmlObject xmlObject, SOAPMessage soapResponseMessage) throws SOAPException {
    String value = null;
    Node nodeToRemove = null;
    NamedNodeMap attributeMap = xmlObject.getDomNode().getFirstChild().getAttributes();
    for (int i = 0; i < attributeMap.getLength(); i++) {
        Node node = attributeMap.item(i);
        if (node.getLocalName().equals(W3CConstants.AN_SCHEMA_LOCATION)) {
            value = node.getNodeValue();
            nodeToRemove = node;
        }
    }
    if (nodeToRemove != null) {
        attributeMap.removeNamedItem(nodeToRemove.getNodeName());
    }
    SOAPEnvelope envelope = soapResponseMessage.getSOAPPart().getEnvelope();
    StringBuilder string = new StringBuilder();
    string.append(envelope.getNamespaceURI());
    string.append(' ');
    string.append(envelope.getNamespaceURI());
    if (value != null && !value.isEmpty()) {
        string.append(' ');
        string.append(value);
    }
    envelope.addAttribute(N52XmlHelper.getSchemaLocationQNameWithPrefix(), string.toString());
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) SOAPEnvelope(javax.xml.soap.SOAPEnvelope)

Aggregations

SOAPEnvelope (javax.xml.soap.SOAPEnvelope)62 SOAPMessage (javax.xml.soap.SOAPMessage)37 SOAPException (javax.xml.soap.SOAPException)32 SOAPPart (javax.xml.soap.SOAPPart)26 SOAPBody (javax.xml.soap.SOAPBody)25 SOAPElement (javax.xml.soap.SOAPElement)22 SOAPHeader (javax.xml.soap.SOAPHeader)17 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)14 Name (javax.xml.soap.Name)13 Iterator (java.util.Iterator)12 QName (javax.xml.namespace.QName)12 WebServiceException (javax.xml.ws.WebServiceException)10 MessageFactory (javax.xml.soap.MessageFactory)8 ProtocolException (javax.xml.ws.ProtocolException)7 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)6 Document (org.w3c.dom.Document)6 Detail (javax.xml.soap.Detail)5 SOAPConnection (javax.xml.soap.SOAPConnection)5 SOAPFault (javax.xml.soap.SOAPFault)5