use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class TestRegisterCustomBuilderForPayloadAfterSOAPFaultCheck method runTest.
@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
SOAPModelBuilder builder = (SOAPModelBuilder) envelope.getBuilder();
// Do a fault check. This is normally done in the engine (Axiom) and should
// not cause inteference with the custom builder processing
envelope.getBody().hasFault();
// Do the registration here...this simulates when it could occure in the engine
// (After the fault check and during phase processing...probably dispatch phase)
((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new BlobOMDataSourceCustomBuilder(MemoryBlob.FACTORY, "utf-8"));
OMElement bodyElement = envelope.getBody().getFirstElement();
assertTrue(bodyElement instanceof OMSourcedElement);
}
use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class ConvertLLOMToDOOMTest method testConvert.
public void testConvert() throws Exception {
String origXML = "<?xml version='1.0' encoding='UTF-8'?>\n" + " <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">\n" + " <soapenv:Header>\n" + " <wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" soapenv:mustUnderstand=\"1\">\n" + " <ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" Id=\"Signature-6426875\">\n" + " <ds:SignedInfo>\n" + " <ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" />\n" + " <ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" />\n" + " <ds:Reference URI=\"#id-3083604\">\n" + " <ds:Transforms>\n" + " <ds:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" />\n" + " </ds:Transforms>\n" + " <ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" />\n" + " <ds:DigestValue>lDeZJk0/r6u4tOOhOKbN0IEvwi0=</ds:DigestValue>\n" + " </ds:Reference>\n" + " </ds:SignedInfo>\n" + " <ds:SignatureValue>KhUeWMoUxUFe5jeTlqLdIEIG2Z7Q2q2mh9HT3IAYwbCev+FzXcuLSiPSsb7/+PSDM2SD0gl9tMp+dHjfPxmq7WiduH9mbnP6gkrxxu0T5rR916WsboshJGJKiPlj71bwpMsrrZohx4evHPdQ2SZHthlNb6jZyjq+LS7qFydppHk=</ds:SignatureValue>\n" + " <ds:KeyInfo Id=\"KeyId-2529687\">\n" + " <wsse:SecurityTokenReference xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"STRId-31966667\">\n" + " <ds:X509Data>\n" + " <ds:X509IssuerSerial>\n" + " <ds:X509IssuerName>CN=OASIS Interop Test CA,O=OASIS</ds:X509IssuerName>\n" + " <ds:X509SerialNumber>68652640310044618358965661752471103641</ds:X509SerialNumber>\n" + " </ds:X509IssuerSerial>\n" + " </ds:X509Data>\n" + " </wsse:SecurityTokenReference>\n" + " </ds:KeyInfo>\n" + " </ds:Signature>\n" + " <wsu:Timestamp xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"Timestamp-13986615\">\n" + " <wsu:Created>2006-03-31T15:34:38.699Z</wsu:Created>\n" + " <wsu:Expires>2006-03-31T15:39:38.699Z</wsu:Expires>\n" + " </wsu:Timestamp>\n" + " </wsse:Security>\n" + " <wsa:To xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">http://localhost:9080/axis2/services/Service</wsa:To>\n" + " <wsa:ReplyTo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">\n" + " <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>\n" + " </wsa:ReplyTo>\n" + " <wsa:MessageID xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">urn:uuid:049875A6E153FCAAF011438192785862</wsa:MessageID>\n" + " <wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT</wsa:Action>\n" + " </soapenv:Header>\n" + " <soapenv:Body xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"id-3083604\">\n" + " <RequestSecurityToken xmlns=\"http://schemas.xmlsoap.org/ws/2005/02/trust\" Context=\"http://get.optional.attrs.working\">\n" + " <TokenType>http://schemas.xmlsoap.org/ws/2005/02/sc/sct</TokenType>\n" + " <RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</RequestType>\n" + " </RequestSecurityToken>\n" + " </soapenv:Body>\n" + " </soapenv:Envelope>";
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(new ByteArrayInputStream(origXML.getBytes()), null);
SOAPEnvelope env = builder.getSOAPEnvelope();
env.build();
SOAPModelBuilder doomBuilder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM), env.getXMLStreamReader());
SOAPEnvelope doomEnv = doomBuilder.getSOAPEnvelope();
doomEnv.build();
OMElement payload = doomEnv.getBody().getFirstElement();
OMXMLParserWrapper llomBuilder = OMXMLBuilderFactory.createStAXOMBuilder(payload.getXMLStreamReaderWithoutCaching());
OMElement llomPayload = llomBuilder.getDocumentElement();
llomPayload.build();
String xml = llomPayload.toString();
assertTrue("Conversion failed", xml.indexOf("</RequestSecurityToken>") != -1);
}
use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class ValidateSample method validateUsingDOM.
// START SNIPPET: dom
public void validateUsingDOM(InputStream in, URL schemaUrl) throws Exception {
OMMetaFactory mf = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM);
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(mf, in, "UTF-8");
SOAPEnvelope envelope = builder.getSOAPEnvelope();
OMElement bodyContent = envelope.getBody().getFirstElement();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaUrl);
Validator validator = schema.newValidator();
validator.validate(new DOMSource((Element) bodyContent));
}
use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class TestGetTextWithCDATA method runTest.
@Override
protected void runTest() throws Throwable {
String soap11Fault = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<SOAP-ENV:Body>" + "<SOAP-ENV:Fault>" + "<faultcode>SOAP-ENV:Server</faultcode>" + "<faultstring xml:lang=\"en\"><![CDATA[handleMessage throws SOAPFaultException for ThrowsSOAPFaultToClientHandlersTest]]></faultstring>" + "<detail>" + "<somefaultentry/>" + "</detail>" + "<faultactor>faultActor</faultactor>" + "</SOAP-ENV:Fault>" + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>";
XMLStreamReader soap11Parser = StAXUtils.createXMLStreamReader(TEST_PARSER_CONFIGURATION, new StringReader(soap11Fault));
SOAPModelBuilder soap11Builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(metaFactory, soap11Parser);
OMElement element = soap11Builder.getDocumentElement();
element.build();
assertTrue(element instanceof SOAPEnvelope);
SOAPEnvelope se = (SOAPEnvelope) element;
SOAPFault fault = se.getBody().getFault();
SOAPFaultReason reason = fault.getReason();
assertTrue(reason.getText().equals("handleMessage throws SOAPFaultException for ThrowsSOAPFaultToClientHandlersTest"));
soap11Parser.close();
}
use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class OMXMLBuilderFactory method createSOAPModelBuilder.
/**
* Create an MTOM aware model builder from the provided {@link MultipartBody} object using a
* particular Axiom implementation. The method will determine the SOAP version based on the
* content type information from the {@link MultipartBody} object. It will configure the
* underlying parser as specified by {@link StAXParserConfiguration#SOAP}.
*
* @param metaFactory
* the meta factory for the Axiom implementation to use
* @param message
* the MIME message
* @return the builder
* @throws OMException
* if an error occurs while processing the content type information from the
* {@link MultipartBody} object
*/
public static SOAPModelBuilder createSOAPModelBuilder(OMMetaFactory metaFactory, MultipartBody message) {
String type = message.getRootPart().getContentType().getParameter("type");
SOAPFactory soapFactory;
if ("text/xml".equalsIgnoreCase(type)) {
soapFactory = metaFactory.getSOAP11Factory();
} else if ("application/soap+xml".equalsIgnoreCase(type)) {
soapFactory = metaFactory.getSOAP12Factory();
} else {
throw new OMException("Unable to determine SOAP version");
}
SOAPModelBuilder builder = ((OMMetaFactorySPI) metaFactory).createSOAPModelBuilder(message);
if (builder.getSOAPMessage().getOMFactory() != soapFactory) {
throw new SOAPProcessingException("Invalid SOAP namespace URI. " + "Expected " + soapFactory.getSoapVersionURI(), SOAP12Constants.FAULT_CODE_SENDER);
}
return builder;
}
Aggregations