Search in sources :

Example 16 with ExtensionManagerBus

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

the class HTTPConduitTest method testAuthPolicyPrecedence.

/**
 * This test verifies the precedence of Authorization Information.
 * Setting authorization information on the Message takes precedence
 * over a Basic Auth Supplier with preemptive UserPass, and that
 * followed by setting it directly on the Conduit.
 */
@Test
public void testAuthPolicyPrecedence() 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();
    conduit.getAuthorization().setUserName("Satan");
    conduit.getAuthorization().setPassword("hell");
    Message message = getNewMessage();
    // Test call
    conduit.prepare(message);
    Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
    assertNotNull("Authorization Header should exist", headers.get("Authorization"));
    assertEquals("Unexpected Authorization Token", DefaultBasicAuthSupplier.getBasicAuthHeader("Satan", "hell"), headers.get("Authorization").get(0));
    // Setting a Basic Auth User Pass should override
    conduit.setAuthSupplier(new TestAuthSupplier());
    message = getNewMessage();
    // Test Call
    conduit.prepare(message);
    headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
    List<String> authorization = headers.get("Authorization");
    assertNotNull("Authorization Token must be set", authorization);
    assertEquals("Wrong Authorization Token", "myauth", authorization.get(0));
    conduit.setAuthSupplier(null);
    // Setting authorization policy on the message should override
    // conduit setting
    AuthorizationPolicy authPolicy = new AuthorizationPolicy();
    authPolicy.setUserName("Hello");
    authPolicy.setPassword("world");
    authPolicy.setAuthorizationType("Basic");
    message = getNewMessage();
    message.put(AuthorizationPolicy.class, authPolicy);
    conduit.prepare(message);
    headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
    assertEquals("Unexpected Authorization Token", DefaultBasicAuthSupplier.getBasicAuthHeader("Hello", "world"), headers.get("Authorization").get(0));
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Message(org.apache.cxf.message.Message) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) ArrayList(java.util.ArrayList) List(java.util.List) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 17 with ExtensionManagerBus

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

the class HTTPConduitURLEasyMockTest method setUpConduit.

private HTTPConduit setUpConduit(boolean send, boolean autoRedirect, String method) throws Exception {
    endpointInfo = new EndpointInfo();
    endpointInfo.setAddress(NOWHERE + "bar/foo");
    connectionFactory = control.createMock(HttpsURLConnectionFactory.class);
    if (send) {
        // proxy = control.createMock(Proxy.class);
        proxy = Proxy.NO_PROXY;
        connection = control.createMock(HttpURLConnection.class);
        connection.getURL();
        EasyMock.expectLastCall().andReturn(new URL(NOWHERE + "bar/foo")).anyTimes();
        connectionFactory.createConnection((TLSClientParameters) EasyMock.isNull(), EasyMock.eq(proxy), EasyMock.eq(new URL(NOWHERE + "bar/foo")));
        EasyMock.expectLastCall().andReturn(connection);
        connection.setDoOutput(true);
        EasyMock.expectLastCall();
        connection.setRequestMethod(method);
        EasyMock.expectLastCall();
        if (!autoRedirect && "POST".equals(method)) {
            connection.setChunkedStreamingMode(-1);
            EasyMock.expectLastCall();
        }
        connection.getRequestMethod();
        EasyMock.expectLastCall().andReturn(method).anyTimes();
        connection.setInstanceFollowRedirects(false);
        EasyMock.expectLastCall().times(1);
        connection.setConnectTimeout(303030);
        EasyMock.expectLastCall();
        connection.setReadTimeout(404040);
        EasyMock.expectLastCall();
        connection.setUseCaches(false);
        EasyMock.expectLastCall();
    }
    ExtensionManagerBus bus = new ExtensionManagerBus();
    control.replay();
    HTTPConduit conduit = new HTTPTestConduit(bus, endpointInfo, null, connectionFactory);
    conduit.finalizeConfig();
    if (send) {
        conduit.getClient().setConnectionTimeout(303030);
        conduit.getClient().setReceiveTimeout(404040);
        conduit.getClient().setAutoRedirect(autoRedirect);
        if (!autoRedirect) {
            conduit.getClient().setAllowChunking(true);
            conduit.getClient().setChunkingThreshold(0);
        }
    }
    observer = new MessageObserver() {

        public void onMessage(Message m) {
            inMessage = m;
        }
    };
    conduit.setMessageObserver(observer);
    return conduit;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HttpsURLConnectionFactory(org.apache.cxf.transport.https.HttpsURLConnectionFactory) HttpURLConnection(java.net.HttpURLConnection) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) URL(java.net.URL)

Example 18 with ExtensionManagerBus

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

the class HTTPConduitURLConnectionTest method doTestTLSServerParameters.

private Object doTestTLSServerParameters() throws Exception {
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("https://secure.nowhere.null/" + "bar/foo");
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    conduit.finalizeConfig();
    Message message = getNewMessage();
    // We need an SSL policy, or we can't use "https".
    conduit.setTlsClientParameters(new TLSClientParameters());
    // Test call
    conduit.prepare(message);
    return message.get("http.connection");
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) Message(org.apache.cxf.message.Message) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus)

Example 19 with ExtensionManagerBus

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

the class BusExtensionLoadingTest method testBusConstructionWithoutTCCL.

/**
 * Tests the ExtensionManagerBus can be built using a given classloader
 *
 * @throws Exception
 */
@Test
public void testBusConstructionWithoutTCCL() throws Exception {
    ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(new TestClassLoader());
        BusFactory factory = new CXFBusFactory() {

            public Bus createBus(Map<Class<?>, Object> e, Map<String, Object> properties) {
                return new ExtensionManagerBus(e, properties, this.getClass().getClassLoader());
            }
        };
        Bus bus = factory.createBus();
        assertNotNullExtensions(bus);
        bus.shutdown(true);
    } finally {
        Thread.currentThread().setContextClassLoader(origClassLoader);
    }
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) CXFBusFactory(org.apache.cxf.bus.CXFBusFactory) BusFactory(org.apache.cxf.BusFactory) Map(java.util.Map) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) CXFBusFactory(org.apache.cxf.bus.CXFBusFactory) Test(org.junit.Test)

Example 20 with ExtensionManagerBus

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

the class AtmosphereWebSocketServletDestinationTest method testRegisteration.

@Test
public void testRegisteration() throws Exception {
    Bus bus = new ExtensionManagerBus();
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);
    TestAtmosphereWebSocketServletDestination dest = new TestAtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);
    dest.activate();
    assertNotNull(registry.getDestinationForPath(ENDPOINT_ADDRESS));
    dest.deactivate();
    assertNull(registry.getDestinationForPath(ENDPOINT_ADDRESS));
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) 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