Search in sources :

Example 6 with PassThroughTransportMetricsCollector

use of org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector in project wso2-synapse by wso2.

the class PassThroughHttpListener method init.

public void init(ConfigurationContext cfgCtx, TransportInDescription transportInDescription) throws AxisFault {
    log.info("Initializing Pass-through HTTP/S Listener...");
    pttInDescription = transportInDescription;
    namePrefix = transportInDescription.getName().toUpperCase(Locale.US);
    scheme = initScheme();
    int portOffset = Integer.parseInt(System.getProperty("portOffset", "0"));
    Parameter portParam = transportInDescription.getParameter("port");
    int port = Integer.parseInt(portParam.getValue().toString());
    operatingPort = port + portOffset;
    portParam.setValue(String.valueOf(operatingPort));
    portParam.getParameterElement().setText(String.valueOf(operatingPort));
    System.setProperty(transportInDescription.getName() + ".nio.port", String.valueOf(operatingPort));
    Object obj = cfgCtx.getProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL);
    WorkerPool workerPool = null;
    if (obj != null) {
        workerPool = (WorkerPool) obj;
    }
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, scheme.getName());
    TransportView view = new TransportView(this, null, metrics, null);
    MBeanRegistrar.getInstance().registerMBean(view, "Transport", "passthru-" + namePrefix.toLowerCase() + "-receiver");
    sourceConfiguration = new SourceConfiguration(cfgCtx, transportInDescription, scheme, workerPool, metrics);
    sourceConfiguration.build();
    HttpHost host = new HttpHost(sourceConfiguration.getHostname(), sourceConfiguration.getPort(), sourceConfiguration.getScheme().getName());
    ServerConnFactoryBuilder connFactoryBuilder = initConnFactoryBuilder(transportInDescription, host);
    connFactory = connFactoryBuilder.build(sourceConfiguration.getHttpParams());
    handler = new SourceHandler(sourceConfiguration);
    passThroughListeningIOReactorManager = PassThroughListeningIOReactorManager.getInstance();
    // register to receive updates on services for lifetime management
    // cfgCtx.getAxisConfiguration().addObservers(axisObserver);
    String prefix = namePrefix + "-Listener I/O dispatcher";
    try {
        ioReactor = (DefaultListeningIOReactor) passThroughListeningIOReactorManager.initIOReactor(operatingPort, handler, new PassThroughSharedListenerConfiguration(new NativeThreadFactory(new ThreadGroup(prefix + " thread group"), prefix), connFactory, sourceConfiguration));
    } catch (IOReactorException e) {
        handleException("Error initiating " + namePrefix + " ListeningIOReactor", e);
    }
    Map<String, String> o = (Map<String, String>) cfgCtx.getProperty(PassThroughConstants.EPR_TO_SERVICE_NAME_MAP);
    if (o != null) {
        this.eprToServiceNameMap = o;
    } else {
        eprToServiceNameMap = new HashMap<String, String>();
        cfgCtx.setProperty(PassThroughConstants.EPR_TO_SERVICE_NAME_MAP, eprToServiceNameMap);
    }
    cfgCtx.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL, sourceConfiguration.getWorkerPool());
    /* register to receive updates on services */
    serviceTracker = new AxisServiceTracker(cfgCtx.getAxisConfiguration(), new AxisServiceFilter() {

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

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

        public void serviceRemoved(AxisService service) {
            removeServiceFfromURIMap(service);
        }
    });
}
Also used : PassThroughSharedListenerConfiguration(org.apache.synapse.transport.passthru.core.PassThroughSharedListenerConfiguration) AxisServiceFilter(org.apache.axis2.transport.base.tracker.AxisServiceFilter) AxisServiceTrackerListener(org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) AxisService(org.apache.axis2.description.AxisService) NativeThreadFactory(org.apache.axis2.transport.base.threads.NativeThreadFactory) IOReactorException(org.apache.http.nio.reactor.IOReactorException) AxisServiceTracker(org.apache.axis2.transport.base.tracker.AxisServiceTracker) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) HttpHost(org.apache.http.HttpHost) TransportView(org.apache.synapse.transport.passthru.jmx.TransportView) SourceConfiguration(org.apache.synapse.transport.passthru.config.SourceConfiguration) Parameter(org.apache.axis2.description.Parameter) Map(java.util.Map) HashMap(java.util.HashMap) ServerConnFactoryBuilder(org.apache.synapse.transport.nhttp.config.ServerConnFactoryBuilder)

Example 7 with PassThroughTransportMetricsCollector

use of org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector in project wso2-synapse by wso2.

the class TargetHandlerTest method testOutputReady.

/**
 * Testing whether output-ready connection is processed
 *
 * @throws Exception
 */
@Test
public void testOutputReady() throws Exception {
    DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
    ClientConnFactory connFactory = mock(ClientConnFactory.class);
    ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
    WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
    TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
    TargetContext targetContext = new TargetContext(targetConfiguration);
    MessageContext messageContext = new MessageContext();
    targetContext.setRequestMsgCtx(messageContext);
    TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
    TargetRequest request = mock(TargetRequest.class);
    NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
    ContentEncoder encoder = mock(ContentEncoder.class);
    mockStatic(TargetContext.class);
    when(TargetContext.get(conn)).thenReturn(targetContext);
    when(TargetContext.getState(conn)).thenReturn(ProtocolState.REQUEST_HEAD);
    when(TargetContext.getRequest(conn)).thenReturn(request);
    when(request.hasEntityBody()).thenReturn(true);
    when(request.write(conn, encoder)).thenReturn(12);
    when(encoder.isCompleted()).thenReturn(true);
    targetHandler.outputReady(conn, encoder);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) ContentEncoder(org.apache.http.nio.ContentEncoder) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ClientConnFactory(org.apache.synapse.transport.http.conn.ClientConnFactory) MessageContext(org.apache.axis2.context.MessageContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with PassThroughTransportMetricsCollector

use of org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector in project wso2-synapse by wso2.

the class TargetHandlerTest method testInputReady.

/**
 * Testing whether input-ready connection is processed
 *
 * @throws Exception
 */
@Test
public void testInputReady() throws Exception {
    DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
    ClientConnFactory connFactory = mock(ClientConnFactory.class);
    ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
    WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
    TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
    TargetContext targetContext = new TargetContext(targetConfiguration);
    MessageContext messageContext = new MessageContext();
    targetContext.setRequestMsgCtx(messageContext);
    TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
    TargetResponse response = mock(TargetResponse.class);
    NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
    ContentDecoder decoder = mock(ContentDecoder.class);
    mockStatic(TargetContext.class);
    when(TargetContext.get(conn)).thenReturn(targetContext);
    when(TargetContext.getState(conn)).thenReturn(ProtocolState.RESPONSE_HEAD);
    when(TargetContext.getResponse(conn)).thenReturn(response);
    when(decoder.isCompleted()).thenReturn(true);
    targetHandler.inputReady(conn, decoder);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ContentDecoder(org.apache.http.nio.ContentDecoder) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ClientConnFactory(org.apache.synapse.transport.http.conn.ClientConnFactory) MessageContext(org.apache.axis2.context.MessageContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with PassThroughTransportMetricsCollector

use of org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector in project wso2-synapse by wso2.

the class SourceConfigurationTest method setUp.

@Before
public void setUp() throws Exception {
    Parameter portParam = new Parameter("port", PORT);
    portParam.setParameterElement(AXIOMUtil.stringToOM("<parameter name=\"port\" locked=\"false\">" + PORT + "</parameter>"));
    Parameter hostParam = new Parameter("hostname", HOST);
    transportInDescription.addParameter(portParam);
    transportInDescription.addParameter(hostParam);
    cfgCtx = new ConfigurationContext(new AxisConfiguration());
    cfgCtx.setServicePath("services");
    cfgCtx.setContextRoot("/");
    scheme = new Scheme(transportInDescription.getName(), PORT, false);
    metrics = new PassThroughTransportMetricsCollector(true, scheme.getName());
    sourceConfiguration = new SourceConfiguration(cfgCtx, transportInDescription, scheme, PassThroughTestUtils.getWorkerPool(passThroughConfiguration), metrics);
    sourceConfiguration.build();
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Scheme(org.apache.synapse.transport.http.conn.Scheme) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) Parameter(org.apache.axis2.description.Parameter) Before(org.junit.Before)

Example 10 with PassThroughTransportMetricsCollector

use of org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector in project wso2-synapse by wso2.

the class TargetConfigurationTest method setUp.

@Before
public void setUp() throws Exception {
    ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
    WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
    configurationContext.setProperty(PASS_THROUGH_TRANSPORT_WORKER_POOL, workerPool);
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
    targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
    targetConfiguration.build();
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) Before(org.junit.Before)

Aggregations

PassThroughTransportMetricsCollector (org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector)10 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)8 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)8 WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)8 NativeWorkerPool (org.apache.axis2.transport.base.threads.NativeWorkerPool)6 TargetConfiguration (org.apache.synapse.transport.passthru.config.TargetConfiguration)6 NHttpClientConnection (org.apache.http.nio.NHttpClientConnection)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Parameter (org.apache.axis2.description.Parameter)3 HttpResponse (org.apache.http.HttpResponse)3 TargetConnections (org.apache.synapse.transport.passthru.connections.TargetConnections)3 Before (org.junit.Before)3 MessageContext (org.apache.axis2.context.MessageContext)2 NativeThreadFactory (org.apache.axis2.transport.base.threads.NativeThreadFactory)2 ContentDecoder (org.apache.http.nio.ContentDecoder)2 IOReactorException (org.apache.http.nio.reactor.IOReactorException)2 ClientConnFactory (org.apache.synapse.transport.http.conn.ClientConnFactory)2 Scheme (org.apache.synapse.transport.http.conn.Scheme)2 TransportView (org.apache.synapse.transport.passthru.jmx.TransportView)2