Search in sources :

Example 91 with URL

use of org.apache.axis2.util.URL in project wso2-synapse by wso2.

the class ProxyServiceTest method testBuildAxisServiceWithMalformedWsdlUri.

/**
 * Tests building a proxy service with a malformed URI specified as the published wsdl url.
 *
 * @throws Exception if an error occurs due to the malformed url
 */
public void testBuildAxisServiceWithMalformedWsdlUri() throws Exception {
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    ProxyService proxyService = new ProxyService("testBuildAxisServiceWithInvalidWsdlUriProxy");
    // note incorrect protocol, 'files'
    URI wsdlUri = new URI("files:/home/sasikala/Documents/ei/git/wso2-synapse/modules/core/target/test-classes" + "/org/apache/synapse/core/axis2/SimpleStockService.wsdl");
    proxyService.setWsdlURI(wsdlUri);
    try {
        proxyService.buildAxisService(synCfg, axisCfg);
        Assert.fail("Axis service should not be built with malformed publish wsdl URI: " + wsdlUri.toString());
    } catch (SynapseException e) {
        Assert.assertEquals("Unexpected exception thrown: " + e, "Malformed URI for wsdl", e.getMessage());
    }
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) SynapseException(org.apache.synapse.SynapseException) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URI(java.net.URI)

Example 92 with URL

use of org.apache.axis2.util.URL in project wso2-synapse by wso2.

the class ProxyServiceTest method testBuildAxisServiceWithFaultyPublishWsdlEndpoint.

/**
 * Tests building a proxy service with a faulty wsdl endpoint specified as the wsdl endpoint.
 *
 * @throws Exception if an error occurs when converting the URI string to a URI
 */
public void testBuildAxisServiceWithFaultyPublishWsdlEndpoint() throws Exception {
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxy");
    proxyService.setPublishWSDLEndpoint("wsdlEndPoint");
    try {
        proxyService.buildAxisService(synCfg, axisCfg);
        Assert.fail("Axis service built with null wsdl endpoint should throw fault");
    } catch (SynapseException e) {
        Assert.assertEquals("Unexpected exception thrown: " + e, "Unable to resolve WSDL url. wsdlEndPoint is null", e.getMessage());
    }
    AddressEndpoint wsdlEndpoint = new AddressEndpoint();
    EndpointDefinition endpointDefinition = new EndpointDefinition();
    endpointDefinition.setAddress(getClass().getResource("SimpleStockService.wsdl").toURI().toString());
    wsdlEndpoint.setDefinition(endpointDefinition);
    synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint);
    try {
        proxyService.buildAxisService(synCfg, axisCfg);
        Assert.fail("Axis service built with faulty wsdl endpoint should be null");
    } catch (SynapseException e) {
        Assert.assertEquals("Unexpected exception thrown: " + e, "Error building service from WSDL", e.getMessage());
    }
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) SynapseException(org.apache.synapse.SynapseException) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 93 with URL

use of org.apache.axis2.util.URL in project wso2-synapse by wso2.

the class ProxyServiceTest method testBuildAxisServiceWithUnreachableWsdlUriWithPublishWSDLSafeModeDisabled.

/**
 * Tests building a proxy service with an unreachable URI specified as the published wsdl url with the
 * 'enablePublishWSDLSafeMode' set to false.
 *
 * @throws Exception if an error occurs when converting the URI string to a URI
 */
public void testBuildAxisServiceWithUnreachableWsdlUriWithPublishWSDLSafeModeDisabled() throws Exception {
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    ProxyService proxyService = new ProxyService("unreachableWsdlUriWithPublishWSDLSafeModeDisabledProxy");
    proxyService.addParameter("enablePublishWSDLSafeMode", false);
    URI wsdlUri = new URI("http://invalid-host/SimpleStockService.wsdl");
    proxyService.setWsdlURI(wsdlUri);
    try {
        proxyService.buildAxisService(synCfg, axisCfg);
        Assert.fail("Axis service should not be built with malformed publish wsdl URI: " + wsdlUri);
    } catch (SynapseException e) {
        Assert.assertEquals("Unexpected exception thrown: " + e, "Error reading from wsdl URI", e.getMessage());
    }
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) SynapseException(org.apache.synapse.SynapseException) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URI(java.net.URI)

Example 94 with URL

use of org.apache.axis2.util.URL in project wso2-synapse by wso2.

the class ProxyServiceTest method testBuildAxisServiceWithUnreachableWsdlUriWithPublishWSDLSafeModeEnabled.

/**
 * Tests building a proxy service with an unreachable URI specified as the published wsdl url with the
 * 'enablePublishWSDLSafeMode' set to true.
 *
 * @throws URISyntaxException if an error occurs when converting the URI string to a URI
 */
public void testBuildAxisServiceWithUnreachableWsdlUriWithPublishWSDLSafeModeEnabled() throws Exception {
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    ProxyService proxyService = new ProxyService("unreachableWsdlUriWithPublishWSDLSafeModeEnabledProxy");
    proxyService.addParameter("enablePublishWSDLSafeMode", true);
    URI wsdlUri = new URI("http://invalid-host/SimpleStockService.wsdl");
    proxyService.setWsdlURI(wsdlUri);
    Assert.assertNull("Axis service returned should be null", proxyService.buildAxisService(synCfg, axisCfg));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URI(java.net.URI)

Example 95 with URL

use of org.apache.axis2.util.URL in project wso2-synapse by wso2.

the class EventSubscriber method executeClient.

public static void executeClient() throws Exception {
    Options options = new Options();
    ServiceClient serviceClient;
    ConfigurationContext configContext = null;
    String addUrl = getProperty("addurl", "http://localhost:8280/services/SampleEventSource");
    String trpUrl = getProperty("trpurl", null);
    String prxUrl = getProperty("prxurl", null);
    String repo = getProperty("repository", "client_repo");
    String topic = getProperty("topic", "synapse/event/test");
    String address = getProperty("address", "http://localhost:9000/services/SimpleStockQuoteService");
    String mode = getProperty("mode", "subscribe");
    String identifier = getProperty("identifier", "90000");
    // Format: 2020-12-31T21:07:00.000-08:00
    String expires = getProperty("expires", "*");
    if (repo != null && !"null".equals(repo)) {
        configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repo, repo + File.separator + "conf" + File.separator + "axis2.xml");
        serviceClient = new ServiceClient(configContext, null);
    } else {
        serviceClient = new ServiceClient();
    }
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement message = factory.createOMElement("message", null);
    OMNamespace nsxmlins = factory.createOMNamespace("http://www.w3.org/2001/XMLSchema", "xmlns");
    OMNamespace nss11 = factory.createOMNamespace("http://schemas.xmlsoap.org/soap/envelope", "s11");
    OMNamespace nswsa = factory.createOMNamespace("http://schemas.xmlsoap.org/ws/2004/08/addressing", "wsa");
    OMNamespace nswse = factory.createOMNamespace("http://schemas.xmlsoap.org/ws/2004/08/eventing", "wse");
    if (mode.equals("subscribe")) {
        OMElement subscribeOm = factory.createOMElement("Subscribe", nswse);
        OMElement deliveryOm = factory.createOMElement("Delivery", nswse);
        deliveryOm.addAttribute(factory.createOMAttribute("Mode", null, "http://schemas.xmlsoap.org/ws/2004/08/eventing/DeliveryModes/Push"));
        OMElement notifyToOm = factory.createOMElement("NotifyTo", nswse);
        OMElement addressOm = factory.createOMElement("Address", nswsa);
        factory.createOMText(addressOm, address);
        OMElement expiresOm = factory.createOMElement("Expires", nswse);
        factory.createOMText(expiresOm, expires);
        OMElement filterOm = factory.createOMElement("Filter", nswse);
        filterOm.addAttribute(factory.createOMAttribute("Dialect", null, "http://synapse.apache.org/eventing/dialect/topicFilter"));
        factory.createOMText(filterOm, topic);
        notifyToOm.addChild(addressOm);
        deliveryOm.addChild(notifyToOm);
        subscribeOm.addChild(deliveryOm);
        if (!(expires.equals("*"))) {
            // Add only if the value provided
            subscribeOm.addChild(expiresOm);
        }
        subscribeOm.addChild(filterOm);
        // set addressing, transport and proxy url
        serviceClient.engageModule("addressing");
        options.setTo(new EndpointReference(addUrl));
        options.setAction("http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe");
        serviceClient.setOptions(options);
        System.out.println("Subscribing \n" + subscribeOm.toString());
        try {
            OMElement response = serviceClient.sendReceive(subscribeOm);
            System.out.println("Subscribed to topic " + topic);
            Thread.sleep(1000);
            System.out.println("Response Received: " + response.toString());
            String subId = response.getFirstChildWithName(new QName(nswse.getNamespaceURI(), "SubscriptionManager")).getFirstChildWithName(new QName(nswsa.getNamespaceURI(), "ReferenceParameters")).getFirstChildWithName(new QName(nswse.getNamespaceURI(), "Identifier")).getText();
            System.out.println("Subscription identifier: " + subId);
        } catch (AxisFault e) {
            System.out.println("Fault Received : " + e.toString());
            System.out.println("Fault Code     : " + e.getFaultCode().toString());
        }
    } else if (mode.equals("unsubscribe")) {
        /**
         * Send unsubscribe message
         *             (01) <s12:Envelope
         *             (02)     xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
         *             (03)     xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
         *             (04)     xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing"
         *             (05)     xmlns:ow="http://www.example.org/oceanwatch" >
         *             (06)   <s12:Header>
         *             (07)     <wsa:Action>
         *             (08)       http://schemas.xmlsoap.org/ws/2004/08/eventing/Unsubscribe
         *             (09)     </wsa:Action>
         *             (10)     <wsa:MessageID>
         *             (11)       uuid:2653f89f-25bc-4c2a-a7c4-620504f6b216
         *             (12)     </wsa:MessageID>
         *             (13)     <wsa:ReplyTo>
         *             (14)      <wsa:Address>http://www.example.com/MyEventSink</wsa:Address>
         *             (15)     </wsa:ReplyTo>
         *             (16)     <wsa:To>
         *             (17)       http://www.example.org/oceanwatch/SubscriptionManager
         *             (18)     </wsa:To>
         *             (19)     <wse:Identifier>
         *             (20)       uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa
         *             (21)     </wse:Identifier>
         *             (22)   </s12:Header>
         *             (23)   <s12:Body>
         *             (24)     <wse:Unsubscribe />
         *             (25)   </s12:Body>
         *             (26) </s12:Envelope>
         */
        OMElement subscribeOm = factory.createOMElement("Unsubscribe", nswse);
        serviceClient.engageModule("addressing");
        options.setTo(new EndpointReference(addUrl));
        options.setAction("http://schemas.xmlsoap.org/ws/2004/08/eventing/Unsubscribe");
        OMElement identifierOm = factory.createOMElement("Identifier", nswse);
        factory.createOMText(identifierOm, identifier);
        serviceClient.addHeader(identifierOm);
        serviceClient.setOptions(options);
        System.out.println("UnSubscribing \n" + subscribeOm.toString());
        try {
            OMElement response = serviceClient.sendReceive(subscribeOm);
            System.out.println("UnSubscribed to ID " + identifier);
            Thread.sleep(1000);
            System.out.println("UnSubscribe Response Received: " + response.toString());
        } catch (AxisFault e) {
            System.out.println("Fault Received : " + e.toString());
            System.out.println("Fault Code     : " + e.getFaultCode().toString());
        }
    } else if (mode.equals("renew")) {
        /**
         * (01) <s12:Envelope
         *             (02)     xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
         *             (03)     xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
         *             (04)     xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing"
         *             (05)     xmlns:ow="http://www.example.org/oceanwatch" >
         *             (06)   <s12:Header>
         *             (07)     <wsa:Action>
         *             (08)       http://schemas.xmlsoap.org/ws/2004/08/eventing/Renew
         *             (09)     </wsa:Action>
         *             (10)     <wsa:MessageID>
         *             (11)       uuid:bd88b3df-5db4-4392-9621-aee9160721f6
         *             (12)     </wsa:MessageID>
         *             (13)     <wsa:ReplyTo>
         *             (14)      <wsa:Address>http://www.example.com/MyEventSink</wsa:Address>
         *             (15)     </wsa:ReplyTo>
         *             (16)     <wsa:To>
         *             (17)       http://www.example.org/oceanwatch/SubscriptionManager
         *             (18)     </wsa:To>
         *             (19)     <wse:Identifier>
         *             (20)       uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa
         *             (21)     </wse:Identifier>
         *             (22)   </s12:Header>
         *             (23)   <s12:Body>
         *             (24)     <wse:Renew>
         *             (25)       <wse:Expires>2004-06-26T21:07:00.000-08:00</wse:Expires>
         *             (26)     </wse:Renew>
         *             (27)   </s12:Body>
         *             (28) </s12:Envelope>
         */
        OMElement subscribeOm = factory.createOMElement("Renew", nswse);
        OMElement expiresOm = factory.createOMElement("Expires", nswse);
        factory.createOMText(expiresOm, expires);
        subscribeOm.addChild(expiresOm);
        serviceClient.engageModule("addressing");
        options.setTo(new EndpointReference(addUrl));
        options.setAction("http://schemas.xmlsoap.org/ws/2004/08/eventing/Renew");
        OMElement identifierOm = factory.createOMElement("Identifier", nswse);
        factory.createOMText(identifierOm, identifier);
        serviceClient.addHeader(identifierOm);
        serviceClient.setOptions(options);
        System.out.println("SynapseSubscription Renew \n" + subscribeOm.toString());
        try {
            OMElement response = serviceClient.sendReceive(subscribeOm);
            System.out.println("SynapseSubscription Renew to ID " + identifier);
            Thread.sleep(1000);
            System.out.println("SynapseSubscription Renew Response Received: " + response.toString());
        } catch (AxisFault e) {
            System.out.println("Fault Received : " + e.toString());
            System.out.println("Fault Code     : " + e.getFaultCode().toString());
        }
    } else if (mode.equals("getstatus")) {
        /**
         * (01) <s12:Envelope
         *             (02)     xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
         *             (03)     xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
         *             (04)     xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing"
         *             (05)     xmlns:ow="http://www.example.org/oceanwatch" >
         *             (06)   <s12:Header>
         *             (07)     <wsa:Action>
         *             (08)       http://schemas.xmlsoap.org/ws/2004/08/eventing/GetStatus
         *             (09)     </wsa:Action>
         *             (10)     <wsa:MessageID>
         *             (11)       uuid:bd88b3df-5db4-4392-9621-aee9160721f6
         *             (12)     </wsa:MessageID>
         *             (13)     <wsa:ReplyTo>
         *             (14)       <wsa:Address>http://www.example.com/MyEventSink</wsa:Address>
         *             (15)     </wsa:ReplyTo>
         *             (16)     <wsa:To>
         *             (17)       http://www.example.org/oceanwatch/SubscriptionManager
         *             (18)     </wsa:To>
         *             (19)     <wse:Identifier>
         *             (20)       uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa
         *             (21)     </wse:Identifier>
         *             (22)   </s12:Header>
         *             (23)   <s12:Body>
         *             (24)     <wse:GetStatus />
         *             (25)   </s12:Body>
         *             (26) </s12:Envelope>
         */
        OMElement subscribeOm = factory.createOMElement("GetStatus", nswse);
        serviceClient.engageModule("addressing");
        options.setTo(new EndpointReference(addUrl));
        options.setAction("http://schemas.xmlsoap.org/ws/2004/08/eventing/GetStatus");
        OMElement identifierOm = factory.createOMElement("Identifier", nswse);
        factory.createOMText(identifierOm, identifier);
        serviceClient.addHeader(identifierOm);
        serviceClient.setOptions(options);
        System.out.println("GetStatus using \n" + subscribeOm.toString());
        try {
            OMElement response = serviceClient.sendReceive(subscribeOm);
            System.out.println("GetStatus to ID " + identifier);
            Thread.sleep(1000);
            System.out.println("GetStatus Response Received: " + response.toString());
        } catch (AxisFault e) {
            System.out.println("Fault Received : " + e.toString());
            System.out.println("Fault Code     : " + e.getFaultCode().toString());
        }
    }
    try {
        if (configContext != null) {
            configContext.terminate();
        }
    } catch (Exception ignore) {
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) OMNamespace(org.apache.axiom.om.OMNamespace) ServiceClient(org.apache.axis2.client.ServiceClient) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

IOException (java.io.IOException)31 EndpointReference (org.apache.axis2.addressing.EndpointReference)29 AxisFault (org.apache.axis2.AxisFault)27 URL (java.net.URL)21 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)19 URL (org.apache.axis2.util.URL)19 HttpClient (org.apache.http.client.HttpClient)19 Options (org.apache.axis2.client.Options)18 MalformedURLException (java.net.MalformedURLException)17 OMElement (org.apache.axiom.om.OMElement)17 MessageContext (org.apache.axis2.context.MessageContext)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 ServiceClient (org.apache.axis2.client.ServiceClient)13 SynapseException (org.apache.synapse.SynapseException)13 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)12 AxisService (org.apache.axis2.description.AxisService)10 StringEntity (org.apache.http.entity.StringEntity)9 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)9 Map (java.util.Map)7 JSONObject (org.json.JSONObject)7