Search in sources :

Example 41 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.

the class MailClient method main.

public static void main(String[] args) throws AxisFault {
    Options options = new Options();
    options.setTo(new EndpointReference(toEpr));
    options.setAction("urn:echo");
    ServiceClient servicClient = new ServiceClient();
    servicClient.setOptions(options);
    servicClient.sendRobust(getPayload());
}
Also used : Options(org.apache.axis2.client.Options) ServiceClient(org.apache.axis2.client.ServiceClient) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 42 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.

the class RESTSearchModel method searchYahoo.

public String searchYahoo(String query, String format) {
    try {
        snippet = beginHTML;
        String epr = "http://search.yahooapis.com/WebSearchService/V1/webSearch";
        ServiceClient client = new ServiceClient();
        Options options = new Options();
        client.setOptions(options);
        options.setTo(new EndpointReference(epr));
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET);
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, org.apache.axis2.kernel.http.HTTPConstants.MEDIA_TYPE_X_WWW_FORM);
        // if post is through GET of HTTP
        OMElement response = client.sendReceive(getPayloadForYahooSearchCall(query, format));
        generateSnippet(response);
        return snippet;
    } catch (Exception e) {
        e.printStackTrace();
        snippet = "<H2>Error occurred during the invocation to Yahoo search service</H2>" + "<p>" + e.getMessage() + "</p>" + endHTML;
    }
    return null;
}
Also used : Options(org.apache.axis2.client.Options) ServiceClient(org.apache.axis2.client.ServiceClient) OMElement(org.apache.axiom.om.OMElement) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 43 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.

the class ServiceDelegate method createDispatch.

@Override
public <T> Dispatch<T> createDispatch(EndpointReference jaxwsEPR, Class<T> type, Mode mode, WebServiceFeature... features) {
    if (log.isDebugEnabled()) {
        log.debug("Create Dispatch with epr: " + jaxwsEPR);
    }
    verifyServiceDescriptionActive();
    if (jaxwsEPR == null) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNoEndpointReference"));
    }
    if (!isValidDispatchType(type)) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchInvalidType"));
    }
    if (!isValidDispatchTypeWithMode(type, mode)) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchInvalidTypeWithMode"));
    }
    org.apache.axis2.addressing.EndpointReference axis2EPR = EndpointReferenceUtils.createAxis2EndpointReference("");
    String addressingNamespace = null;
    try {
        addressingNamespace = EndpointReferenceUtils.convertToAxis2(axis2EPR, jaxwsEPR);
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("invalidEndpointReference", e.toString()));
    }
    EndpointDescription endpointDesc = DescriptionFactory.updateEndpoint(serviceDescription, null, axis2EPR, addressingNamespace, DescriptionFactory.UpdateType.CREATE_DISPATCH, this);
    if (endpointDesc == null) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointDescriptionConstructionFailure", jaxwsEPR.toString()));
    }
    XMLDispatch<T> dispatch = new XMLDispatch<T>(this, endpointDesc, axis2EPR, addressingNamespace, features);
    if (mode != null) {
        dispatch.setMode(mode);
    } else {
        dispatch.setMode(Service.Mode.PAYLOAD);
    }
    if (serviceClient == null)
        serviceClient = getServiceClient(endpointDesc.getPortQName());
    dispatch.setServiceClient(serviceClient);
    dispatch.setType(type);
    return dispatch;
}
Also used : XMLDispatch(org.apache.axis2.jaxws.client.dispatch.XMLDispatch) EndpointDescription(org.apache.axis2.jaxws.description.EndpointDescription) PrivilegedActionException(java.security.PrivilegedActionException) MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException)

Example 44 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.

the class Provider method getPort.

@Override
public <T> T getPort(EndpointReference jaxwsEPR, Class<T> sei, WebServiceFeature... features) {
    if (jaxwsEPR == null) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNoEndpointReference2"));
    }
    if (sei == null) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("getPortInvalidSEI", jaxwsEPR.toString(), "null"));
    }
    org.apache.axis2.addressing.EndpointReference axis2EPR = EndpointReferenceUtils.createAxis2EndpointReference("");
    String addressingNamespace = null;
    try {
        addressingNamespace = EndpointReferenceUtils.convertToAxis2(axis2EPR, jaxwsEPR);
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("invalidEndpointReference", e.toString()));
    }
    org.apache.axis2.jaxws.spi.ServiceDelegate serviceDelegate = null;
    try {
        ServiceName serviceName = EndpointReferenceHelper.getServiceNameMetadata(axis2EPR, addressingNamespace);
        WSDLLocation wsdlLocation = EndpointReferenceHelper.getWSDLLocationMetadata(axis2EPR, addressingNamespace);
        URL wsdlLocationURL = null;
        if (wsdlLocation.getLocation() != null) {
            wsdlLocationURL = new URL(wsdlLocation.getLocation());
            if (log.isDebugEnabled()) {
                log.debug("getPort: Using EPR wsdlLocationURL = " + wsdlLocationURL);
            }
        } else {
            wsdlLocationURL = new URL(axis2EPR.getAddress() + "?wsdl");
            if (log.isDebugEnabled()) {
                log.debug("getPort: Using default wsdlLocationURL = " + wsdlLocationURL);
            }
        }
        serviceDelegate = new org.apache.axis2.jaxws.spi.ServiceDelegate(wsdlLocationURL, serviceName.getName(), Service.class);
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointUpdateError"), e);
    }
    return serviceDelegate.getPort(axis2EPR, addressingNamespace, sei, features);
}
Also used : Service(javax.xml.ws.Service) URL(java.net.URL) ServiceName(org.apache.axis2.addressing.metadata.ServiceName) WSDLLocation(org.apache.axis2.addressing.metadata.WSDLLocation)

Example 45 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.

the class RequestURIBasedServiceDispatcherTest method testFindService.

public void testFindService() throws AxisFault {
    MessageContext messageContext;
    // Global services
    AxisService as1 = new AxisService("Service1");
    AxisService as2 = new AxisService("Service2");
    as1.addEndpoint("Service1Endpoint", new AxisEndpoint());
    // Hierarchical Services
    AxisService as3 = new AxisService("foo/bar/Version");
    AxisService as4 = new AxisService("foo/bar/1.0.1/Echo");
    as3.addEndpoint("VersionEndpoint", new AxisEndpoint());
    as4.addEndpoint("EchoEndpoint", new AxisEndpoint());
    ConfigurationContext cc = ConfigurationContextFactory.createEmptyConfigurationContext();
    AxisConfiguration ac = cc.getAxisConfiguration();
    ac.addService(as1);
    ac.addService(as2);
    ac.addService(as3);
    ac.addService(as4);
    RequestURIBasedServiceDispatcher ruisd = new RequestURIBasedServiceDispatcher();
    /**
     * Tests for global services
     */
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service2"));
    ruisd.invoke(messageContext);
    assertEquals(as2, messageContext.getAxisService());
    // service/operation scenario
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service2/getName"));
    ruisd.invoke(messageContext);
    assertEquals(as2, messageContext.getAxisService());
    // REST scenario
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service2/student/name/peter/age/25"));
    ruisd.invoke(messageContext);
    assertEquals(as2, messageContext.getAxisService());
    // service.endpoint scenario
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service1.Service1Endpoint"));
    ruisd.invoke(messageContext);
    assertEquals(as1, messageContext.getAxisService());
    // service.endpoint/operation scenario
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service1.Service1Endpoint/getName"));
    ruisd.invoke(messageContext);
    assertEquals(as1, messageContext.getAxisService());
    /**
     * Tests for hierarchical services
     */
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version"));
    ruisd.invoke(messageContext);
    assertEquals(as3, messageContext.getAxisService());
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version/getVersion"));
    ruisd.invoke(messageContext);
    assertEquals(as3, messageContext.getAxisService());
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version/student/name/peter/age/25"));
    ruisd.invoke(messageContext);
    assertEquals(as3, messageContext.getAxisService());
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version.VersionEndpoint"));
    ruisd.invoke(messageContext);
    assertEquals(as3, messageContext.getAxisService());
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version.VersionEndpoint/getVersion"));
    ruisd.invoke(messageContext);
    assertEquals(as3, messageContext.getAxisService());
    /**
     * Tests for hierarchical services with '.' in the service name
     */
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo"));
    ruisd.invoke(messageContext);
    assertEquals(as4, messageContext.getAxisService());
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo/echo"));
    ruisd.invoke(messageContext);
    assertEquals(as4, messageContext.getAxisService());
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo/student/name/peter/age/25"));
    ruisd.invoke(messageContext);
    assertEquals(as4, messageContext.getAxisService());
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo.EchoEndpoint"));
    ruisd.invoke(messageContext);
    assertEquals(as4, messageContext.getAxisService());
    messageContext = cc.createMessageContext();
    messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo.EchoEndpoint/echo"));
    ruisd.invoke(messageContext);
    assertEquals(as4, messageContext.getAxisService());
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) AxisService(org.apache.axis2.description.AxisService) MessageContext(org.apache.axis2.context.MessageContext) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

EndpointReference (org.apache.axis2.addressing.EndpointReference)261 Options (org.apache.axis2.client.Options)99 OMElement (org.apache.axiom.om.OMElement)67 AxisFault (org.apache.axis2.AxisFault)66 MessageContext (org.apache.axis2.context.MessageContext)58 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)57 ServiceClient (org.apache.axis2.client.ServiceClient)54 QName (javax.xml.namespace.QName)40 ArrayList (java.util.ArrayList)37 AxisService (org.apache.axis2.description.AxisService)28 Map (java.util.Map)25 MessageContext (org.apache.synapse.MessageContext)25 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)25 Test (org.junit.Test)20 IOException (java.io.IOException)19 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)18 RelatesTo (org.apache.axis2.addressing.RelatesTo)18 URL (java.net.URL)17 SOAPFactory (org.apache.axiom.soap.SOAPFactory)17 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)17