Example usage for javax.xml.soap SOAPFactory newInstance

List of usage examples for javax.xml.soap SOAPFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.soap SOAPFactory newInstance.

Prototype

public static SOAPFactory newInstance(String protocol) throws SOAPException 

Source Link

Document

Creates a new SOAPFactory object that is an instance of the specified implementation, this method uses the SAAJMetaFactory to locate the implementation class and create the SOAPFactory instance.

Usage

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test/* ww  w.ja  v  a  2  s  .c  o m*/
public void testCreateElement() {
    try {
        //SOAPFactory sf = SOAPFactory.newInstance();
        SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        if (sf == null) {
            fail("createElementTest4() could not create SOAPFactory object");
        }
        //Create QName object with localName=MyName1,prefix=MyPrefix1, uri=MyUri1
        QName name = new QName("MyUri1", "MyName1", "MyPrefix1");
        SOAPElement se = sf.createElement(name);
        assertNotNull(se);
        name = se.getElementQName();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
        String uri = name.getNamespaceURI();
        if (localName == null) {
            fail("localName is null (expected MyName1)");
        } else if (!localName.equals("MyName1")) {
            fail("localName is wrong (expected MyName1)");
        } else if (prefix == null) {
            fail("prefix is null (expected MyPrefix1)");
        } else if (!prefix.equals("MyPrefix1")) {
            fail("prefix is wrong (expected MyPrefix1)");
        } else if (uri == null) {
            fail("uri is null (expected MyUri1)");
        } else if (!uri.equals("MyUri1")) {
            fail("uri is wrong (expected MyUri1)");
        }
    } catch (Exception e) {
        fail();
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test/*from   ww  w.j  ava2s.co  m*/
public void testCreateFault() {
    try {
        SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        //SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault sf = factory.createFault("This is the fault reason.", SOAPConstants.SOAP_RECEIVER_FAULT);
        assertNotNull(sf);
        assertTrue(sf instanceof SOAPFault);
        QName fc = sf.getFaultCodeAsQName();
        //Expect FaultCode="+SOAPConstants.SOAP_RECEIVER_FAULT
        Iterator i = sf.getFaultReasonTexts();
        if (i == null) {
            log.info("Call to getFaultReasonTexts() returned null iterator");
        }
        String reason = "";
        while (i.hasNext()) {
            reason += (String) i.next();
        }
        assertNotNull(reason);
        assertTrue(reason.indexOf("This is the fault reason.") > -1);
        assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
    } catch (SOAPException e) {
        fail("Caught unexpected SOAPException");
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

/** for soap 1.1 */
@Validated/*from   www .  java2  s. com*/
@Test
public void testSOAPFaultException1() {
    try {
        SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPFault fault = factory.createFault("This is the fault reason.",
                new QName("http://MyNamespaceURI.org/", "My Fault Code"));
    } catch (UnsupportedOperationException e) {
        //Caught expected UnsupportedOperationException
    } catch (SOAPException e) {
        //Caught expected SOAPException
    } catch (IllegalArgumentException e) {
        //Caught expected IllegalArgumentException
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

/** for soap 1.2 */
@Validated// w  w w.  ja va2s . com
@Test
public void testSOAPFaultException2() {
    try {
        SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPFault sf = factory.createFault("This is the fault reason.",
                new QName("http://MyNamespaceURI.org/", "My Fault Code"));
        fail("Did not throw expected SOAPException");
    } catch (UnsupportedOperationException e) {
        //Caught expected UnsupportedOperationException
    } catch (SOAPException e) {
        //Caught expected SOAPException
    } catch (IllegalArgumentException e) {
        //Caught expected IllegalArgumentException
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}