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));
}
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;
}
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");
}
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);
}
}
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));
}
Aggregations