Search in sources :

Example 56 with EndpointReference

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

the class LocalTransportTest method test.

@Test
public void test() throws Exception {
    ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromURIs(LocalTransportTest.class.getResource("axis2.xml"), null);
    AxisService service = new AxisService("Echo");
    AxisOperation operation = new InOutAxisOperation(new QName("echo"));
    operation.setMessageReceiver(new EchoMessageReceiver());
    service.addOperation(operation);
    service.addParameter(AxisService.SUPPORT_SINGLE_OP, true);
    configurationContext.getAxisConfiguration().addService(service);
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement requestElement = factory.createOMElement("test", "urn:test", "t");
    requestElement.setText("Hi there!");
    Options options = new Options();
    options.setTo(new EndpointReference("local://localhost/axis2/services/Echo"));
    ServiceClient serviceClient = new ServiceClient(configurationContext, null);
    serviceClient.setOptions(options);
    OMElement responseElement = serviceClient.sendReceive(requestElement);
    XMLAssert.assertXMLEqual(requestElement.toString(), responseElement.toString());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Options(org.apache.axis2.client.Options) InOutAxisOperation(org.apache.axis2.description.InOutAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) QName(javax.xml.namespace.QName) ServiceClient(org.apache.axis2.client.ServiceClient) AxisService(org.apache.axis2.description.AxisService) OMElement(org.apache.axiom.om.OMElement) InOutAxisOperation(org.apache.axis2.description.InOutAxisOperation) EndpointReference(org.apache.axis2.addressing.EndpointReference) Test(org.junit.Test)

Example 57 with EndpointReference

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

the class AxisInvocationController method initOperationClient.

private void initOperationClient(OperationClient opClient, MessageContext requestMsgCtx) {
    org.apache.axis2.context.MessageContext axisRequest = requestMsgCtx.getAxisMessageContext();
    // , axisRequest.getOptions());
    setupProperties(requestMsgCtx);
    if (opClient != null) {
        Options options = opClient.getOptions();
        // Get the target endpoint address and setup the TO endpoint
        // reference.  This tells us where the request is going.
        EndpointReference toEPR = axisRequest.getTo();
        if (toEPR == null) {
            String targetUrl = (String) requestMsgCtx.getProperty(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
            toEPR = new EndpointReference(targetUrl);
        }
        options.setTo(toEPR);
        // Get the SOAP Action (if needed)
        String soapAction = ClientUtils.findSOAPAction(requestMsgCtx);
        options.setAction(soapAction);
        // get the timeout from the request message context options as it may have been
        // set by the user; if it was not set by the user we will just be setting the
        // timeout on the operation client to the default so it will not have a negative
        // effect; this logic is reliant on the fact the JAX-WS MessageContext is delegating
        // to the Axis2 Options object and not storing its own property bag
        long timeout = axisRequest.getOptions().getTimeOutInMilliSeconds();
        options.setTimeOutInMilliSeconds(timeout);
        // of the response in the response MessageContext.
        try {
            // Set the Axis2 request MessageContext
            opClient.addMessageContext(axisRequest);
        } catch (Exception e) {
        // TODO: Do something
        }
    }
}
Also used : Options(org.apache.axis2.client.Options) MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 58 with EndpointReference

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

the class Axis2EndpointReferenceFactoryImpl method createEndpointReference.

/*
     *  (non-Javadoc)
     * @see org.apache.axis2.jaxws.addressing.factory.Axis2EndpointReferenceFactory#createEndpointReference(java.lang.String, javax.xml.namespace.QName, javax.xml.namespace.QName, java.lang.String, java.lang.String)
     */
public EndpointReference createEndpointReference(String address, QName serviceName, QName portName, String wsdlDocumentLocation, String addressingNamespace) {
    EndpointReference axis2EPR = null;
    if (address != null) {
        if (serviceName == null && portName != null) {
            throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr", portName.toString()));
        }
        axis2EPR = createEndpointReference(address);
    } else if (serviceName != null && portName != null) {
        axis2EPR = createEndpointReference(serviceName, portName);
    } else {
        throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr2"));
    }
    // should simply use those.
    try {
        // This code is locate here instead of in the createEndpointReference(QName, QName)
        // method so that if the address is also specified the EPR metadata will still be
        // filled in correctly.
        EndpointReferenceUtils.addService(axis2EPR, serviceName, portName, addressingNamespace);
        if (wsdlDocumentLocation != null) {
            URL wsdlURL;
            try {
                wsdlURL = new URL(wsdlDocumentLocation);
            } catch (MalformedURLException e) {
                // just to keep it clean:
                if (axis2EPR.getAddress().endsWith("/") && wsdlDocumentLocation.startsWith("/")) {
                    wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation.substring(1);
                } else if (axis2EPR.getAddress().endsWith("/")) {
                    String eprAddress = axis2EPR.getAddress();
                    wsdlDocumentLocation = eprAddress.substring(0, eprAddress.length() - 1) + wsdlDocumentLocation;
                } else {
                    wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation;
                }
            }
            wsdlURL = new URL(wsdlDocumentLocation);
            // This is a temporary usage, so use a memory sensitive wrapper
            WSDLWrapper wrapper = new WSDL4JWrapper(wsdlURL, true, 2);
            if (serviceName != null) {
                QName serviceNameNoTrailingSlash = new QName("");
                // TODO: why in the world would we have to do this?
                if (serviceName.getNamespaceURI().endsWith("/")) {
                    String ns = serviceName.getNamespaceURI();
                    serviceNameNoTrailingSlash = new QName(ns.substring(0, ns.length() - 1), serviceName.getLocalPart());
                }
                if ((wrapper.getService(serviceName) == null) && (wrapper.getService(serviceNameNoTrailingSlash) == null)) {
                    throw new IllegalStateException(Messages.getMessage("MissingServiceName", serviceName.toString(), wsdlDocumentLocation));
                }
                if (portName != null) {
                    String[] ports = wrapper.getPorts(serviceName);
                    // search the other name.  TODO: again, why do we have to do this?
                    if (ports == null) {
                        ports = wrapper.getPorts(serviceNameNoTrailingSlash);
                    }
                    String portLocalName = portName.getLocalPart();
                    boolean found = false;
                    if (ports != null) {
                        for (String port : ports) {
                            // TODO: axis2 perhaps is deploying with "TypeImplPort" appended, but not reading/honoring the WSDL?
                            if (port.equals(portLocalName) || (port + "TypeImplPort").equals(portLocalName)) {
                                log.debug("found port: " + port);
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found) {
                        throw new IllegalStateException(Messages.getMessage("MissingPortName", portName.toString(), wsdlDocumentLocation));
                    }
                    log.debug("Setting wsdlDocumentLocation to " + wsdlDocumentLocation + " for EndpointReference at port " + portName);
                    EndpointReferenceUtils.addLocation(axis2EPR, portName.getNamespaceURI(), wsdlDocumentLocation, addressingNamespace);
                }
            }
        }
    } catch (IllegalStateException ise) {
        throw ise;
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointRefCreationError"), e);
    }
    return axis2EPR;
}
Also used : MalformedURLException(java.net.MalformedURLException) WSDL4JWrapper(org.apache.axis2.jaxws.util.WSDL4JWrapper) QName(javax.xml.namespace.QName) URL(java.net.URL) WSDLWrapper(org.apache.axis2.jaxws.util.WSDLWrapper) MalformedURLException(java.net.MalformedURLException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 59 with EndpointReference

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

the class EndpointReferenceUtils method addService.

/**
 * @param axis2EPR
 * @param service
 * @param port
 * @param addressingNamespace
 * @throws Exception
 */
public static void addService(EndpointReference axis2EPR, QName service, QName port, String addressingNamespace) throws Exception {
    if (service != null && port != null) {
        ServiceName serviceName = new ServiceName(service, port.getLocalPart());
        EndpointReferenceHelper.setServiceNameMetadata(omFactory, axis2EPR, addressingNamespace, serviceName);
    }
}
Also used : ServiceName(org.apache.axis2.addressing.metadata.ServiceName)

Example 60 with EndpointReference

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

the class EndpointReferenceUtils method addLocation.

/**
 * @param axis2EPR
 * @param targetNamespace
 * @param wsdlDocumentLocation
 * @param addressingNamespace
 * @throws Exception
 */
public static void addLocation(EndpointReference axis2EPR, String targetNamespace, String wsdlDocumentLocation, String addressingNamespace) throws Exception {
    if (targetNamespace != null && wsdlDocumentLocation != null) {
        WSDLLocation wsdlLocation = new WSDLLocation(targetNamespace, wsdlDocumentLocation);
        EndpointReferenceHelper.setWSDLLocationMetadata(omFactory, axis2EPR, addressingNamespace, wsdlLocation);
    }
}
Also used : WSDLLocation(org.apache.axis2.addressing.metadata.WSDLLocation)

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