Search in sources :

Example 21 with Builder

use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.

the class ResponseMessageBuilderTest method testUnsubscriptionResponse.

public void testUnsubscriptionResponse() {
    String id = UIDGenerator.generateURNString();
    String addressUrl = "http://synapse.test.com/eventing/sunscriptions";
    SynapseSubscription sub = new SynapseSubscription();
    sub.setId(id);
    sub.setSubManUrl(addressUrl);
    String expected = "<wse:UnsubscribeResponse xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\"/>";
    try {
        MessageContext msgCtx = TestUtils.getAxis2MessageContext("<empty/>", null).getAxis2MessageContext();
        ResponseMessageBuilder builder = new ResponseMessageBuilder(msgCtx);
        SOAPEnvelope env = builder.genUnSubscribeResponse(sub);
        OMElement resultOm = env.getBody().getFirstElement();
        OMElement expectedOm = AXIOMUtil.stringToOM(expected);
        assertTrue(compare(expectedOm, resultOm));
    } catch (Exception e) {
        fail("Error while constructing the test message context: " + e.getMessage());
    }
}
Also used : SynapseSubscription(org.apache.synapse.eventing.SynapseSubscription) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 22 with Builder

use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.

the class ResponseMessageBuilderTest method testSubscriptionResponse.

public void testSubscriptionResponse() {
    String id = UIDGenerator.generateURNString();
    String addressUrl = "http://synapse.test.com/eventing/sunscriptions";
    SynapseSubscription sub = new SynapseSubscription();
    sub.setId(id);
    sub.setSubManUrl(addressUrl);
    String expected = "<wse:SubscribeResponse xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\">" + "<wse:SubscriptionManager>" + "<wsa:Address xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">" + addressUrl + "</wsa:Address>" + "<wsa:ReferenceParameters xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">" + "<wse:Identifier>" + id + "</wse:Identifier>" + "</wsa:ReferenceParameters>" + "</wse:SubscriptionManager>" + "</wse:SubscribeResponse>";
    try {
        MessageContext msgCtx = TestUtils.getAxis2MessageContext("<empty/>", null).getAxis2MessageContext();
        ResponseMessageBuilder builder = new ResponseMessageBuilder(msgCtx);
        SOAPEnvelope env = builder.genSubscriptionResponse(sub);
        OMElement resultOm = env.getBody().getFirstElement();
        OMElement expectedOm = AXIOMUtil.stringToOM(expected);
        assertTrue(compare(expectedOm, resultOm));
    } catch (Exception e) {
        fail("Error while constructing the test message context: " + e.getMessage());
    }
}
Also used : SynapseSubscription(org.apache.synapse.eventing.SynapseSubscription) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 23 with Builder

use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.

the class StockQuoteSampleClient method init.

private void init(String addUrl, String trpUrl, String prxUrl, String policyKey, long timeout) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Initializing sample Axis2 client");
    }
    configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientConfig.getClientRepo(), clientConfig.getAxis2Xml());
    serviceClient = new ServiceClient(configContext, null);
    Options options = new Options();
    if (addUrl != null && !"".equals(addUrl)) {
        serviceClient.engageModule("addressing");
        options.setTo(new EndpointReference(addUrl));
    }
    if (trpUrl != null && !"".equals(trpUrl)) {
        options.setProperty(Constants.Configuration.TRANSPORT_URL, trpUrl);
    }
    if (prxUrl != null && !"".equals(prxUrl)) {
        HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties();
        URL url = new URL(prxUrl);
        proxyProperties.setProxyName(url.getHost());
        proxyProperties.setProxyPort(url.getPort());
        proxyProperties.setUserName("");
        proxyProperties.setPassWord("");
        proxyProperties.setDomain("");
        options.setProperty(HTTPConstants.PROXY, proxyProperties);
    }
    if (policyKey != null && !"".equals(policyKey)) {
        log.info("Using WS-Security");
        serviceClient.engageModule("addressing");
        serviceClient.engageModule("rampart");
        OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(new FileInputStream(policyKey));
        Policy policy = PolicyEngine.getPolicy(builder.getDocumentElement());
        options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);
    }
    if (timeout > 0) {
        log.info("setting client timeout to: " + timeout);
        options.setTimeOutInMilliSeconds(timeout);
    }
    options.setProperty(HTTPConstants.HTTP_HEADERS, httpHeaders);
    serviceClient.setOptions(options);
}
Also used : Policy(org.apache.neethi.Policy) Options(org.apache.axis2.client.Options) HttpTransportProperties(org.apache.axis2.transport.http.HttpTransportProperties) ServiceClient(org.apache.axis2.client.ServiceClient) URL(java.net.URL) FileInputStream(java.io.FileInputStream) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 24 with Builder

use of org.apache.axis2.builder.Builder in project wso2-axis2-transports by wso2.

the class RabbitMQUtils method setSOAPEnvelope.

public static void setSOAPEnvelope(RabbitMQMessage message, MessageContext msgContext, String contentType) throws AxisFault {
    int index = contentType.indexOf(';');
    String type = index > 0 ? contentType.substring(0, index) : contentType;
    Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
    if (builder == null) {
        if (log.isDebugEnabled()) {
            log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
        }
        builder = new SOAPBuilder();
    }
    OMElement documentElement;
    String charSetEnc = null;
    try {
        if (contentType != null) {
            charSetEnc = new ContentType(contentType).getParameter("charset");
        }
    } catch (ParseException ex) {
        log.debug("Parse error", ex);
    }
    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
    documentElement = builder.processDocument(new ByteArrayInputStream(message.getBody()), contentType, msgContext);
    msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
Also used : ContentType(javax.mail.internet.ContentType) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) Builder(org.apache.axis2.builder.Builder) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) OMElement(org.apache.axiom.om.OMElement) LongString(com.rabbitmq.client.LongString) ParseException(javax.mail.internet.ParseException)

Example 25 with Builder

use of org.apache.axis2.builder.Builder in project carbon-business-process by wso2.

the class ServiceConfigurationUtil method configureService.

public static void configureService(AxisService axisService, EndpointConfiguration endpointConf, ConfigurationContext configCtx) throws AxisFault {
    if (endpointConf != null && endpointConf.isServiceDescriptionAvailable() && StringUtils.isNotEmpty(endpointConf.getServiceDescriptionLocation())) {
        OMElement documentEle = getServiceElement(endpointConf);
        if (documentEle != null) {
            if (log.isDebugEnabled()) {
                log.debug("Configuring service " + axisService.getName() + " using: " + endpointConf.getServiceDescriptionLocation());
            }
            ServiceBuilder builder = new ServiceBuilder(configCtx, axisService);
            Iterator itr = documentEle.getChildElements();
            while (itr.hasNext()) {
                OMElement serviceEle = (OMElement) itr.next();
                if (serviceEle.getLocalName().toLowerCase().equals("service")) {
                    if (serviceEle.getAttribute(new QName("name")) != null && serviceEle.getAttribute(new QName("name")).getAttributeValue().equals(axisService.getName())) {
                        builder.populateService(serviceEle);
                        // This is a hack to avoid security configurations get persisted when we configure using
                        // services.xml file or policy.xml file BPEL package. But this should be fix at the
                        // Carbon Persistence manager.
                        Parameter param = new Parameter(BusinessProcessConstants.CONFIGURED_USING_BPEL_PKG_CONFIG_FILES, "true");
                        axisService.addParameter(param);
                    }
                }
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) ServiceBuilder(org.apache.axis2.deployment.ServiceBuilder)

Aggregations

OMElement (org.apache.axiom.om.OMElement)24 MessageContext (org.apache.axis2.context.MessageContext)15 Builder (org.apache.axis2.builder.Builder)13 AxisFault (org.apache.axis2.AxisFault)11 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SOAPBuilder (org.apache.axis2.builder.SOAPBuilder)8 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 EndpointReference (org.apache.axis2.addressing.EndpointReference)5 ContentType (javax.mail.internet.ContentType)4 ParseException (javax.mail.internet.ParseException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Parameter (org.apache.axis2.description.Parameter)4 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)4 MessageFormatter (org.apache.axis2.transport.MessageFormatter)4 ManagedTestSuite (org.apache.axis2.transport.testkit.ManagedTestSuite)4 TransportTestSuiteBuilder (org.apache.axis2.transport.testkit.TransportTestSuiteBuilder)4 AxisAsyncTestClient (org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient)4