Search in sources :

Example 36 with Bus

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));
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.camel.Message) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) WebClient(org.apache.cxf.jaxrs.client.WebClient) GenericType(javax.ws.rs.core.GenericType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) CookieHandler(org.apache.camel.http.common.cookie.CookieHandler)

Example 37 with Bus

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);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 38 with Bus

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());
}
Also used : AssertionBuilderRegistry(org.apache.cxf.ws.policy.AssertionBuilderRegistry) Bus(org.apache.cxf.Bus) OpenAMSessionTokenServerAssertionBuilder(org.forgerock.openam.sts.soap.policy.am.OpenAMSessionTokenServerAssertionBuilder) PolicyInterceptorProviderRegistry(org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry)

Example 39 with Bus

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);
    }
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) OnBehalfOfServiceIface(org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface) URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) WrapThreadContextClassLoader(org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)

Example 40 with Bus

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);
    }
}
Also used : Bus(org.apache.cxf.Bus) ActAsServiceIface(org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface) ServiceIface(org.jboss.as.test.integration.ws.wsse.trust.service.ServiceIface) OnBehalfOfServiceIface(org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) IOException(java.io.IOException) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) WrapThreadContextClassLoader(org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)

Aggregations

Bus (org.apache.cxf.Bus)57 Test (org.junit.Test)31 URL (java.net.URL)19 QName (javax.xml.namespace.QName)15 Service (javax.xml.ws.Service)12 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)11 Exchange (org.apache.cxf.message.Exchange)9 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)9 Message (org.apache.cxf.message.Message)9 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)9 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)9 WrapThreadContextClassLoader (org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)9 ServiceIface (org.jboss.as.test.integration.ws.wsse.trust.service.ServiceIface)7 IOException (java.io.IOException)6 ActAsServiceIface (org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface)6 OnBehalfOfServiceIface (org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface)6 CamelContext (org.apache.camel.CamelContext)4 Message (org.apache.camel.Message)4 Greeter (org.apache.camel.hello_world_soap_http.Greeter)4 GreeterService (org.apache.camel.hello_world_soap_http.GreeterService)4