Search in sources :

Example 46 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class HTTPConduitTest method testGetTarget.

/**
 * This test verfies that the "getTarget() call returns the correct
 * EndpointReferenceType for the given endpoint address.
 */
@Test
public void testGetTarget() throws Exception {
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    conduit.finalizeConfig();
    EndpointReferenceType target = EndpointReferenceUtils.getEndpointReference("http://nowhere.com/bar/foo");
    // Test call
    EndpointReferenceType ref = conduit.getTarget();
    assertNotNull("unexpected null target", ref);
    assertEquals("unexpected target", EndpointReferenceUtils.getAddress(ref), EndpointReferenceUtils.getAddress(target));
    assertEquals("unexpected address", conduit.getAddress(), "http://nowhere.com/bar/foo");
    assertEquals("unexpected on-demand URL", conduit.getURI().getPath(), "/bar/foo");
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 47 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class HTTPConduitTest method testHandleResponseOnWorkqueueAllowCurrentThread.

@Test
public void testHandleResponseOnWorkqueueAllowCurrentThread() throws Exception {
    Message m = getNewMessage();
    Exchange exchange = new ExchangeImpl();
    Bus bus = new ExtensionManagerBus();
    exchange.put(Bus.class, bus);
    EndpointInfo endpointInfo = new EndpointInfo();
    Endpoint endpoint = new EndpointImpl(null, null, endpointInfo);
    exchange.put(Endpoint.class, endpoint);
    m.setExchange(exchange);
    HTTPClientPolicy policy = new HTTPClientPolicy();
    policy.setAsyncExecuteTimeoutRejection(true);
    m.put(HTTPClientPolicy.class, policy);
    exchange.put(Executor.class, new Executor() {

        @Override
        public void execute(Runnable command) {
            // forces us to use current thread
            throw new RejectedExecutionException("expected");
        }
    });
    HTTPConduit conduit = new MockHTTPConduit(bus, endpointInfo, policy);
    OutputStream os = conduit.createOutputStream(m, false, false, 0);
    assertTrue(os instanceof WrappedOutputStream);
    WrappedOutputStream wos = (WrappedOutputStream) os;
    try {
        wos.handleResponseOnWorkqueue(true, false);
        assertEquals(Thread.currentThread(), m.get(Thread.class));
        try {
            wos.handleResponseOnWorkqueue(false, false);
            fail("Expected RejectedExecutionException not thrown");
        } catch (RejectedExecutionException ex) {
            assertEquals("expected", ex.getMessage());
        }
    } catch (Exception ex) {
        throw ex;
    }
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Message(org.apache.cxf.message.Message) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) WrappedOutputStream(org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream) OutputStream(java.io.OutputStream) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Executor(java.util.concurrent.Executor) Endpoint(org.apache.cxf.endpoint.Endpoint) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) WrappedOutputStream(org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 48 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class HttpConduitConfigApplierTest method testTrustVerificationEnabled.

@Test
public void testTrustVerificationEnabled() throws IOException {
    HttpConduitConfigApplier configApplier = new HttpConduitConfigApplier();
    Dictionary<String, String> configValues = new Hashtable<>();
    configValues.put("tlsClientParameters.disableCNCheck", "true");
    configValues.put("tlsClientParameters.trustManagers.disableTrustVerification", "false");
    String address = "https://localhost:12345";
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(address);
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    configApplier.apply(configValues, conduit, address);
    assertNotNull(conduit.getTlsClientParameters().getTrustManagers());
    assertEquals(conduit.getTlsClientParameters().getTrustManagers().length, 1);
    assertFalse(conduit.getTlsClientParameters().getTrustManagers()[0].getClass().getName().startsWith(InsecureTrustManager.class.getName()));
    assertTrue(conduit.getTlsClientParameters().isDisableCNCheck());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) URLConnectionHTTPConduit(org.apache.cxf.transport.http.URLConnectionHTTPConduit) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Hashtable(java.util.Hashtable) URLConnectionHTTPConduit(org.apache.cxf.transport.http.URLConnectionHTTPConduit) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 49 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class HttpConduitConfigApplierTest method testNormalTrustLoading.

@Test
public void testNormalTrustLoading() throws IOException {
    HttpConduitConfigApplier configApplier = new HttpConduitConfigApplier();
    Dictionary<String, String> configValues = new Hashtable<>();
    configValues.put("tlsClientParameters.disableCNCheck", "false");
    String address = "https://localhost:12345";
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(address);
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    configApplier.apply(configValues, conduit, address);
    assertNull(conduit.getTlsClientParameters().getTrustManagers());
    assertFalse(conduit.getTlsClientParameters().isDisableCNCheck());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) URLConnectionHTTPConduit(org.apache.cxf.transport.http.URLConnectionHTTPConduit) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Hashtable(java.util.Hashtable) URLConnectionHTTPConduit(org.apache.cxf.transport.http.URLConnectionHTTPConduit) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 50 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class HttpConduitConfigApplierTest method testDisableTrustVerification.

@Test
public void testDisableTrustVerification() throws IOException {
    HttpConduitConfigApplier configApplier = new HttpConduitConfigApplier();
    Dictionary<String, String> configValues = new Hashtable<>();
    configValues.put("tlsClientParameters.disableCNCheck", "true");
    configValues.put("tlsClientParameters.trustManagers.disableTrustVerification", "true");
    String address = "https://localhost:12345";
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(address);
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    configApplier.apply(configValues, conduit, address);
    assertNotNull(conduit.getTlsClientParameters().getTrustManagers());
    assertEquals(conduit.getTlsClientParameters().getTrustManagers().length, 1);
    assertTrue(conduit.getTlsClientParameters().getTrustManagers()[0].getClass().getName().startsWith(InsecureTrustManager.class.getName()));
    assertTrue(conduit.getTlsClientParameters().isDisableCNCheck());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) URLConnectionHTTPConduit(org.apache.cxf.transport.http.URLConnectionHTTPConduit) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Hashtable(java.util.Hashtable) URLConnectionHTTPConduit(org.apache.cxf.transport.http.URLConnectionHTTPConduit) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Aggregations

ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)59 Bus (org.apache.cxf.Bus)48 Test (org.junit.Test)44 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)28 Message (org.apache.cxf.message.Message)14 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)14 QName (javax.xml.namespace.QName)8 DestinationRegistry (org.apache.cxf.transport.http.DestinationRegistry)8 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)7 ArrayList (java.util.ArrayList)6 AtmosphereInterceptor (org.atmosphere.cpr.AtmosphereInterceptor)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 URL (java.net.URL)4 List (java.util.List)4 ASMHelperImpl (org.apache.cxf.common.util.ASMHelperImpl)4 MessageObserver (org.apache.cxf.transport.MessageObserver)4 HTTPServerPolicy (org.apache.cxf.transports.http.configuration.HTTPServerPolicy)4 HttpURLConnection (java.net.HttpURLConnection)3 Hashtable (java.util.Hashtable)3