Search in sources :

Example 1 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class MTOMSample method retrieveContent.

// START SNIPPET: retrieveContent
public void retrieveContent(URL serviceURL, String id, OutputStream result) throws Exception {
    // Build the SOAP request
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope request = soapFactory.getDefaultEnvelope();
    OMElement retrieveContent = soapFactory.createOMElement(new QName("urn:test", "retrieveContent"), request.getBody());
    OMElement fileId = soapFactory.createOMElement(new QName("fileId"), retrieveContent);
    fileId.setText(id);
    // Use the java.net.URL API to connect to the service
    URLConnection connection = serviceURL.openConnection();
    connection.setDoOutput(true);
    connection.addRequestProperty("Content-Type", "text/xml; charset=UTF-8");
    OutputStream out = connection.getOutputStream();
    // Send the request
    OMOutputFormat format = new OMOutputFormat();
    format.setCharSetEncoding("UTF-8");
    request.serialize(out, format);
    out.close();
    // Get the SOAP response
    InputStream in = connection.getInputStream();
    MultipartBody multipartBody = MultipartBody.builder().setInputStream(in).setContentType(connection.getContentType()).build();
    SOAPEnvelope response = OMXMLBuilderFactory.createSOAPModelBuilder(multipartBody).getSOAPEnvelope();
    OMElement retrieveContentResponse = response.getBody().getFirstElement();
    OMElement content = retrieveContentResponse.getFirstElement();
    // Extract the DataHandler representing the optimized binary data
    DataHandler dh = ((OMText) content.getFirstOMChild()).getDataHandler();
    // Stream the content of the MIME part
    InputStream contentStream = ((PartDataHandler) dh).getPart().getInputStream(false);
    // Write the content to the result stream
    IOUtils.copy(contentStream, result);
    contentStream.close();
    in.close();
}
Also used : QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) MultipartBody(org.apache.axiom.mime.MultipartBody) OutputStream(java.io.OutputStream) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) DataHandler(javax.activation.DataHandler) PartDataHandler(org.apache.axiom.mime.PartDataHandler) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) SOAPFactory(org.apache.axiom.soap.SOAPFactory) URLConnection(java.net.URLConnection)

Example 2 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class ValidateSample method validate.

// START SNIPPET: sax
public void validate(InputStream in, URL schemaUrl) throws Exception {
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(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(bodyContent.getSAXSource(true));
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Validator(javax.xml.validation.Validator)

Example 3 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class CharacterEncoding2Test method testISO99591.

public void testISO99591() throws Exception {
    ByteArrayInputStream byteInStr = new ByteArrayInputStream(xml.getBytes("iso-8859-1"));
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(byteInStr, null);
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    envelope.build();
    assertEquals("iso-8859-1", builder.getDocument().getXMLStreamReader().getCharacterEncodingScheme());
    ByteArrayOutputStream byteOutStr = new ByteArrayOutputStream();
    OMOutputFormat outputFormat = new OMOutputFormat();
    outputFormat.setCharSetEncoding("iso-8859-1");
    envelope.serialize(byteOutStr, outputFormat);
    assertAbout(xml()).that(new InputStreamReader(new ByteArrayInputStream(byteOutStr.toByteArray()), "iso-8859-1")).hasSameContentAs(new InputStreamReader(new ByteArrayInputStream(xml.getBytes("iso-8859-1")), "iso-8859-1"));
    builder.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 4 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class CharacterEncodingTest method runTest.

public void runTest(String value, String expected) throws XMLStreamException, FactoryConfigurationError, IOException {
    SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    String ns = "http://testuri.org";
    OMNamespace namespace = factory.createOMNamespace(ns, "tst");
    String ln = "Child";
    OMElement bodyChild = factory.createOMElement(ln, namespace);
    bodyChild.addChild(factory.createOMText(value));
    envelope.getBody().addChild(bodyChild);
    ByteArrayOutputStream byteOutStr = new ByteArrayOutputStream();
    OMOutputFormat outputFormat = new OMOutputFormat();
    outputFormat.setCharSetEncoding(UTF_16);
    envelope.serialize(byteOutStr, outputFormat);
    ByteArrayInputStream byteInStr = new ByteArrayInputStream(byteOutStr.toByteArray());
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(byteInStr, UTF_16);
    SOAPEnvelope resultEnv = builder.getSOAPEnvelope();
    OMElement bodyChildResult = resultEnv.getBody().getFirstElement();
    assertNotNull("No child in body element", bodyChildResult);
    String result = bodyChildResult.getText();
    assertNotNull("No value for testParam param", result);
    assertEquals("Expected result not received.", expected, result);
    builder.close();
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) ByteArrayInputStream(java.io.ByteArrayInputStream) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 5 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class ElementSerializerTest method testElementSerilizationSOAPBodyCacheOff.

public void testElementSerilizationSOAPBodyCacheOff() throws Exception {
    SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
    OMNode node = env.getBody();
    node.serialize(writer);
}
Also used : OMNode(org.apache.axiom.om.OMNode) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Aggregations

SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)86 OMElement (org.apache.axiom.om.OMElement)28 SOAPBody (org.apache.axiom.soap.SOAPBody)23 OMNamespace (org.apache.axiom.om.OMNamespace)20 SOAPHeader (org.apache.axiom.soap.SOAPHeader)20 SOAPFault (org.apache.axiom.soap.SOAPFault)14 QName (javax.xml.namespace.QName)12 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)12 OMNode (org.apache.axiom.om.OMNode)11 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)11 SOAPFactory (org.apache.axiom.soap.SOAPFactory)10 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)8 StringReader (java.io.StringReader)7 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataHandler (javax.activation.DataHandler)6 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 MultipartBody (org.apache.axiom.mime.MultipartBody)5 SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)5