Search in sources :

Example 1 with TransportInDescription

use of org.apache.axis2.description.TransportInDescription in project wso2-axis2-transports by wso2.

the class AxisTestClientContext method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(TransportDescriptionFactory tdf, AxisTestClientContextConfigurator[] configurators) throws Exception {
    cfgCtx = ConfigurationContextFactory.createConfigurationContext(new CustomAxisConfigurator());
    AxisConfiguration axisCfg = cfgCtx.getAxisConfiguration();
    TransportOutDescription trpOutDesc = tdf.createTransportOutDescription();
    axisCfg.addTransportOut(trpOutDesc);
    sender = trpOutDesc.getSender();
    sender.init(cfgCtx, trpOutDesc);
    boolean useListener = false;
    for (AxisTestClientContextConfigurator configurator : configurators) {
        if (configurator.isTransportListenerRequired()) {
            useListener = true;
            break;
        }
    }
    TransportInDescription trpInDesc;
    if (useListener) {
        trpInDesc = tdf.createTransportInDescription();
    } else {
        trpInDesc = null;
    }
    for (AxisTestClientContextConfigurator configurator : configurators) {
        configurator.setupTransport(trpInDesc, trpOutDesc);
    }
    if (useListener) {
        listenerManager = new ListenerManager();
        listenerManager.init(cfgCtx);
        cfgCtx.setTransportManager(listenerManager);
        listenerManager.addListener(trpInDesc, false);
        listenerManager.start();
    }
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) CustomAxisConfigurator(org.apache.axis2.transport.CustomAxisConfigurator) TransportInDescription(org.apache.axis2.description.TransportInDescription) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) ListenerManager(org.apache.axis2.engine.ListenerManager) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Example 2 with TransportInDescription

use of org.apache.axis2.description.TransportInDescription in project wso2-axis2-transports by wso2.

the class UDPTest method getClientCfgCtx.

public ConfigurationContext getClientCfgCtx() throws Exception {
    ConfigurationContext cfgCtx = ConfigurationContextFactory.createConfigurationContext(new CustomAxisConfigurator());
    AxisConfiguration axisCfg = cfgCtx.getAxisConfiguration();
    axisCfg.engageModule("addressing");
    TransportInDescription trpInDesc = new TransportInDescription("udp");
    trpInDesc.setReceiver(new UDPListener());
    axisCfg.addTransportIn(trpInDesc);
    TransportOutDescription trpOutDesc = new TransportOutDescription("udp");
    trpOutDesc.setSender(new UDPSender());
    axisCfg.addTransportOut(trpOutDesc);
    return cfgCtx;
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) CustomAxisConfigurator(org.apache.axis2.transport.CustomAxisConfigurator) TransportInDescription(org.apache.axis2.description.TransportInDescription) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 3 with TransportInDescription

use of org.apache.axis2.description.TransportInDescription in project wso2-axis2-transports by wso2.

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)

Example 4 with TransportInDescription

use of org.apache.axis2.description.TransportInDescription in project wso2-axis2-transports by wso2.

the class MailTransportSender method waitForReply.

private void waitForReply(MessageContext msgContext, String mailMessageID) throws AxisFault {
    // message context in asnych model
    if (!(msgContext.getAxisOperation() instanceof OutInAxisOperation) && (msgContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) == null)) {
        return;
    }
    ConfigurationContext configContext = msgContext.getConfigurationContext();
    // if the mail message listner has not started we need to start it
    if (!configContext.getListenerManager().isListenerRunning(MailConstants.TRANSPORT_NAME)) {
        TransportInDescription mailTo = configContext.getAxisConfiguration().getTransportIn(MailConstants.TRANSPORT_NAME);
        if (mailTo == null) {
            handleException("Could not find the transport receiver for " + MailConstants.TRANSPORT_NAME);
        }
        configContext.getListenerManager().addListener(mailTo, false);
    }
    SynchronousCallback synchronousCallback = new SynchronousCallback(msgContext);
    Map callBackMap = (Map) msgContext.getConfigurationContext().getProperty(BaseConstants.CALLBACK_TABLE);
    callBackMap.put(mailMessageID, synchronousCallback);
    synchronized (synchronousCallback) {
        try {
            synchronousCallback.wait(msgContext.getOptions().getTimeOutInMilliSeconds());
        } catch (InterruptedException e) {
            handleException("Error occured while waiting ..", e);
        }
    }
    if (!synchronousCallback.isComplete()) {
        // when timeout occurs remove this entry.
        callBackMap.remove(mailMessageID);
        handleException("Timeout while waiting for a response");
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with TransportInDescription

use of org.apache.axis2.description.TransportInDescription in project wso2-axis2-transports by wso2.

the class AbstractTransportListener method init.

/**
 * Initialize the generic transport. Sets up the transport and the thread pool to be used
 * for message processing. Also creates an AxisObserver that gets notified of service
 * life cycle events for the transport to act on
 * @param cfgCtx the axis configuration context
 * @param transportIn the transport-in description
 * @throws AxisFault on error
 */
public void init(ConfigurationContext cfgCtx, TransportInDescription transportIn) throws AxisFault {
    this.cfgCtx = cfgCtx;
    this.transportIn = transportIn;
    this.transportOut = cfgCtx.getAxisConfiguration().getTransportOut(getTransportName());
    this.config = TransportConfiguration.getConfiguration(getTransportName());
    if (useAxis2ThreadPool) {
        // this.workerPool = cfgCtx.getThreadPool(); not yet implemented
        throw new AxisFault("Unsupported thread pool for task execution - Axis2 thread pool");
    } else {
        if (this.workerPool == null) {
            // FIXME <-- workaround for AXIS2-4552
            this.workerPool = WorkerPoolFactory.getWorkerPool(config.getServerCoreThreads(), config.getServerMaxThreads(), config.getServerKeepalive(), config.getServerQueueLen(), getTransportName() + "Server Worker thread group", getTransportName() + "-Worker");
        }
    }
    // register to receive updates on services for lifetime management
    serviceTracker = new AxisServiceTracker(cfgCtx.getAxisConfiguration(), new AxisServiceFilter() {

        public boolean matches(AxisService service) {
            return // these are "private" services
            !service.getName().startsWith("__") && BaseUtils.isUsingTransport(service, getTransportName());
        }
    }, new AxisServiceTrackerListener() {

        public void serviceAdded(AxisService service) {
            internalStartListeningForService(service);
        }

        public void serviceRemoved(AxisService service) {
            internalStopListeningForService(service);
        }
    });
    // register with JMX
    if (mbeanSupport == null) {
        // FIXME <-- workaround for AXIS2-4552
        mbeanSupport = new TransportMBeanSupport(this, getTransportName());
        mbeanSupport.register();
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisServiceTracker(org.apache.axis2.transport.base.tracker.AxisServiceTracker) AxisServiceFilter(org.apache.axis2.transport.base.tracker.AxisServiceFilter) AxisServiceTrackerListener(org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener)

Aggregations

TransportInDescription (org.apache.axis2.description.TransportInDescription)7 AxisFault (org.apache.axis2.AxisFault)5 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)3 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 Map (java.util.Map)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 MessageContext (org.apache.axis2.context.MessageContext)2 Parameter (org.apache.axis2.description.Parameter)2 CustomAxisConfigurator (org.apache.axis2.transport.CustomAxisConfigurator)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 QName (javax.xml.namespace.QName)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 AxisService (org.apache.axis2.description.AxisService)1 ParameterIncludeImpl (org.apache.axis2.description.ParameterIncludeImpl)1 ListenerManager (org.apache.axis2.engine.ListenerManager)1 AxisServiceFilter (org.apache.axis2.transport.base.tracker.AxisServiceFilter)1 AxisServiceTracker (org.apache.axis2.transport.base.tracker.AxisServiceTracker)1