Java Code Examples for org.apache.cxf.BusFactory

The following are top voted examples for showing how to use org.apache.cxf.BusFactory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: cas-5.1.0   File: SecurityTokenServiceClientBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Build client for security token requests.
 *
 * @param service the rp
 * @return the security token service client
 */
public SecurityTokenServiceClient buildClientForSecurityTokenRequests(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.setTokenType(StringUtils.defaultIfBlank(service.getTokenType(), WSConstants.WSS_SAML2_TOKEN_TYPE));
    sts.setKeyType(WSFederationConstants.HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512_BEARER);
    sts.setWsdlLocation(prepareWsdlLocation(service));
    if (StringUtils.isNotBlank(service.getPolicyNamespace())) {
        sts.setWspNamespace(service.getPolicyNamespace());
    }
    final String namespace = StringUtils.defaultIfBlank(service.getNamespace(), WSFederationConstants.HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512);
    sts.setServiceQName(new QName(namespace, StringUtils.defaultIfBlank(service.getWsdlService(), WSFederationConstants.SECURITY_TOKEN_SERVICE)));
    sts.setEndpointQName(new QName(namespace, service.getWsdlEndpoint()));
    sts.getProperties().putAll(new HashMap<>());
    return sts;
}
 
Example 2
Project: cas-5.1.0   File: SecurityTokenServiceClientBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Project: dss-demonstrations   File: AppInitializer.java   Source Code and License 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	WebApplicationContext context = getContext();
	servletContext.addListener(new ContextLoaderListener(context));
	servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter("UTF-8"));

	DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
	dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Dispatcher", dispatcherServlet);
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/*");

	CXFServlet cxf = new CXFServlet();
	BusFactory.setDefaultBus(cxf.getBus());
	ServletRegistration.Dynamic cxfServlet = servletContext.addServlet("CXFServlet", cxf);
	cxfServlet.setLoadOnStartup(1);
	cxfServlet.addMapping("/services/*");

	servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false,
			"/*");

	servletContext.getSessionCookieConfig().setSecure(cookieSecure);
}
 
Example 4
Project: microbule   File: DefaultJaxrsServerFactory.java   Source Code and License 6 votes vote down vote up
@Override
public JaxrsServer createJaxrsServer(Class<?> serviceInterface, Object serviceImplementation) {
    final String serviceName = namingStrategy.get().serviceName(serviceInterface);
    final Config serverConfig = configService.createServerConfig(serviceInterface, serviceName);
    final String baseAddress = serverConfig.value(BASE_ADDRESS_PROP).orElse(StringUtils.EMPTY);
    final String serverAddress = serverConfig.value(SERVER_ADDRESS_PROP).orElse(namingStrategy.get().serverAddress(serviceInterface));
    final String fullAddress = baseAddress + serverAddress;
    LOGGER.info("Starting {} JAX-RS server ({})...", serviceInterface.getSimpleName(), fullAddress);

    final DefaultJaxrsServiceDescriptor descriptor = new DefaultJaxrsServiceDescriptor(serviceInterface, serviceName);
    decorate(descriptor, serverConfig);
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(BusFactory.getDefaultBus(true));
    sf.setServiceBean(serviceImplementation);

    sf.setAddress(fullAddress);
    sf.setFeatures(descriptor.getFeatures());
    sf.setProviders(descriptor.getProviders());
    final Server server = sf.create();
    LOGGER.info("Successfully started {} JAX-RS server ({}).", serviceInterface.getSimpleName(), serverAddress);
    return server::destroy;
}
 
Example 5
Project: Camel   File: CxfConsumerWSRMTest.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 6
Project: Camel   File: CxfCustomerStartStopTest.java   Source Code and License 6 votes vote down vote up
@Test
public void startAndStopService() throws Exception {
    CamelContext context = new DefaultCamelContext();
    // start a server    
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("cxf:http://localhost:" + PORT1 + "/test?serviceClass=org.apache.camel.component.cxf.HelloService")
                .to("log:endpoint");
        }
    });
    
    context.start();
    Thread.sleep(300);
    context.stop();
    Bus bus = BusFactory.getDefaultBus();
    JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
    JettyHTTPServerEngine engine = factory.retrieveJettyHTTPServerEngine(PORT1);
    assertNotNull("Jetty engine should be found there", engine);
    // Need to call the bus shutdown ourselves.
    String orig = System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", "false");
    bus.shutdown(true);
    System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort",
                       orig == null ? "true" : "false");
    engine = factory.retrieveJettyHTTPServerEngine(PORT1);
    assertNull("Jetty engine should be removed", engine);
}
 
Example 7
Project: Camel   File: CxfEndpointTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSettingClientBus() throws Exception {
    ExtensionManagerBus bus = (ExtensionManagerBus) BusFactory.newInstance().createBus();
    bus.setId("oldCXF");
    BusFactory.setThreadDefaultBus(bus);

    ExtensionManagerBus newBus = (ExtensionManagerBus) BusFactory.newInstance().createBus();
    newBus.setId("newCXF");
    CxfComponent cxfComponent = new CxfComponent(new DefaultCamelContext());
    CxfEndpoint endpoint = (CxfEndpoint)cxfComponent.createEndpoint(routerEndpointURI);
    endpoint.setBus(newBus);
    CamelCxfClientImpl client = (CamelCxfClientImpl)endpoint.createClient();
    assertEquals("CamelCxfClientImpl should has the same bus with CxfEndpoint", newBus, client.getBus());

    endpoint = (CxfEndpoint)cxfComponent.createEndpoint(wsdlEndpointURI);
    endpoint.setBus(newBus);
    client = (CamelCxfClientImpl)endpoint.createClient();
    assertEquals("CamelCxfClientImpl should has the same bus with CxfEndpoint", newBus, client.getBus());
}
 
Example 8
Project: Camel   File: CxfConsumerResponseTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(simpleEndpointAddress);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.getDefaultBus());

    HelloService client = (HelloService) proxyFactory.create();
    assertNotNull(client);

    String result = client.echo(TEST_MESSAGE);
    assertEquals("We should get the echo string result from router", result, "echo " + TEST_MESSAGE);

    Boolean bool = client.echoBoolean(Boolean.TRUE);
    assertNotNull("The result should not be null", bool);
    assertEquals("We should get the echo boolean result from router ", bool.toString(), "true");
    
    int beforeCallingPing = pingCounter;
    client.ping();
    int afterCallingPing = pingCounter;
    assertTrue("The ping operation doesn't be called", afterCallingPing - beforeCallingPing == 1);
}
 
Example 9
Project: Camel   File: CxfConsumerPayloadXPathClientServerTest.java   Source Code and License 6 votes vote down vote up
private void execTest(int size) throws Exception {
    buildTestMessage(size);

    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(simpleEndpointAddress);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.getDefaultBus());

    HelloService client = (HelloService) proxyFactory.create();

    String result = client.echo(testMessage);
    assertEquals("We should get the echo string result from router", "echo Hello World!", result);

    //check received requests
    assertEquals("Lengths of testMessage and receiveMessage should be equal (conversion body to String),", testMessage.length(), receivedMessageStringApplyingXPath.length());
    assertEquals("Lengths of receivedMessageByDom and receivedMessageCxfPayloadApplyingXPath should be equal", receivedMessageCxfPayloadApplyingXPath.length(), receivedMessageByDom.length());
    assertEquals("Lengths of testMessage and receiveMessage should be equal (body is CxfPayload),", testMessage.length(), receivedMessageCxfPayloadApplyingXPath.length());
}
 
Example 10
Project: Camel   File: WSSecurityRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSignature() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSecurityRouteTest.class.getResource("../client/wssec.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterSignaturePort();
     
    ((BindingProvider)greeter).getRequestContext().put(
            BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "http://localhost:" + CXFTestSupport.getPort2() 
            + "/WSSecurityRouteTest/GreeterSignaturePort"
    );
    
    assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security"));
}
 
Example 11
Project: Camel   File: WSSecurityRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testUsernameToken() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSecurityRouteTest.class.getResource("../client/wssec.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterUsernameTokenPort();
     
    ((BindingProvider)greeter).getRequestContext().put(
            BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "http://localhost:" + CXFTestSupport.getPort2() 
            + "/WSSecurityRouteTest/GreeterUsernameTokenPort"
    );
    
    assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security"));
}
 
Example 12
Project: Camel   File: WSSecurityRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testEncryption() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSecurityRouteTest.class.getResource("../client/wssec.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterEncryptionPort();
     
    ((BindingProvider)greeter).getRequestContext().put(
            BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "http://localhost:" + CXFTestSupport.getPort2() 
            + "/WSSecurityRouteTest/GreeterEncryptionPort"
    );
    
    assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security"));
}
 
Example 13
Project: Camel   File: WSSecurityRouteTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSecurityPolicy() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSecurityRouteTest.class.getResource("../client/wssec.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterSecurityPolicyPort();
     
    ((BindingProvider)greeter).getRequestContext().put(
            BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "http://localhost:" + CXFTestSupport.getPort2() 
            + "/WSSecurityRouteTest/GreeterSecurityPolicyPort"
    );
    
    assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security"));
}
 
Example 14
Project: Camel   File: CxfConsumerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(SIMPLE_ENDPOINT_ADDRESS);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.newInstance().createBus());

    HelloService client = (HelloService) proxyFactory.create();

    String result = client.echo(TEST_MESSAGE);
    assertEquals("We should get the echo string result from router", result, "echo " + TEST_MESSAGE);

    Boolean bool = client.echoBoolean(Boolean.TRUE);
    assertNotNull("The result should not be null", bool);
    assertEquals("We should get the echo boolean result from router ", bool.toString(), "true");
}
 
Example 15
Project: Camel   File: CxfConsumerMessageTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testInvokingServiceFromClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(simpleEndpointAddress);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.getDefaultBus());

    HelloService client = (HelloService) proxyFactory.create();

    String result = client.echo(TEST_MESSAGE);
    assertEquals("We should get the echo string result from router", result, "echo " + TEST_MESSAGE);

    Boolean bool = client.echoBoolean(Boolean.TRUE);
    assertNotNull("The result should not be null", bool);
    assertEquals("We should get the echo boolean result from router ", bool.toString(), "true");

}
 
Example 16
Project: Camel   File: CamelDestinationTest.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 17
Project: Camel   File: CamelTransportTestSupport.java   Source Code and License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    BusFactory bf = BusFactory.newInstance();
    //setup the camel transport for the bus
    bus = bf.createBus();
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    CamelTransportFactory camelTransportFactory = new CamelTransportFactory();
    //set the context here to the transport factory;
    camelTransportFactory.setCamelContext(context);
    ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
    dfm.registerDestinationFactory(CamelTransportFactory.TRANSPORT_ID, camelTransportFactory);
    cim.registerConduitInitiator(CamelTransportFactory.TRANSPORT_ID, camelTransportFactory);
    BusFactory.setDefaultBus(bus);
    endpointInfo = new EndpointInfo();
}
 
Example 18
Project: jbossws-cxf   File: FastInfosetTestCase.java   Source Code and License 6 votes vote down vote up
private void internalTestInfosetUsingFeatureProperties(URL wsdlURL, QName serviceName, QName portQName) throws Exception {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   ByteArrayOutputStream in = new ByteArrayOutputStream();
   PrintWriter pwIn = new PrintWriter(in);
   PrintWriter pwOut = new PrintWriter(out);
   Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   try {
      bus.getInInterceptors().add(new LoggingInInterceptor(pwIn));
      bus.getOutInterceptors().add(new LoggingOutInterceptor(pwOut));

      Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
      HelloWorld port = (HelloWorld) service.getPort(portQName, HelloWorld.class);
      
      ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer();
      configurer.setConfigProperties(port, "META-INF/jaxws-client-config.xml", "Custom Client Config");
      
      assertEquals("helloworld", port.echo("helloworld"));
      assertTrue("request is expected fastinfoset", out.toString().indexOf("application/fastinfoset") > -1);
      assertTrue("response is expected fastinfoset", in.toString().indexOf("application/fastinfoset") > -1);
   } finally {
      bus.shutdown(true);
      pwOut.close();
      pwIn.close();
   }
}
 
Example 19
Project: jbossws-cxf   File: Helper.java   Source Code and License 6 votes vote down vote up
/**
 * Verify a JAXWS client can be properly created and used to invoke a ws endpoint
 * 
 * @return
 * @throws Exception
 */
public boolean testJAXWSClient() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      BusFactory.setThreadDefaultBus(bus);

      URL wsdlURL = new URL(targetEndpoint + "?wsdl");
      QName serviceName = new QName("http://org.jboss.ws/spring", "EndpointService");

      Service service = Service.create(wsdlURL, serviceName);
      Endpoint port = (Endpoint) service.getPort(Endpoint.class);
      return "Hello".equals(port.echo("Hello"));
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 20
Project: jbossws-cxf   File: HelloDigestTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testDigest() throws Exception
{
   final Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   try {
      QName serviceName = new QName("http://jboss.org/http/security", "HelloService");
      URL wsdlURL = getResourceURL("jaxws/cxf/httpauth/WEB-INF/wsdl/hello.wsdl");
      Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
      Hello proxy = (Hello)service.getPort(Hello.class);
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, baseURL.toString());
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jbossws");
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "jbossws");
      HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
      cond.setAuthSupplier(new DigestAuthSupplier());
      int result = proxy.helloRequest("number");
      assertEquals(100, result);
   } finally {
      bus.shutdown(true);
   }
}
 
Example 21
Project: jbossws-cxf   File: HelloDigestTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testDigestAuthFail() throws Exception
{
   final Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   try {
      QName serviceName = new QName("http://jboss.org/http/security", "HelloService");
      URL wsdlURL = getResourceURL("jaxws/cxf/httpauth/WEB-INF/wsdl/hello.wsdl");
      Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
      Hello proxy = (Hello)service.getPort(Hello.class);
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, baseURL.toString());
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jbossws");
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "wrongPwd");
      HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
      cond.setAuthSupplier(new DigestAuthSupplier());
      try {
         proxy.helloRequest("number");
         fail("Authorization exception expected!");
      } catch (Exception e) {
         assertTrue(e.getCause().getMessage().contains("Authorization"));
      }
   } finally {
      bus.shutdown(true);
   }
}
 
Example 22
Project: jbossws-cxf   File: OasisCatalogHelloWSTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testCatalogOnServerSide() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try {
      BusFactory.setThreadDefaultBus(bus);

      QName serviceName = new QName(
         org.jboss.test.ws.jaxws.cxf.catalog.HelloWs.TARGET_NAMESPACE,
         org.jboss.test.ws.jaxws.cxf.catalog.HelloWs.NAME);
      URL wsdlURL = new URL(baseURL + "HelloService?wsdl");
      Service service = Service.create(wsdlURL, serviceName);
      HelloWs proxy = service.getPort(HelloWs.class);
      HelloRequest helloReq = new HelloRequest();
      helloReq.setInput("Anyone home?");
      proxy.doHello(helloReq);

   } finally {
      bus.shutdown(true);
   }
}
 
Example 23
Project: jbossws-cxf   File: HTTPConduitTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testDefaultWrapperInstalled() throws Exception {
   Bus bus = BusFactory.newInstance().createBus();
   try {
      HTTPConduitFactory hcf = bus.getExtension(HTTPConduitFactory.class);
      assertNotNull(hcf);
      assertTrue(hcf instanceof DefaultHTTPConduitFactoryWrapper);
      
      URL wsdlURL = new URL(baseURL + "/ServiceOne" + "?wsdl");
      Service service = Service.create(wsdlURL, new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "ServiceOne"));
      EndpointOne port = service.getPort(new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "EndpointOnePort"), EndpointOne.class);
      assertEquals("Foo", port.echo("Foo"));
   } finally {
      bus.shutdown(true);
   }
}
 
Example 24
Project: jbossws-cxf   File: Helper.java   Source Code and License 6 votes vote down vote up
public boolean testGZIPServerSideOnlyInterceptorOnClient() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      BusFactory.setThreadDefaultBus(bus);
      
      HelloWorld port = getPort();
      Client client = ClientProxy.getClient(port);
      HTTPConduit conduit = (HTTPConduit)client.getConduit();
      HTTPClientPolicy policy = conduit.getClient();
      //enable Accept gzip, otherwise the server will not try to reply using gzip
      policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
      //add interceptor for decoding gzip message
      
      ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer();
      configurer.setConfigProperties(port, "jaxws-client-config.xml", "Interceptor Client Config");
      
      return ("foo".equals(port.echo("foo")));
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 25
Project: jbossws-cxf   File: Helper.java   Source Code and License 6 votes vote down vote up
public boolean testGZIPUsingFeatureOnBus() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      BusFactory.setThreadDefaultBus(bus);
      
      GZIPFeature gzipFeature = new GZIPFeature();
      gzipFeature.setThreshold(0);
      gzipFeature.initialize(bus);

      HelloWorld port = getPort();
      return ("foo".equals(port.echo("foo")));
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 26
Project: jbossws-cxf   File: Helper.java   Source Code and License 6 votes vote down vote up
public boolean testGZIPServerSideOnlyInterceptorOnClient() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      BusFactory.setThreadDefaultBus(bus);
      
      HelloWorld port = getPort();
      Client client = ClientProxy.getClient(port);
      HTTPConduit conduit = (HTTPConduit)client.getConduit();
      HTTPClientPolicy policy = conduit.getClient();
      //enable Accept gzip, otherwise the server will not try to reply using gzip
      policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
      //add interceptor for decoding gzip message
      client.getInInterceptors().add(new GZIPEnforcingInInterceptor());
      return ("foo".equals(port.echo("foo")));
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 27
Project: jbossws-cxf   File: Helper.java   Source Code and License 6 votes vote down vote up
public boolean testGZIPServerSideOnlyInterceptorsOnBus() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      //enable Accept gzip, otherwise the server will not try to reply using gzip
      GZIPOutInterceptor outInterceptor = new GZIPOutInterceptor();
      outInterceptor.setThreshold(1024*1024); // 1MB -> no gzip on request
      bus.getOutInterceptors().add(outInterceptor);
      //add interceptor for decoding gzip message
      bus.getInInterceptors().add(new GZIPEnforcingInInterceptor());
      BusFactory.setThreadDefaultBus(bus);
      HelloWorld port = getPort();
      return ("foo".equals(port.echo("foo")));
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 28
Project: jbossws-cxf   File: PolicyInterceptorProviderTestCase.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies the policy-enabled client can be configured to ignore a given policy in the wsdl contract
 * 
 * @throws Exception
 */
@Test
@RunAsClient
public void testUnsupportedPolicy() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      BusFactory.setThreadDefaultBus(bus);
      
      PolicyInterceptorProviderRegistry reg = bus.getExtension(PolicyInterceptorProviderRegistry.class);
      reg.register(new IgnorablePolicyInterceptorProvider(new QName("http://my.custom.org/policy", "MyPolicy")));
      
      URL wsdlURL = new URL(baseURL + "/jaxws-cxf-policy/PIPService/PIPEndpoint?wsdl");
      QName serviceName = new QName("http://policy.cxf.jaxws.ws.test.jboss.org/", "PIPService");
      Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
      QName portQName = new QName("http://policy.cxf.jaxws.ws.test.jboss.org/", "PIPEndpointPort");
      PIPEndpoint port = (PIPEndpoint)service.getPort(portQName, PIPEndpoint.class);

      assertEquals("foo", port.echo("foo"));
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 29
Project: jbossws-cxf   File: CXFEndpointServlet.java   Source Code and License 6 votes vote down vote up
@Override
public void loadBus(ServletConfig servletConfig)
{
   super.loadBus(servletConfig);

   // You could add the endpoint publish codes here
   try {
      //be sure to use the bus that's been created in loadBus..
      Bus bus = getBus();
      BusFactory.setThreadDefaultBus(bus);
      Endpoint.publish("/Echo1", new EchoImpl());
   } finally {
      //free the thread default bus association in the current thread which
      //is serving the servlet init, as it can have side effect on other
      //servlet(s) deployed afterwards
      BusFactory.setThreadDefaultBus(null);
   }
}
 
Example 30
Project: jbossws-cxf   File: AsyncClientTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testAysncClientWithPolicy () throws Exception 
{
   Bus bus = BusFactory.newInstance().createBus();
   AsyncEnabledInfoInterceptor asyncInfo = new AsyncEnabledInfoInterceptor();
   try
   {
      bus.setProperty("use.async.http.conduit", "ASYNC_ONLY");
      bus.getOutInterceptors().add(asyncInfo);
      BusFactory.setThreadDefaultBus(bus);
      Endpoint proxy = initPort();
      assertEquals("Echo:1000", proxy.echo(1000));
      assertFalse("Async client is expected disabled", asyncInfo.isAsyncEnabled());
      assertEquals("Echo:1000", proxy.echoAsync(1000).get());
      assertTrue("Async client is expected enabled", asyncInfo.isAsyncEnabled());
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 31
Project: jbossws-cxf   File: ClientServerLifeCycleTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void testCustomClientLifeCycleListener() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   try {
      URL wsdlOneURL = new URL(baseURL + "/ServiceOne/EndpointOne?wsdl");
      QName serviceOneName = new QName("http://org.jboss.ws.jaxws.cxf/jbws3098", "ServiceOne");
      Service serviceOne = Service.create(wsdlOneURL, serviceOneName, new UseThreadBusFeature());
      CustomClientLifeCycleListener listener = new CustomClientLifeCycleListener();
      ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
      try {
         mgr.registerListener(listener);
         assertEquals(0, listener.getCount());
         EndpointOne portOne = (EndpointOne)serviceOne.getPort(EndpointOne.class);
         assertEquals(1, listener.getCount());
         assertEquals("Foo", portOne.echo("Foo"));
      } finally {
         mgr.unRegisterListener(listener);
      }
   } finally {
      bus.shutdown(true);
   }
}
 
Example 32
Project: jbossws-cxf   File: Helper.java   Source Code and License 6 votes vote down vote up
/**
 * Setup binding customization on client side using the JBossWSConfigurer
 *
 * @throws Exception
 */
@SuppressWarnings("unchecked")
private Bus setBindingCustomizationOnClientSide() throws Exception
{
   BindingCustomization jaxbCustomizations = new JAXBBindingCustomization();
   if (jaxbIntroUrl == null)
   {
      jaxbIntroUrl = Thread.currentThread().getContextClassLoader().getResource("jaxb-intros.xml");
   }
   BindingCustomizationFactory.populateBindingCustomization(jaxbIntroUrl.openStream(), jaxbCustomizations);

   Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   JBossWSConfigurer configurer = (JBossWSConfigurer)bus.getExtension(Configurer.class);
   configurer.getCustomizer().setBindingCustomization(jaxbCustomizations);
   return bus;
}
 
Example 33
Project: jbossws-cxf   File: AbstractClient.java   Source Code and License 6 votes vote down vote up
public static void testBusCreation() throws BusTestException
{
   Bus initialDefaultBus = BusFactory.getDefaultBus(false);
   Bus initialThreadBus = BusFactory.getThreadDefaultBus(false);
   BusFactory factory = BusFactory.newInstance();
   Bus bus = factory.createBus();
   assert (bus != null);
   if (initialThreadBus == null) //if the thread bus was not set before, it should now be
   {
      checkThreadBus(bus);
   }
   checkDefaultBus(initialDefaultBus);
   BusFactory.setThreadDefaultBus(initialThreadBus);
   checkThreadBus(initialThreadBus);
   checkDefaultBus(initialDefaultBus);
}
 
Example 34
Project: jbossws-cxf   File: AbstractClient.java   Source Code and License 6 votes vote down vote up
public static void testWebServiceRef(Endpoint port) throws BusTestException
{
   Bus initialDefaultBus = BusFactory.getDefaultBus(false);
   Bus threadBus = BusFactory.getThreadDefaultBus(false);
   performInvocation(port); //does not change anything to the bus, as the port is already created when injecting serviceref
   checkDefaultBus(initialDefaultBus);
   checkThreadBus(threadBus);
   try
   {
      BusFactory.setThreadDefaultBus(null);
      performInvocation(port); //does not change anything to the bus, as the port is already created when injecting serviceref
      checkDefaultBus(initialDefaultBus);
      checkThreadBus(null);
      BusFactory factory = BusFactory.newInstance();
      Bus bus = factory.createBus(); //internally sets the thread bus
      performInvocation(port); //does not change anything to the bus, as the port is already created when injecting serviceref
      checkDefaultBus(initialDefaultBus);
      checkThreadBus(bus);
   }
   finally
   {
      BusFactory.setThreadDefaultBus(threadBus);
   }
}
 
Example 35
Project: jbossws-cxf   File: WSTrustTestCase.java   Source Code and License 6 votes vote down vote up
/**
 * No CallbackHandler is provided in STSCLient.  Username and password provided instead.
 *
 * @throws Exception
 */
@Test
@RunAsClient
@OperateOnDeployment(SERVER_DEP)
@WrapThreadContextClassLoader
public void testNoClientCallback() 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.setupWsseAndSTSClientNoCallbackHandler(proxy, bus, stsURL.toString(), stsServiceName, stsPortName);

      assertEquals("WS-Trust Hello World!", proxy.sayHello());
   } finally {
      bus.shutdown(true);
   }
}
 
Example 36
Project: jbossws-cxf   File: WSTrustTestCase.java   Source Code and License 6 votes vote down vote up
/**
 *  Request a security token that allows it to act as if it were somebody else.
 *
 * @throws Exception
 */
@Test
@RunAsClient
@OperateOnDeployment(ACT_AS_SERVER_DEP)
@WrapThreadContextClassLoader
public void testActAs() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      BusFactory.setThreadDefaultBus(bus);

      final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/actaswssecuritypolicy", "ActAsService");
      final URL wsdlURL = new URL(serviceURL + "ActAsService?wsdl");
      Service service = Service.create(wsdlURL, serviceName);
      ActAsServiceIface proxy = (ActAsServiceIface) service.getPort(ActAsServiceIface.class);

      WSTrustTestUtils.setupWsseAndSTSClientActAs((BindingProvider) proxy, bus);

      assertEquals("ActAs WS-Trust Hello World!", proxy.sayHello(getServerHost(), String.valueOf(getServerPort())));
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 37
Project: jbossws-cxf   File: WSTrustTestCase.java   Source Code and License 6 votes vote down vote up
@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 + 8443, "/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);
   }
}
 
Example 38
Project: jbossws-cxf   File: WSTrustTestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
@OperateOnDeployment(BEARER_SERVER_DEP)
@WrapThreadContextClassLoader
public void testBearer() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      BusFactory.setThreadDefaultBus(bus);

      final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/bearerwssecuritypolicy", "BearerService");
      Service service = Service.create(new URL(serviceURL + "BearerService?wsdl"), serviceName);
      BearerIface proxy = (BearerIface) service.getPort(BearerIface.class);

      WSTrustTestUtils.setupWsseAndSTSClientBearer((BindingProvider) proxy, bus);
      assertEquals("Bearer WS-Trust Hello World!", proxy.sayHello());

   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 39
Project: jbossws-cxf   File: WSReliableMessagingWithAPITestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
public void test() throws Exception
{
   final Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   try {
      QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wsrm", "SimpleService");
      URL wsdlURL = getResourceURL("jaxws/samples/wsrm/WEB-INF/wsdl/SimpleService.wsdl");
      Service service = Service.create(wsdlURL, serviceName);
      SimpleService proxy = (SimpleService)service.getPort(SimpleService.class);
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, baseURL + "/jaxws-samples-wsrm-api/SimpleService");
      
      assertEquals("Hello World!", proxy.echo("Hello World!")); // request response call
      proxy.ping(); // one way call
   } finally {
      bus.shutdown(true);
   }
}
 
Example 40
Project: jbossws-cxf   File: WSReliableMessagingWithAPITestCase.java   Source Code and License 6 votes vote down vote up
@Test
@RunAsClient
@WrapThreadContextClassLoader
public void testWithFeatureProperty() throws Exception
{
   final Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   try {
      QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wsrm", "SimpleService");
      URL wsdlURL = getResourceURL("jaxws/samples/wsrm/WEB-INF/wsdl/SimpleService.wsdl");
      Service service = Service.create(wsdlURL, serviceName);
      SimpleService proxy = (SimpleService)service.getPort(SimpleService.class);
      
      ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer();
      configurer.setConfigProperties(proxy, "META-INF/jaxws-client-config.xml", "Custom Client Config");
      
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, baseURL + "/jaxws-samples-wsrm-api/SimpleService");
      
      assertEquals("Hello World!", proxy.echo("Hello World!")); // request response call
      proxy.ping(); // one way call
   } finally {
      bus.shutdown(true);
   }
}