コード例 #1
0
  /** @testStrategy Tests conversions between SAAJ and OM SOAPEnvelopes */
  public void test1() throws Exception {

    // Bootstrap: Create an OM SOAPEnvelope from the sample text
    StringReader sr = new StringReader(sampleEnvelope);
    XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
    StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
    org.apache.axiom.soap.SOAPEnvelope omEnvelope = builder.getSOAPEnvelope();

    // Step 1: Get the SAAJConverter object from the Factory
    SAAJConverterFactory f =
        (SAAJConverterFactory) FactoryRegistry.getFactory(SAAJConverterFactory.class);
    SAAJConverter converter = f.getSAAJConverter();

    // Step 2: Convert the OM SOAPEnvelope to an SAAJ SOAPEnvelope
    SOAPEnvelope saajEnvelope = converter.toSAAJ(omEnvelope);

    // Step 2a: Simple assertion check to ensure correctness.
    String name = saajEnvelope.getBody().getFirstChild().getLocalName();
    assertTrue("a".equals(name));

    // Step 3: Convert the SAAJ SOAPEnvelope to an OM SOAPEnvelope
    omEnvelope = converter.toOM(saajEnvelope);

    // Step 3a: Simple assertion check to ensure correctness
    name = omEnvelope.getBody().getFirstElement().getLocalName();
    assertTrue("a".equals(name));

    // Step 4: Rinse and repeat
    saajEnvelope = converter.toSAAJ(omEnvelope);
    name = saajEnvelope.getBody().getFirstChild().getLocalName();
    assertTrue("a".equals(name));
    omEnvelope = converter.toOM(saajEnvelope);
    name = omEnvelope.getBody().getFirstElement().getLocalName();
    assertTrue("a".equals(name));
  }
コード例 #2
0
  /** @testStrategy: Create an OMElement, without using a builder. Verification of AXIS2-970 */
  public void test3() throws Exception {

    //    	 Step 1: Get the SAAJConverter object from the Factory
    SAAJConverterFactory f =
        (SAAJConverterFactory) FactoryRegistry.getFactory(SAAJConverterFactory.class);
    SAAJConverter converter = f.getSAAJConverter();

    // Stept 2: Create OM and parent SOAPElement
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace wrapNs = fac.createOMNamespace("namespace", "prefix");
    OMElement ome = fac.createOMElement("localname", wrapNs);
    SOAPFactory sf = SOAPFactory.newInstance();
    SOAPElement se = sf.createElement("name");

    // Step 3: Do the conversion
    converter.toSAAJ(ome, se, sf);
  }
コード例 #3
0
  /** @testStrategy Tests conversions between SAAJ and OM for normal element */
  public void test2() throws Exception {

    // Bootstrap: Create an OM SOAPEnvelope from the sample text.
    StringReader sr = new StringReader(sampleEnvelope);
    XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
    StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
    org.apache.axiom.soap.SOAPEnvelope omEnvelope = builder.getSOAPEnvelope();

    // Bootstrap: Get an OMElement from the body
    OMElement om = omEnvelope.getBody().getFirstElement();

    // Bootstrap: Get an SAAJ Body to hold the target SOAPElement
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage message = msgFactory.createMessage();
    SOAPBody body = message.getSOAPBody();

    // Step 1: Get the SAAJConverter object from the Factory
    SAAJConverterFactory f =
        (SAAJConverterFactory) FactoryRegistry.getFactory(SAAJConverterFactory.class);
    SAAJConverter converter = f.getSAAJConverter();

    // Step 2: Convert OM to SAAJ
    SOAPElement se = converter.toSAAJ(om, body);

    // Step 2a: Verify
    assertTrue(se instanceof SOAPBodyElement);
    assertTrue(se.getLocalName().equals("a"));

    // Step 3: Convert SAAJ to OM
    om = converter.toOM(se);

    // Step 3a: Verify
    assertTrue(om.getLocalName().equals("a"));

    // Step 4: Rinse and Repeat
    se = converter.toSAAJ(om, body);
    assertTrue(se instanceof SOAPBodyElement);
    assertTrue(se.getLocalName().equals("a"));
    om = converter.toOM(se);
    assertTrue(om.getLocalName().equals("a"));
  }