Search in sources :

Example 1 with TransportListener

use of org.apache.axis2.transport.TransportListener in project wso2-axis2-transports by wso2.

the class AxisTestEndpoint method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(LogManager logManager, AxisTestEndpointContext context, Channel channel, AxisServiceConfigurator[] configurators) throws Exception {
    this.context = context;
    TransportListener listener = context.getTransportListener();
    if (listener instanceof TransportErrorSource) {
        transportErrorSource = (TransportErrorSource) listener;
        errorListener = new TransportErrorListener() {

            public void error(TransportError error) {
                AxisService s = error.getService();
                if (s == null || s == service) {
                    onTransportError(error.getException());
                }
            }
        };
        transportErrorSource.addErrorListener(errorListener);
    } else {
        transportErrorSource = null;
    }
    String path;
    try {
        path = new URI(channel.getEndpointReference().getAddress()).getPath();
    } catch (URISyntaxException ex) {
        path = null;
    }
    String serviceName;
    if (path != null && path.startsWith(Channel.CONTEXT_PATH + "/")) {
        serviceName = path.substring(Channel.CONTEXT_PATH.length() + 1);
    } else {
        serviceName = "TestService-" + UUID.randomUUID();
    }
    service = new AxisService(serviceName);
    service.addOperation(createOperation());
    if (configurators != null) {
        for (AxisServiceConfigurator configurator : configurators) {
            configurator.setupService(service, false);
        }
    }
    // Output service parameters to log file
    // FIXME: This actually doesn't give the expected result because the AxisTestEndpoint might be reused
    // by several test cases and in that case the log file is only produced once
    List<Parameter> params = (List<Parameter>) service.getParameters();
    if (!params.isEmpty()) {
        PrintWriter log = new PrintWriter(logManager.createLog("service-parameters"), false);
        try {
            for (Parameter param : params) {
                log.print(param.getName());
                log.print("=");
                log.println(param.getValue());
            }
        } finally {
            log.close();
        }
    }
    // We want to receive all messages through the same operation:
    service.addParameter(AxisService.SUPPORT_SINGLE_OP, true);
    context.getAxisConfiguration().addService(service);
    // The transport may disable the service. In that case, fail directly.
    if (!BaseUtils.isUsingTransport(service, context.getTransportName())) {
        Assert.fail("The service has been disabled by the transport");
    }
}
Also used : TransportError(org.apache.axis2.transport.base.event.TransportError) AxisServiceConfigurator(org.apache.axis2.transport.testkit.axis2.AxisServiceConfigurator) AxisService(org.apache.axis2.description.AxisService) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) TransportErrorSource(org.apache.axis2.transport.base.event.TransportErrorSource) TransportListener(org.apache.axis2.transport.TransportListener) TransportErrorListener(org.apache.axis2.transport.base.event.TransportErrorListener) Parameter(org.apache.axis2.description.Parameter) List(java.util.List) PrintWriter(java.io.PrintWriter) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Example 2 with TransportListener

use of org.apache.axis2.transport.TransportListener in project wso2-synapse by wso2.

the class Axis2TransportHelper method getPendingListenerThreadCount.

/**
 * Determines the total number of pending listener threads (active + queued).
 *
 * @return the total number of pending listener threads (active + queued).
 */
public int getPendingListenerThreadCount() {
    int pendingThreads = 0;
    Map<String, TransportInDescription> trpIns = configurationContext.getAxisConfiguration().getTransportsIn();
    for (TransportInDescription trpIn : trpIns.values()) {
        TransportListener trpLst = trpIn.getReceiver();
        if (trpLst instanceof ManagementSupport) {
            int inUse = ((ManagementSupport) trpLst).getActiveThreadCount();
            int inQue = ((ManagementSupport) trpLst).getQueueSize();
            if ((inUse + inQue) > 0) {
                if (log.isDebugEnabled()) {
                    log.debug(new StringBuilder("Transport Listener : ").append(trpIn.getName()).append(" currently using : ").append(inUse).append(" threads with ").append(inQue).append(" requests already queued...").toString());
                }
                pendingThreads = (inUse + inQue);
            }
        }
    }
    return pendingThreads;
}
Also used : TransportListener(org.apache.axis2.transport.TransportListener) TransportInDescription(org.apache.axis2.description.TransportInDescription) ManagementSupport(org.apache.axis2.transport.base.ManagementSupport)

Example 3 with TransportListener

use of org.apache.axis2.transport.TransportListener in project wso2-synapse by wso2.

the class HttpWebSocketInboundEndpointHandler method createTransportInDescription.

private static TransportInDescription createTransportInDescription(String transportName, TransportListener transportListener, HttpWebSocketInboundEndpointConfiguration httpWebSocketConfig) throws AxisFault {
    TransportInDescription transportInDescription = new TransportInDescription(transportName);
    transportInDescription.setReceiver(transportListener);
    // populate parameters
    addParameter(transportInDescription, BridgeConstants.PORT_PARAM, httpWebSocketConfig.getPort());
    addParameter(transportInDescription, BridgeConstants.HOSTNAME_PARAM, httpWebSocketConfig.getHostname());
    addParameter(transportInDescription, BridgeConstants.HTTP_PROTOCOL_VERSION_PARAM, httpWebSocketConfig.getHttpProtocolVersion());
    SSLConfiguration sslConfiguration = httpWebSocketConfig.getSslConfiguration();
    // SSLConfiguration will be null for non-secured transport. Hence, need to do the null check here.
    if (Objects.nonNull(sslConfiguration)) {
        populateSSLParameters(sslConfiguration, transportInDescription);
    }
    return transportInDescription;
}
Also used : SSLConfiguration(org.apache.synapse.transport.netty.api.config.SSLConfiguration) TransportInDescription(org.apache.axis2.description.TransportInDescription)

Example 4 with TransportListener

use of org.apache.axis2.transport.TransportListener in project wso2-synapse by wso2.

the class HttpWebSocketInboundEndpointHandler method startServer.

private static boolean startServer(Axis2HttpTransportListener transportListener, String transportName, HttpWebSocketInboundEndpointConfiguration httpWebSocketConfig, ConfigurationContext configurationContext) {
    TransportInDescription transportInDescription;
    try {
        // Generate the TransportInDescription and add it to the ConfigurationContext
        transportInDescription = createTransportInDescription(transportName, transportListener, httpWebSocketConfig);
    } catch (AxisFault e) {
        logStartupError(e, "Error occurred while generating TransportInDescription. Hence, ", httpWebSocketConfig, transportName);
        return false;
    }
    try {
        // Initialize the Axis2HttpTransportListener and set MessagingHandlers
        transportListener.init(configurationContext, transportInDescription);
        transportListener.setMessagingHandlers(httpWebSocketConfig.getInboundEndpointHandlers());
    } catch (AxisFault e) {
        logStartupError(e, "Error occurred while initializing the " + transportName + " transport listener. Hence, ", httpWebSocketConfig, transportName);
        return false;
    }
    try {
        transportListener.start();
        // If the transport it started successfully, store it in the transportListenerMap against the port. This
        // map will be used when stopping the listener.
        transportListenerMap.put(httpWebSocketConfig.getPort(), transportListener);
    } catch (AxisFault e) {
        logStartupError(e, "Error occurred while generating TransportInDescription. Hence, ", httpWebSocketConfig, transportName);
        return false;
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) TransportInDescription(org.apache.axis2.description.TransportInDescription)

Example 5 with TransportListener

use of org.apache.axis2.transport.TransportListener in project wso2-synapse by wso2.

the class HttpWebSocketInboundEndpointHandler method closeEndpoint.

/**
 * Close ListeningEndpoint running on the given port.
 *
 * @param port Port of  ListeningEndpoint to be closed
 * @return IS successfully closed
 */
public static boolean closeEndpoint(int port) {
    LOG.info("Closing Endpoint Listener for port " + port);
    TransportListener listener = transportListenerMap.get(port);
    if (Objects.nonNull(listener)) {
        try {
            listener.stop();
        } catch (AxisFault e) {
            LOG.error("Cannot close Endpoint relevant to port " + port, e);
            return false;
        } finally {
            int portCloseVerifyTimeout = DEFAULT_PORT_CLOSE_VERIFY_TIMEOUT;
            if (isPortCloseSuccess(port, portCloseVerifyTimeout)) {
                LOG.info("Successfully closed Endpoint Listener for port " + port);
            } else {
                LOG.warn("Port close verify timeout " + portCloseVerifyTimeout + "s exceeded. " + "Endpoint Listener for port " + port + " still bound to the ListenerEndpoint.");
            }
        }
    }
    return true;
}
Also used : Axis2HttpTransportListener(org.apache.synapse.transport.netty.listener.Axis2HttpTransportListener) TransportListener(org.apache.axis2.transport.TransportListener) Axis2HttpSSLTransportListener(org.apache.synapse.transport.netty.listener.Axis2HttpSSLTransportListener) AxisFault(org.apache.axis2.AxisFault)

Aggregations

TransportInDescription (org.apache.axis2.description.TransportInDescription)3 TransportListener (org.apache.axis2.transport.TransportListener)3 AxisFault (org.apache.axis2.AxisFault)2 PrintWriter (java.io.PrintWriter)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 AxisService (org.apache.axis2.description.AxisService)1 Parameter (org.apache.axis2.description.Parameter)1 ManagementSupport (org.apache.axis2.transport.base.ManagementSupport)1 TransportError (org.apache.axis2.transport.base.event.TransportError)1 TransportErrorListener (org.apache.axis2.transport.base.event.TransportErrorListener)1 TransportErrorSource (org.apache.axis2.transport.base.event.TransportErrorSource)1 AxisServiceConfigurator (org.apache.axis2.transport.testkit.axis2.AxisServiceConfigurator)1 Setup (org.apache.axis2.transport.testkit.tests.Setup)1 SSLConfiguration (org.apache.synapse.transport.netty.api.config.SSLConfiguration)1 Axis2HttpSSLTransportListener (org.apache.synapse.transport.netty.listener.Axis2HttpSSLTransportListener)1 Axis2HttpTransportListener (org.apache.synapse.transport.netty.listener.Axis2HttpTransportListener)1