Search in sources :

Example 11 with SOAPModelBuilder

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);
}
Also used : CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) BlobOMDataSourceCustomBuilder(org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 12 with SOAPModelBuilder

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 13 with SOAPModelBuilder

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));
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DOMSource(javax.xml.transform.dom.DOMSource) Schema(javax.xml.validation.Schema) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMMetaFactory(org.apache.axiom.om.OMMetaFactory) Validator(javax.xml.validation.Validator)

Example 14 with SOAPModelBuilder

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();
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 15 with SOAPModelBuilder

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;
}
Also used : SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Aggregations

SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)18 OMElement (org.apache.axiom.om.OMElement)11 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)11 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringReader (java.io.StringReader)4 CustomBuilderSupport (org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)3 BlobOMDataSourceCustomBuilder (org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder)3 SOAPFactory (org.apache.axiom.soap.SOAPFactory)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 Schema (javax.xml.validation.Schema)2 SchemaFactory (javax.xml.validation.SchemaFactory)2 Validator (javax.xml.validation.Validator)2 Attachments (org.apache.axiom.attachments.Attachments)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 OMText (org.apache.axiom.om.OMText)2 CustomBuilder (org.apache.axiom.om.ds.custombuilder.CustomBuilder)2