Search in sources :

Example 6 with MessageFactory

use of javax.xml.soap.MessageFactory in project keycloak by keycloak.

the class Soap method extractSoapMessage.

/**
 * <p>Returns Docuemnt based on the given <code>inputStream</code> which must contain a valid SOAP message.
 *
 * <p>The resulting string is based on the Body of the SOAP message, which should map to a valid SAML message.
 *
 * @param inputStream an InputStream consisting of a SOAPMessage
 * @return A document containing the body of the SOAP message
 */
public static Document extractSoapMessage(InputStream inputStream) {
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage(null, inputStream);
        return extractSoapMessage(soapMessage);
    } catch (Exception e) {
        throw new RuntimeException("Error creating fault message.", e);
    }
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException)

Example 7 with MessageFactory

use of javax.xml.soap.MessageFactory in project cerberus-source by cerberustesting.

the class SoapService method createSoapRequest.

@Override
public SOAPMessage createSoapRequest(String envelope, String method, List<AppServiceHeader> header, String token) throws SOAPException, IOException, SAXException, ParserConfigurationException {
    String unescapedEnvelope = StringEscapeUtils.unescapeXml(envelope);
    boolean is12SoapVersion = SOAP_1_2_NAMESPACE_PATTERN.matcher(unescapedEnvelope).matches();
    MimeHeaders headers = new MimeHeaders();
    for (AppServiceHeader appServiceHeader : header) {
        headers.addHeader(appServiceHeader.getKey(), appServiceHeader.getValue());
    }
    InputStream input = new ByteArrayInputStream(unescapedEnvelope.getBytes("UTF-8"));
    MessageFactory messageFactory = MessageFactory.newInstance(is12SoapVersion ? SOAPConstants.SOAP_1_2_PROTOCOL : SOAPConstants.SOAP_1_1_PROTOCOL);
    return messageFactory.createMessage(headers, input);
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IFactoryAppServiceHeader(org.cerberus.crud.factory.IFactoryAppServiceHeader) AppServiceHeader(org.cerberus.crud.entity.AppServiceHeader)

Example 8 with MessageFactory

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

the class JBWS1815TestCase method getRequestMessage.

private SOAPMessage getRequestMessage() throws SOAPException, IOException {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgString.getBytes()));
    return reqMsg;
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 9 with MessageFactory

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

the class WebMethodTestCase method testLegalMessageAccess.

@Test
@RunAsClient
public void testLegalMessageAccess() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    String reqEnv = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + " <env:Header/>" + " <env:Body>" + "  <ns1:echoString xmlns:ns1='" + targetNS + "'>" + "   <arg0>Hello</arg0>" + "  </ns1:echoString>" + " </env:Body>" + "</env:Envelope>";
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
    URL epURL = new URL(baseURL + "/TestService");
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    QName qname = new QName(targetNS, "echoStringResponse");
    SOAPElement soapElement = (SOAPElement) resMsg.getSOAPBody().getChildElements(qname).next();
    soapElement = (SOAPElement) soapElement.getChildElements(new QName("return")).next();
    assertEquals("Hello", soapElement.getValue());
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 10 with MessageFactory

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

the class WebMethodTestCase method testIllegalMessageAccess.

@Test
@RunAsClient
public void testIllegalMessageAccess() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    String reqEnv = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + " <env:Header/>" + " <env:Body>" + "  <ns1:noWebMethod xmlns:ns1='" + targetNS + "'>" + "   <String_1>Hello</String_1>" + "  </ns1:noWebMethod>" + " </env:Body>" + "</env:Envelope>";
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
    URL epURL = new URL(baseURL + "/TestService");
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    SOAPFault soapFault = resMsg.getSOAPBody().getFault();
    assertNotNull("Expected SOAPFault", soapFault);
    String faultString = soapFault.getFaultString();
    assertTrue(faultString, faultString.indexOf("noWebMethod") > 0);
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPFault(javax.xml.soap.SOAPFault) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

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