use of org.apache.cxf.Bus in project camel by apache.
the class CxfRsProducer method invokeAsyncHttpClient.
protected void invokeAsyncHttpClient(Exchange exchange, final AsyncCallback callback) throws Exception {
Message inMessage = exchange.getIn();
JAXRSClientFactoryBean cfb = clientFactoryBeanCache.get(CxfEndpointUtils.getEffectiveAddress(exchange, ((CxfRsEndpoint) getEndpoint()).getAddress()));
Bus bus = ((CxfRsEndpoint) getEndpoint()).getBus();
// We need to apply the bus setting from the CxfRsEndpoint which is not use the default bus
if (bus != null) {
cfb.setBus(bus);
}
WebClient client = cfb.createWebClient();
((CxfRsEndpoint) getEndpoint()).getChainedCxfRsEndpointConfigurer().configureClient(client);
String httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, String.class);
Class<?> responseClass = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Class.class);
Type genericType = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE, Type.class);
Object[] pathValues = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, Object[].class);
String path = inMessage.getHeader(Exchange.HTTP_PATH, String.class);
if (LOG.isTraceEnabled()) {
LOG.trace("HTTP method = {}", httpMethod);
LOG.trace("path = {}", path);
LOG.trace("responseClass = {}", responseClass);
}
// set the path
if (path != null) {
if (ObjectHelper.isNotEmpty(pathValues) && pathValues.length > 0) {
client.path(path, pathValues);
} else {
client.path(path);
}
}
CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
CxfRsBinding binding = cxfRsEndpoint.getBinding();
Object body = getBody(exchange, inMessage, httpMethod, cxfRsEndpoint, binding);
setupClientMatrix(client, exchange);
setupClientQueryAndHeaders(client, exchange);
//Build message entity
Entity<Object> entity = binding.bindCamelMessageToRequestEntity(body, inMessage, exchange);
// handle cookies
CookieHandler cookieHandler = ((CxfRsEndpoint) getEndpoint()).getCookieHandler();
loadCookies(exchange, client, cookieHandler);
// invoke the client
client.async().method(httpMethod, entity, new CxfInvocationCallback(client, exchange, cxfRsEndpoint, responseClass, callback, genericType));
}
use of org.apache.cxf.Bus in project camel by apache.
the class CamelDestinationTest method testCamelDestinationConfiguration.
@Test
public void testCamelDestinationConfiguration() throws Exception {
QName testEndpointQName = new QName("http://camel.apache.org/camel-test", "port");
// set up the bus with configure file
SpringBusFactory bf = new SpringBusFactory();
BusFactory.setDefaultBus(null);
Bus bus = bf.createBus("/org/apache/camel/component/cxf/transport/CamelDestination.xml");
BusFactory.setDefaultBus(bus);
endpointInfo.setAddress("camel://direct:EndpointA");
endpointInfo.setName(testEndpointQName);
CamelDestination destination = new CamelDestination(null, bus, null, endpointInfo);
assertEquals("{http://camel.apache.org/camel-test}port.camel-destination", destination.getBeanName());
CamelContext context = destination.getCamelContext();
assertNotNull("The camel context which get from camel destination is not null", context);
assertEquals("Get the wrong camel context", context.getName(), "dest_context");
assertEquals("The camel context should has two routers", context.getRoutes().size(), 2);
bus.shutdown(false);
}
use of org.apache.cxf.Bus in project OpenAM by OpenRock.
the class SoapSTSLifecycleImpl method registerCustomPolicyInterceptors.
/*
This method will register the OpenAMSessionToken AssertionBuilder and InterceptorProvider instances with the cxf
Bus, so that any OpenAMSessionToken SecurityPolicy bindings in any of the published soap-sts instances can be
supported. Note that this registration is global to all soap-sts instances published in this realm, as the AssertionBuilderRegistry
and the PolicyInterceptorProviderRegistry are global to a cxf Bus, and thus to a cxf deployment. This does not cause
problems however, as the OpenAM session validation which is consumed as part of realizing this interceptor context
is specific only to a realm, and each soap-sts deployment is realm specific (as it corresponds to a soap-sts-agent,
which is also realm-specific.) Note, however, if we wanted to support OpenID Connect ID tokens, then a global
interceptor would have to be registered which would ultimately consult sts-instance-specific state corresponding to the
authN context which would validate this OIDC id token, and the key used to look-up this instance-specific
state from the global interceptor would be the last url constituent of the soap-sts invocation (including any realm
elements), as this is the soap-sts-instance identifier.
*/
private void registerCustomPolicyInterceptors() {
final boolean createIfNecessary = false;
final Bus bus = BusFactory.getDefaultBus(createIfNecessary);
final PolicyInterceptorProviderRegistry policyInterceptorProviderRegistry = bus.getExtension(PolicyInterceptorProviderRegistry.class);
policyInterceptorProviderRegistry.register(openAMSessionTokenServerInterceptorProvider);
AssertionBuilderRegistry assertionBuilderRegistry = bus.getExtension(AssertionBuilderRegistry.class);
assertionBuilderRegistry.registerBuilder(AMSTSConstants.AM_SESSION_TOKEN_ASSERTION_QNAME, new OpenAMSessionTokenServerAssertionBuilder());
}
use of org.apache.cxf.Bus in project wildfly by wildfly.
the class WSTrustTestCase method testOnBehalfOf.
/**
* Request a security token that allows it to act on behalf of somebody else.
*
* @throws Exception
*/
@Test
@RunAsClient
@OperateOnDeployment(ON_BEHALF_OF_SERVER_DEP)
@WrapThreadContextClassLoader
public void testOnBehalfOf() throws Exception {
Bus bus = BusFactory.newInstance().createBus();
try {
BusFactory.setThreadDefaultBus(bus);
final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/onbehalfofwssecuritypolicy", "OnBehalfOfService");
final URL wsdlURL = new URL(serviceURL + "OnBehalfOfService?wsdl");
Service service = Service.create(wsdlURL, serviceName);
OnBehalfOfServiceIface proxy = (OnBehalfOfServiceIface) service.getPort(OnBehalfOfServiceIface.class);
WSTrustTestUtils.setupWsseAndSTSClientOnBehalfOf((BindingProvider) proxy, bus);
assertEquals("OnBehalfOf WS-Trust Hello World!", proxy.sayHello(serviceURL.getHost(), String.valueOf(serviceURL.getPort())));
} finally {
bus.shutdown(true);
}
}
use of org.apache.cxf.Bus in project wildfly by wildfly.
the class WSTrustTestCase method test.
/**
* WS-Trust test with the STS information programmatically provided
*
* @throws Exception
*/
@Test
@RunAsClient
@OperateOnDeployment(SERVER_DEP)
@WrapThreadContextClassLoader
public void test() throws Exception {
Bus bus = BusFactory.newInstance().createBus();
try {
BusFactory.setThreadDefaultBus(bus);
final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
final URL wsdlURL = new URL(serviceURL + "SecurityService?wsdl");
Service service = Service.create(wsdlURL, serviceName);
ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
final QName stsServiceName = new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "SecurityTokenService");
final QName stsPortName = new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "UT_Port");
URL stsURL = new URL(serviceURL.getProtocol(), serviceURL.getHost(), serviceURL.getPort(), "/jaxws-samples-wsse-policy-trust-sts/SecurityTokenService?wsdl");
WSTrustTestUtils.setupWsseAndSTSClient(proxy, bus, stsURL.toString(), stsServiceName, stsPortName);
try {
assertEquals("WS-Trust Hello World!", proxy.sayHello());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} finally {
bus.shutdown(true);
}
}
Aggregations