Search in sources :

Example 81 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestName3Unqualified method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory f = metaFactory.getOMFactory();
    // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
    OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
    OMNamespace ns = f.createOMNamespace("http://DUMMYNS", "DUMMYPREFIX");
    OMElement element = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT3.getContent()), "DUMMYNAME", ns);
    OMElement root = f.createOMElement("root", rootNS);
    root.addChild(element);
    // Test getting the namespace, localpart and prefix.  This should used not result in expansion
    assertTrue(element.getLocalName().equals("DUMMYNAME"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
    assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
    // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
    StringWriter writer = new StringWriter();
    try {
        root.serialize(writer);
    } catch (Exception e) {
        // are consistent with the original setting.
        return;
    }
    String result = writer.toString();
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals(""));
    assertTrue(element.getNamespace().getPrefix().equals(""));
    assertTrue(result.indexOf("DUMMY") < // Make sure that the serialized string does not contain the DUMMY values
    0);
    assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
    // Serialize again
    writer = new StringWriter();
    root.serialize(writer);
    result = writer.toString();
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
    assertTrue(element.getNamespace().getPrefix().equals(""));
    assertTrue(result.indexOf("DUMMY") < // Make sure that the serialized string does not contain the DUMMY values
    0);
    assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) StringWriter(java.io.StringWriter) OMElement(org.apache.axiom.om.OMElement)

Example 82 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project wso2-axis2-transports by wso2.

the class TCPEchoRawXMLTest method createPayload.

private OMElement createPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement method = fac.createOMElement("echoOMElement", omNs);
    OMElement value = fac.createOMElement("myValue", omNs);
    value.addChild(fac.createOMText(value, "Isaac Asimov, The Foundation Trilogy"));
    method.addChild(value);
    return method;
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 83 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project wso2-axis2-transports by wso2.

the class TCPEchoRawXMLTest method testEchoXMLSyncMC.

public void testEchoXMLSyncMC() throws Exception {
    AxisOperation opdesc = new OutInAxisOperation(new QName("echoOMElement"));
    Options options = new Options();
    options.setTo(targetEPR);
    options.setAction(operationName.getLocalPart());
    options.setTransportInProtocol(Constants.TRANSPORT_TCP);
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement method = fac.createOMElement("echoOMElement", omNs);
    OMElement value = fac.createOMElement("myValue", omNs);
    value.setText("Isaac Asimov, The Foundation Trilogy");
    method.addChild(value);
    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    envelope.getBody().addChild(method);
    MessageContext requestContext = new MessageContext();
    requestContext.setConfigurationContext(configContext);
    requestContext.setAxisService(clientService);
    requestContext.setAxisOperation(opdesc);
    requestContext.setEnvelope(envelope);
    ServiceClient sender = new ServiceClient(configContext, clientService);
    sender.setOptions(options);
    OperationClient opClient = sender.createClient(new QName("echoOMElement"));
    opClient.addMessageContext(requestContext);
    opClient.setOptions(options);
    opClient.execute(true);
    MessageContext response = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    SOAPEnvelope env = response.getEnvelope();
    assertNotNull(env);
    env.getBody().serialize(StAXUtils.createXMLStreamWriter(System.out));
    sender.cleanup();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) Options(org.apache.axis2.client.Options) OperationClient(org.apache.axis2.client.OperationClient) OMNamespace(org.apache.axiom.om.OMNamespace) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) QName(javax.xml.namespace.QName) ServiceClient(org.apache.axis2.client.ServiceClient) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MessageContext(org.apache.axis2.context.MessageContext) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 84 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project wso2-axis2-transports by wso2.

the class AbstractTransportTest method createPayload.

/**
 * Create the payload for an echoOMElement request
 * @return
 */
protected OMElement createPayload(String textValue) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/axis2/services/EchoXMLService", "my");
    OMElement method = fac.createOMElement("echoOMElement", omNs);
    OMElement value = fac.createOMElement("myValue", omNs);
    value.addChild(fac.createOMText(value, textValue));
    method.addChild(value);
    return method;
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 85 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project wso2-axis2-transports by wso2.

the class JMSUtils method convertJMSMapToXML.

/**
 * @param message JMSMap message
 * @return XML representation of JMS Map message
 */
public static OMElement convertJMSMapToXML(MapMessage message) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace jmsMapNS = OMAbstractFactory.getOMFactory().createOMNamespace(JMSConstants.JMS_MAP_NS, "");
    OMElement jmsMap = fac.createOMElement(JMSConstants.JMS_MAP_ELEMENT_NAME, jmsMapNS);
    try {
        Enumeration names = message.getMapNames();
        while (names.hasMoreElements()) {
            String nextName = names.nextElement().toString();
            String nextVal = message.getString(nextName);
            OMElement next = fac.createOMElement(nextName.replace(" ", ""), jmsMapNS);
            next.setText(nextVal);
            jmsMap.addChild(next);
        }
    } catch (JMSException e) {
        handleException("Unable to process JMSMap message", e);
    }
    return jmsMap;
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) Enumeration(java.util.Enumeration) OMElement(org.apache.axiom.om.OMElement) JMSException(javax.jms.JMSException)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)171 OMElement (org.apache.axiom.om.OMElement)108 OMFactory (org.apache.axiom.om.OMFactory)101 QName (javax.xml.namespace.QName)34 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)22 OMAttribute (org.apache.axiom.om.OMAttribute)18 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)16 StringWriter (java.io.StringWriter)15 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)13 SOAPHeader (org.apache.axiom.soap.SOAPHeader)12 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMText (org.apache.axiom.om.OMText)7 Iterator (java.util.Iterator)6 SOAPBody (org.apache.axiom.soap.SOAPBody)6 StringReader (java.io.StringReader)5 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)5 HashSet (java.util.HashSet)4 OMDataSource (org.apache.axiom.om.OMDataSource)4 OMNode (org.apache.axiom.om.OMNode)4