Esempio n. 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));
  }
Esempio n. 2
0
  /** Simulate creating a SOAP 1.2 message when the business object provided is just the payload. */
  public void testCreateSoap12FromPayload() throws Exception {
    // Create a SOAP 1.2 Message
    MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
    Message m = mf.create(Protocol.soap12);

    // Get the BlockFactory
    XMLStringBlockFactory f =
        (XMLStringBlockFactory) FactoryRegistry.getFactory(XMLStringBlockFactory.class);

    // Create a Block using the sample string as the content.  This simulates
    // what occurs on the outbound JAX-WS dispatch<String> client
    Block block = f.createFrom(sampleText, null, null);

    // Add the block to the message as normal body content.
    m.setBodyBlock(block);

    // Assuming no handlers are installed, the next thing that will happen
    // is a XMLStreamReader will be requested...to go to OM.   At this point the
    // block should be consumed.
    OMElement om = m.getAsOMElement();

    // The block should not be consumed yet...because the message has not been read
    assertTrue(!block.isConsumed());

    // To check that the output is correct, get the String contents of the
    // reader
    Reader2Writer r2w = new Reader2Writer(om.getXMLStreamReader());
    String newText = r2w.getAsString();
    TestLogger.logger.debug(newText);
    assertTrue(newText.contains(sampleText));
    assertTrue(newText.contains("soap"));
    assertTrue(newText.contains("Envelope"));
    assertTrue(newText.contains("Body"));

    assertTrue(m.getProtocol().equals(Protocol.soap12));

    SOAPEnvelope omSoapEnv = (SOAPEnvelope) m.getAsOMElement();
    OMNamespace ns = omSoapEnv.getNamespace();
    assertTrue(ns.getNamespaceURI().equals(SOAP12_NS_URI));

    // The block should be consumed at this point
    assertTrue(block.isConsumed());
  }
Esempio n. 3
0
  public void testGetMessageFromSoap12() throws Exception {
    // On inbound, there will already be an OM
    // which represents the message.  The following code simulates the input
    // OM
    StringReader sr = new StringReader(sampleSoap12Envelope);
    XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
    StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
    OMElement omElement = builder.getSOAPEnvelope();

    // The JAX-WS layer creates a Message from the OM
    MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
    Message m = mf.createFrom(omElement, null);

    // Make sure the right Protocol was set on the Message
    assertTrue(m.getProtocol().equals(Protocol.soap12));

    // Check the SOAPEnvelope to make sure we've got the right
    // protocol namespace there as well.
    SOAPEnvelope soapEnv = (SOAPEnvelope) m.getAsOMElement();
    OMNamespace ns = soapEnv.getNamespace();
    assertTrue(ns.getNamespaceURI().equals(SOAP12_NS_URI));

    // Assuming no handlers are installed, the next thing that will happen
    // is the proxy code will ask for the business object (String).
    XMLStringBlockFactory blockFactory =
        (XMLStringBlockFactory) FactoryRegistry.getFactory(XMLStringBlockFactory.class);
    Block block = blockFactory.createFrom(m.getAsOMElement(), null, null);
    Object bo = block.getBusinessObject(true);
    assertTrue(bo instanceof String);

    // The block should be consumed
    assertTrue(block.isConsumed());

    // Check the String for accuracy
    assertTrue(((String) bo).contains("<soapenv:Body><echo>test string</echo></soapenv:Body>"));
  }
Esempio n. 4
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);
  }
Esempio n. 5
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"));
  }
  /*
   * (non-Javadoc)
   * @see org.apache.axis2.jaxws.core.controller.InvocationController#invoke(org.apache.axis2.jaxws.core.InvocationContext)
   */
  public MessageContext doInvoke(MessageContext request) {

    // We need the qname of the operation being invoked to know which
    // AxisOperation the OperationClient should be based on.
    // Note that the OperationDesc is only set through use of the Proxy. Dispatch
    // clients do not use operations, so the operationDesc will be null.  In this
    // case an anonymous AxisService with anoymouns AxisOperations for the supported
    // MEPs will be created; and it is that anonymous operation name which needs to
    // be specified
    QName operationName = getOperationNameToUse(request, ServiceClient.ANON_OUT_IN_OP);

    // TODO: Will the ServiceClient stick around on the InvocationContext
    // or will we need some other mechanism of creating this?
    // Try to create an OperationClient from the passed in ServiceClient
    InvocationContext ic = request.getInvocationContext();
    ServiceClient svcClient = ic.getServiceClient();
    OperationClient opClient = createOperationClient(svcClient, operationName);

    initOperationClient(opClient, request);

    // Setup the client so that it knows whether the underlying call to
    // Axis2 knows whether or not to start a listening port for an
    // asynchronous response.
    Boolean useAsyncMep = (Boolean) request.getProperty(Constants.USE_ASYNC_MEP);
    if ((useAsyncMep != null && useAsyncMep.booleanValue())
        || opClient.getOptions().isUseSeparateListener()) {
      configureAsyncListener(opClient);
    } else {
      if (log.isDebugEnabled()) {
        log.debug(
            "Asynchronous message exchange not enabled.  The invocation will be synchronous.");
      }
    }

    org.apache.axis2.context.MessageContext axisRequestMsgCtx = request.getAxisMessageContext();
    org.apache.axis2.context.MessageContext axisResponseMsgCtx = null;

    MessageContext response = null;

    AxisFault faultexception =
        null; // don't let the keyword "fault" confuse you.  This is an exception class.
    try {
      execute(opClient, true, axisRequestMsgCtx);
    } catch (AxisFault af) {
      // If an AxisFault was thrown, we need to cleanup the original OperationContext.
      // Failure to do so results in a memory leak.
      opClient.getOperationContext().cleanup();
      // save the fault in case it didn't come from the endpoint, and thus
      // there would be no message on the MessageContext
      faultexception = af;
      if (log.isDebugEnabled()) {
        log.debug(
            axisRequestMsgCtx.getLogIDString()
                + " AxisFault received from client: "
                + af.getMessage());
      }
    }

    try {
      // Collect the response MessageContext and envelope
      axisResponseMsgCtx = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
      response = new MessageContext(axisResponseMsgCtx);
      response.setMEPContext(request.getMEPContext());

      // If the Message object is still null, then it's possible that a
      // local AxisFault was thrown and we need to save it for later throwing
      // We do not want to create a message and go through the whole handler or
      // XMLFault processing because it's unnecessary.
      //
      // Same is true if we get a valid non-fault server response but some jaxws
      // client processing (a handler, perhaps) throws an exception.
      //
      // If the response message itself is a fault message, let it pass through.
      if ((faultexception != null)
          && ((response.getMessage() == null) || (!response.getMessage().isFault()))) {
        MessageFactory factory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
        Message message = factory.create(request.getMessage().getProtocol());
        response.setLocalException(faultexception);
        response.setMessage(message);
      }

      // This assumes that we are on the ultimate execution thread
      ThreadContextMigratorUtil.performMigrationToThread(
          Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID, axisResponseMsgCtx);
    } catch (Exception e) {
      throw ExceptionFactory.makeWebServiceException(e);
    }

    return response;
  }