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);
}
}
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);
}
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;
}
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());
}
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);
}
Aggregations