Search in sources :

Example 11 with Bus

use of org.apache.cxf.Bus in project camel by apache.

the class CxfConsumerWSRMTest method testInvokeGreeter.

@Test
public void testInvokeGreeter() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Bus clientBus = context.getRegistry().lookupByNameAndType("client-bus", Bus.class);
    assertNotNull(clientBus);
    BusFactory.setThreadDefaultBus(clientBus);
    try {
        Service service = Service.create(SERVICE_NAME);
        service.addPort(PORT_NAME, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + CXFTestSupport.getPort1() + "/CxfConsumerWSRMTest/router");
        Greeter greeter = service.getPort(PORT_NAME, Greeter.class);
        greeter.greetMeOneWay("test");
    } finally {
        BusFactory.setThreadDefaultBus(null);
    }
    assertMockEndpointsSatisfied();
}
Also used : Bus(org.apache.cxf.Bus) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Greeter(org.apache.hello_world_soap_http.Greeter) Service(javax.xml.ws.Service) Test(org.junit.Test)

Example 12 with Bus

use of org.apache.cxf.Bus in project cas by apereo.

the class SecurityTokenServiceClientBuilder method buildClientForRelyingPartyTokenResponses.

/**
     * Build client for relying party token responses.
     *
     * @param securityToken the security token
     * @param service       the service
     * @return the security token service client
     */
public SecurityTokenServiceClient buildClientForRelyingPartyTokenResponses(final SecurityToken securityToken, final WSFederationRegisteredService service) {
    final Bus cxfBus = BusFactory.getDefaultBus();
    final SecurityTokenServiceClient sts = new SecurityTokenServiceClient(cxfBus);
    sts.setAddressingNamespace(StringUtils.defaultIfBlank(service.getAddressingNamespace(), WSFederationConstants.HTTP_WWW_W3_ORG_2005_08_ADDRESSING));
    sts.setWsdlLocation(prepareWsdlLocation(service));
    final String namespace = StringUtils.defaultIfBlank(service.getNamespace(), WSFederationConstants.HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512);
    sts.setServiceQName(new QName(namespace, service.getWsdlService()));
    sts.setEndpointQName(new QName(namespace, service.getWsdlEndpoint()));
    sts.setEnableAppliesTo(StringUtils.isNotBlank(service.getAppliesTo()));
    sts.setOnBehalfOf(securityToken.getToken());
    sts.setKeyType(WSFederationConstants.HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512_BEARER);
    sts.setTokenType(StringUtils.defaultIfBlank(service.getTokenType(), WSConstants.WSS_SAML2_TOKEN_TYPE));
    if (StringUtils.isNotBlank(service.getPolicyNamespace())) {
        sts.setWspNamespace(service.getPolicyNamespace());
    }
    return sts;
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName)

Example 13 with Bus

use of org.apache.cxf.Bus in project Activiti by Activiti.

the class CxfWSDLImporter method importFrom.

public void importFrom(String url) {
    this.wsServices.clear();
    this.wsOperations.clear();
    this.structures.clear();
    this.wsdlLocation = url;
    try {
        Bus bus = BusFactory.getDefaultBus();
        final Enumeration<URL> xjcBindingUrls = Thread.currentThread().getContextClassLoader().getResources(JAXB_BINDINGS_RESOURCE);
        if (xjcBindingUrls.hasMoreElements()) {
            final URL xjcBindingUrl = xjcBindingUrls.nextElement();
            if (xjcBindingUrls.hasMoreElements()) {
                throw new ActivitiException("Several JAXB binding definitions found for activiti-cxf: " + JAXB_BINDINGS_RESOURCE);
            }
            DynamicClientFactory.newInstance(bus).createClient(url, Arrays.asList(new String[] { xjcBindingUrl.toString() }));
            WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
            Definition def = wsdlManager.getDefinition(url);
            WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
            List<ServiceInfo> services = builder.buildServices(def);
            for (ServiceInfo service : services) {
                WSService wsService = this.importService(service);
                this.wsServices.put(this.namespace + wsService.getName(), wsService);
            }
            if (def != null && def.getTypes() != null) {
                this.importTypes(def.getTypes());
            }
        } else {
            throw new ActivitiException("The JAXB binding definitions are not found for activiti-cxf: " + JAXB_BINDINGS_RESOURCE);
        }
    } catch (WSDLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        throw new ActivitiException("Error retrieveing the JAXB binding definitions", e);
    }
}
Also used : Bus(org.apache.cxf.Bus) ActivitiException(org.activiti.engine.ActivitiException) WSDLException(javax.wsdl.WSDLException) StructureDefinition(org.activiti.engine.impl.bpmn.data.StructureDefinition) SimpleStructureDefinition(org.activiti.engine.impl.bpmn.data.SimpleStructureDefinition) Definition(javax.wsdl.Definition) PrimitiveStructureDefinition(org.activiti.engine.impl.bpmn.data.PrimitiveStructureDefinition) IOException(java.io.IOException) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) WSDLManager(org.apache.cxf.wsdl.WSDLManager)

Example 14 with Bus

use of org.apache.cxf.Bus in project wildfly by wildfly.

the class OnBehalfOfServiceImpl method sayHello.

public String sayHello(String host, String port) {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        final String serviceURL = "http://" + host + ":" + port + "/jaxws-samples-wsse-policy-trust/SecurityService";
        final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
        final URL wsdlURL = new URL(serviceURL + "?wsdl");
        Service service = Service.create(wsdlURL, serviceName);
        ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
        Map<String, Object> ctx = ((BindingProvider) proxy).getRequestContext();
        ctx.put(SecurityConstants.CALLBACK_HANDLER, new OnBehalfOfCallbackHandler());
        ctx.put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("actasKeystore.properties"));
        ctx.put(SecurityConstants.SIGNATURE_USERNAME, "myactaskey");
        ctx.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("../../META-INF/clientKeystore.properties"));
        ctx.put(SecurityConstants.ENCRYPT_USERNAME, "myservicekey");
        STSClient stsClient = new STSClient(bus);
        Map<String, Object> props = stsClient.getProperties();
        //-rls test
        props.put(SecurityConstants.USERNAME, "bob");
        props.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
        props.put(SecurityConstants.STS_TOKEN_USERNAME, "myactaskey");
        props.put(SecurityConstants.STS_TOKEN_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("actasKeystore.properties"));
        props.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
        ctx.put(SecurityConstants.STS_CLIENT, stsClient);
        return "OnBehalfOf " + proxy.sayHello();
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) MalformedURLException(java.net.MalformedURLException) ServiceIface(org.jboss.as.test.integration.ws.wsse.trust.service.ServiceIface) QName(javax.xml.namespace.QName) WebService(javax.jws.WebService) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL)

Example 15 with Bus

use of org.apache.cxf.Bus in project wildfly by wildfly.

the class WSTrustTestCase method testHolderOfKey.

@Test
@RunAsClient
@OperateOnDeployment(HOLDER_OF_KEY_SERVER_DEP)
@WrapThreadContextClassLoader
public void testHolderOfKey() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/holderofkeywssecuritypolicy", "HolderOfKeyService");
        final URL wsdlURL = new URL("https", serviceURL.getHost(), serviceURL.getPort() - 8080 + 8444, "/jaxws-samples-wsse-policy-trust-holderofkey/HolderOfKeyService?wsdl");
        Service service = Service.create(wsdlURL, serviceName);
        HolderOfKeyIface proxy = (HolderOfKeyIface) service.getPort(HolderOfKeyIface.class);
        WSTrustTestUtils.setupWsseAndSTSClientHolderOfKey((BindingProvider) proxy, bus);
        assertEquals("Holder-Of-Key WS-Trust Hello World!", proxy.sayHello());
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) HolderOfKeyIface(org.jboss.as.test.integration.ws.wsse.trust.holderofkey.HolderOfKeyIface) 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)

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