Search in sources :

Example 66 with EndpointReference

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

the class AxisEndpoint method calculateEndpointURL.

public String calculateEndpointURL(String hostIP) {
    if (transportInDescName != null && parent != null) {
        AxisConfiguration axisConfiguration = getAxisConfiguration();
        if (axisConfiguration != null) {
            try {
                String serviceName = ((AxisService) parent).getName();
                TransportInDescription in = axisConfiguration.getTransportIn(transportInDescName);
                TransportListener listener = in.getReceiver();
                String ip;
                if (hostIP != null) {
                    ip = hostIP;
                } else {
                    ip = Utils.getIpAddress(axisConfiguration);
                }
                // we should pass [serviceName].[endpointName] instead of
                // [endpointName]
                String sDOTe = serviceName + "." + name;
                EndpointReference[] eprsForService = listener.getEPRsForService(sDOTe, ip);
                // we consider only the first address return by the listener
                if (eprsForService != null && eprsForService.length > 0) {
                    return eprsForService[0].getAddress();
                }
            } catch (SocketException e) {
                logger.warn(e.getMessage(), e);
            } catch (AxisFault e) {
                logger.warn(e.getMessage(), e);
            }
        }
    }
    return null;
}
Also used : TransportListener(org.apache.axis2.kernel.TransportListener) AxisFault(org.apache.axis2.AxisFault) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) SocketException(java.net.SocketException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 67 with EndpointReference

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

the class OutInAxisOperationClient method sendAsync.

private void sendAsync(boolean useAsync, MessageContext mc) throws AxisFault {
    if (log.isDebugEnabled()) {
        log.debug("useAsync=" + useAsync + ", seperateListener=" + mc.getOptions().isUseSeparateListener());
    }
    /**
     * We are following the async path. If the user hasn't set a callback object then we must
     * block until the whole MEP is complete, as they have no other way to get their reply message.
     */
    // THREADSAFE issue: Multiple threads could be trying to initialize the callback receiver
    // so it is synchronized.  It is not done within the else clause to avoid the
    // double-checked lock antipattern.
    CallbackReceiver callbackReceiver;
    synchronized (axisOp) {
        if (axisOp.getMessageReceiver() != null && axisOp.getMessageReceiver() instanceof CallbackReceiver) {
            callbackReceiver = (CallbackReceiver) axisOp.getMessageReceiver();
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Creating new callback receiver");
            }
            callbackReceiver = new CallbackReceiver();
            axisOp.setMessageReceiver(callbackReceiver);
            if (log.isDebugEnabled())
                log.debug("OutInAxisOperation: callbackReceiver " + callbackReceiver + " : " + axisOp);
        }
    }
    SyncCallBack internalCallback = null;
    if (axisCallback != null) {
        callbackReceiver.addCallback(mc.getMessageID(), axisCallback);
        if (log.isDebugEnabled())
            log.debug("OutInAxisOperationClient: Creating axis callback");
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Creating internal callback");
        }
        internalCallback = new SyncCallBack();
        callbackReceiver.addCallback(mc.getMessageID(), internalCallback);
        if (log.isDebugEnabled())
            log.debug("OutInAxisOperationClient: Creating internal callback");
    }
    /**
     * If USE_CUSTOM_LISTENER is set to 'true' the replyTo value will not be replaced and Axis2 will not
     * start its internal listner. Some other enntity (e.g. a module) should take care of obtaining the
     * response message.
     */
    Boolean useCustomListener = (Boolean) options.getProperty(Constants.Configuration.USE_CUSTOM_LISTENER);
    if (useAsync) {
        useCustomListener = Boolean.TRUE;
    }
    if (useCustomListener == null || !useCustomListener.booleanValue()) {
        EndpointReference replyTo = mc.getReplyTo();
        if (replyTo == null || replyTo.hasAnonymousAddress()) {
            EndpointReference replyToFromTransport = mc.getConfigurationContext().getListenerManager().getEPRforService(sc.getAxisService().getName(), axisOp.getName().getLocalPart(), mc.getTransportIn().getName());
            if (replyTo == null) {
                mc.setReplyTo(replyToFromTransport);
            } else {
                replyTo.setAddress(replyToFromTransport.getAddress());
            }
        }
    }
    // if we don't do this , this guy will wait till it gets HTTP 202 in the HTTP case
    mc.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.TRUE);
    mc.getConfigurationContext().registerOperationContext(mc.getMessageID(), oc);
    AxisEngine.send(mc);
    if (internalCallback != null) {
        internalCallback.waitForCompletion(options.getTimeOutInMilliSeconds());
        // process the result of the invocation
        if (internalCallback.envelope == null) {
            if (internalCallback.error == null) {
                log.error("Callback had neither error nor response");
            }
            if (options.isExceptionToBeThrownOnSOAPFault()) {
                throw AxisFault.makeFault(internalCallback.error);
            }
        }
    }
}
Also used : CallbackReceiver(org.apache.axis2.util.CallbackReceiver) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 68 with EndpointReference

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

the class OutInAxisOperationClient method executeImpl.

/**
 * Executes the MEP. What this does depends on the specific MEP client. The
 * basic idea is to have the MEP client execute and do something with the
 * messages that have been added to it so far. For example, if its an Out-In
 * MEP, then if the Out message has been set, then executing the client asks
 * it to send the message and get the In message, possibly using a different
 * thread.
 *
 * @param block Indicates whether execution should block or return ASAP. What
 *              block means is of course a function of the specific MEP
 *              client. IGNORED BY THIS MEP CLIENT.
 * @throws AxisFault if something goes wrong during the execution of the MEP.
 */
public void executeImpl(boolean block) throws AxisFault {
    if (log.isDebugEnabled()) {
        log.debug("Entry: OutInAxisOperationClient::execute, " + block);
    }
    if (completed) {
        throw new AxisFault(Messages.getMessage("mepiscomplted"));
    }
    ConfigurationContext cc = sc.getConfigurationContext();
    // copy interesting info from options to message context.
    MessageContext mc = oc.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
    if (mc == null) {
        throw new AxisFault(Messages.getMessage("outmsgctxnull"));
    }
    prepareMessageContext(cc, mc);
    if (options.getTransportIn() == null && mc.getTransportIn() == null) {
        mc.setTransportIn(ClientUtils.inferInTransport(cc.getAxisConfiguration(), options, mc));
    } else if (mc.getTransportIn() == null) {
        mc.setTransportIn(options.getTransportIn());
    }
    /**
     * If a module has set the USE_ASYNC_OPERATIONS option then we override the behaviour
     * for sync calls, and effectively USE_CUSTOM_LISTENER too. However we leave real
     * async calls alone.
     */
    boolean useAsync = false;
    if (!mc.getOptions().isUseSeparateListener()) {
        Boolean useAsyncOption = (Boolean) mc.getProperty(Constants.Configuration.USE_ASYNC_OPERATIONS);
        if (log.isDebugEnabled())
            log.debug("OutInAxisOperationClient: useAsyncOption " + useAsyncOption);
        if (useAsyncOption != null) {
            useAsync = useAsyncOption.booleanValue();
        }
    }
    EndpointReference replyTo = mc.getReplyTo();
    if (replyTo != null) {
        if (replyTo.hasNoneAddress()) {
            throw new AxisFault(replyTo.getAddress() + "" + " can not be used with OutInAxisOperationClient , user either " + "fireAndForget or sendRobust)");
        } else if (replyTo.isWSAddressingAnonymous() && replyTo.getAllReferenceParameters() != null) {
            mc.setProperty(AddressingConstants.INCLUDE_OPTIONAL_HEADERS, Boolean.TRUE);
        }
        String customReplyTo = (String) options.getProperty(Options.CUSTOM_REPLYTO_ADDRESS);
        if (!(Options.CUSTOM_REPLYTO_ADDRESS_TRUE.equals(customReplyTo))) {
            if (!replyTo.hasAnonymousAddress()) {
                useAsync = true;
            }
        }
    }
    if (useAsync || mc.getOptions().isUseSeparateListener()) {
        sendAsync(useAsync, mc);
    } else {
        if (block) {
            // Send the SOAP Message and receive a response
            send(mc);
            completed = true;
        } else {
            sc.getConfigurationContext().getThreadPool().execute(new NonBlockingInvocationWorker(mc, axisCallback));
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 69 with EndpointReference

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

the class XMPPSampleClient method invokeTimeService.

private static void invokeTimeService() {
    String endPointUrl = "xmpp://synapse.demo.0@gmail.com/" + "TimeService";
    EndpointReference targetEPR = new EndpointReference(endPointUrl);
    try {
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromURIs(XMPPSampleClient.class.getResource("axis2.xml"), null);
        OMElement payload = getPayload();
        Options options = new Options();
        options.setProperty(XMPPConstants.XMPP_SERVER_TYPE, XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK);
        options.setProperty(XMPPConstants.XMPP_SERVER_URL, XMPPConstants.GOOGLETALK_URL);
        options.setProperty(XMPPConstants.XMPP_SERVER_USERNAME, "synapse.demo.0");
        options.setProperty(XMPPConstants.XMPP_SERVER_PASSWORD, "mailpassword");
        options.setTo(targetEPR);
        options.setAction("urn:getServerTime");
        ServiceClient sender = new ServiceClient(ctx, null);
        sender.setOptions(options);
        OMElement result = sender.sendReceive(payload);
        XMLPrettyPrinter.prettify(result, System.out);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Options(org.apache.axis2.client.Options) ServiceClient(org.apache.axis2.client.ServiceClient) OMElement(org.apache.axiom.om.OMElement) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 70 with EndpointReference

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

the class XMPPPacketListener method createMessageContext.

/**
 * Creates message context using values received in XMPP packet
 * @param packet
 * @return MessageContext
 * @throws AxisFault
 */
private MessageContext createMessageContext(Packet packet) throws AxisFault {
    Message message = (Message) packet;
    Boolean isServerSide = (Boolean) message.getProperty(XMPPConstants.IS_SERVER_SIDE);
    String serviceName = (String) message.getProperty(XMPPConstants.SERVICE_NAME);
    String action = (String) message.getProperty(XMPPConstants.ACTION);
    MessageContext msgContext = null;
    TransportInDescription transportIn = configurationContext.getAxisConfiguration().getTransportIn("xmpp");
    TransportOutDescription transportOut = configurationContext.getAxisConfiguration().getTransportOut("xmpp");
    if ((transportIn != null) && (transportOut != null)) {
        msgContext = configurationContext.createMessageContext();
        msgContext.setTransportIn(transportIn);
        msgContext.setTransportOut(transportOut);
        if (isServerSide != null) {
            msgContext.setServerSide(isServerSide.booleanValue());
        }
        msgContext.setProperty(CONTENT_TYPE, "text/xml");
        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
        msgContext.setIncomingTransportName("xmpp");
        Map services = configurationContext.getAxisConfiguration().getServices();
        AxisService axisService = (AxisService) services.get(serviceName);
        msgContext.setAxisService(axisService);
        msgContext.setSoapAction(action);
        // pass the configurationFactory to transport sender
        msgContext.setProperty("XMPPConfigurationFactory", this.xmppConnectionFactory);
        if (packet.getFrom() != null) {
            msgContext.setFrom(new EndpointReference(packet.getFrom()));
        }
        if (packet.getTo() != null) {
            msgContext.setTo(new EndpointReference(packet.getTo()));
        }
        XMPPOutTransportInfo xmppOutTransportInfo = new XMPPOutTransportInfo();
        xmppOutTransportInfo.setConnectionFactory(this.xmppConnectionFactory);
        String packetFrom = packet.getFrom();
        if (packetFrom != null) {
            EndpointReference fromEPR = new EndpointReference(packetFrom);
            xmppOutTransportInfo.setFrom(fromEPR);
            xmppOutTransportInfo.setDestinationAccount(packetFrom);
        }
        // Save Message-Id to set as In-Reply-To on reply
        String xmppMessageId = packet.getPacketID();
        if (xmppMessageId != null) {
            xmppOutTransportInfo.setInReplyTo(xmppMessageId);
        }
        xmppOutTransportInfo.setSequenceID((String) message.getProperty(XMPPConstants.SEQUENCE_ID));
        msgContext.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, xmppOutTransportInfo);
        buildSOAPEnvelope(packet, msgContext);
    } else {
        throw new AxisFault("Either transport in or transport out is null");
    }
    return msgContext;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Message(org.jivesoftware.smack.packet.Message) AxisService(org.apache.axis2.description.AxisService) MessageContext(org.apache.axis2.context.MessageContext) TransportInDescription(org.apache.axis2.description.TransportInDescription) Map(java.util.Map) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) 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