Java Code Examples for org.apache.cxf.jaxws.JaxWsProxyFactoryBean#setServiceClass()

The following examples show how to use org.apache.cxf.jaxws.JaxWsProxyFactoryBean#setServiceClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoapActionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSoap12Endpoint() throws Exception {

    JaxWsProxyFactoryBean pf = new JaxWsProxyFactoryBean();
    pf.setServiceClass(Greeter.class);
    pf.setAddress(add12);
    SoapBindingConfiguration config = new SoapBindingConfiguration();
    config.setVersion(Soap12.getInstance());
    pf.setBindingConfig(config);
    pf.setBus(bus);

    Greeter greeter = (Greeter) pf.create();

    assertEquals("sayHi", greeter.sayHi("test"));
    assertEquals("sayHi2", greeter.sayHi2("test"));
}
 
Example 2
Source File: ClientConfig.java    From cxf-jaxws with MIT License 6 votes vote down vote up
@Bean(name = "ticketAgentProxy")
public TicketAgent ticketAgentProxy() {
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();
  jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class);
  jaxWsProxyFactoryBean.setAddress(address);

  // add an interceptor to log the outgoing request messages
  jaxWsProxyFactoryBean.getOutInterceptors()
      .add(loggingOutInterceptor());
  // add an interceptor to log the incoming response messages
  jaxWsProxyFactoryBean.getInInterceptors()
      .add(loggingInInterceptor());
  // add an interceptor to log the incoming fault messages
  jaxWsProxyFactoryBean.getInFaultInterceptors()
      .add(loggingInInterceptor());

  return (TicketAgent) jaxWsProxyFactoryBean.create();
}
 
Example 3
Source File: IntegrationBaseTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Resource createClient(ReferenceParametersType refParams) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

    Map<String, Object> props = factory.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
            ExpressionType.class);
    factory.setProperties(props);

    factory.setBus(bus);
    factory.setServiceClass(Resource.class);
    factory.setAddress(RESOURCE_ADDRESS);
    Resource proxy = (Resource) factory.create();

    // Add reference parameters
    AddressingProperties addrProps = new AddressingProperties();
    EndpointReferenceType endpoint = new EndpointReferenceType();
    endpoint.setReferenceParameters(refParams);
    endpoint.setAddress(ContextUtils.getAttributedURI(RESOURCE_ADDRESS));
    addrProps.setTo(endpoint);
    ((BindingProvider) proxy).getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProps);

    return proxy;
}
 
Example 4
Source File: SoapChannel.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public void connect(TokenHolder tokenHolder) {
	for (Class<? extends PublicInterface> interface1 : interfaces) {
		JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean();
		cpfb.setServiceClass(interface1);
		cpfb.setAddress(address + "/" + interface1.getSimpleName());
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put("mtom-enabled", Boolean.TRUE);
		cpfb.setProperties(properties);
		
		PublicInterface serviceInterface = (PublicInterface) cpfb.create();
		
		client = ClientProxy.getClient(serviceInterface);
		HTTPConduit http = (HTTPConduit) client.getConduit();
		http.getClient().setConnectionTimeout(360000);
		http.getClient().setAllowChunking(false);
		http.getClient().setReceiveTimeout(320000);
		
		if (!useSoapHeaderSessions) {
			((BindingProvider) serviceInterface).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
		}
		add(interface1.getName(), serviceInterface);
	}
	tokenHolder.registerTokenChangeListener(this);
	notifyOfConnect();
}
 
Example 5
Source File: AegisClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testJaxWsAegisClient() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(AuthService.class);
    proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegis");
    AuthService service = (AuthService) proxyFactory.create();
    assertTrue(service.authenticate("Joe", "Joe", "123"));
    assertFalse(service.authenticate("Joe1", "Joe", "fang"));
    assertTrue(service.authenticate("Joe", null, "123"));
    List<String> list = service.getRoles("Joe");
    assertEquals(3, list.size());
    assertEquals("Joe", list.get(0));
    assertEquals("Joe-1", list.get(1));
    assertEquals("Joe-2", list.get(2));
    String[] roles = service.getRolesAsArray("Joe");
    assertEquals(2, roles.length);
    assertEquals("Joe", roles[0]);
    assertEquals("Joe-1", roles[1]);

    roles = service.getRolesAsArray("null");
    assertNull(roles);

    roles = service.getRolesAsArray("0");
    assertEquals(0, roles.length);

    assertEquals("get Joe", service.getAuthentication("Joe"));
    Authenticate au = new Authenticate();
    au.setSid("ffang");
    au.setUid("ffang");
    assertTrue(service.authenticate(au));
    au.setUid("ffang1");
    assertFalse(service.authenticate(au));
}
 
Example 6
Source File: HelloWorldImplTest.java    From cxf-jaxws with MIT License 5 votes vote down vote up
private static HelloWorldPortType createClientProxy() {
  // create a CXF JaxWsProxyFactoryBean for creating JAX-WS proxies
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();

  // // set the HelloWorld portType class
  jaxWsProxyFactoryBean.setServiceClass(HelloWorldPortType.class);
  // set the address at which the HelloWorld endpoint will be called
  jaxWsProxyFactoryBean.setAddress(ENDPOINT_ADDRESS);

  // create a JAX-WS proxy for the HelloWorld portType
  return (HelloWorldPortType) jaxWsProxyFactoryBean.create();
}
 
Example 7
Source File: JMSTransactionTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Greeter createGreeterProxy() throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.getFeatures().add(cff);
    factory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);
    factory.setServiceClass(Greeter.class);
    factory.setAddress(SERVICE_ADDRESS);
    return (Greeter)markForClose(factory.create());
}
 
Example 8
Source File: WSAFeatureXmlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testClientProxyFactory() {

    JaxWsProxyFactoryBean cf = new JaxWsProxyFactoryBean();
    cf.setAddress("http://localhost:" + PORT + "/test");
    cf.setServiceClass(Greeter.class);
    cf.setBus(getBus());
    Configurer c = getBus().getExtension(Configurer.class);
    c.configureBean("client.proxyFactory", cf);
    Greeter greeter = (Greeter) cf.create();
    Client client = ClientProxy.getClient(greeter);
    checkAddressInterceptors(client.getInInterceptors());
}
 
Example 9
Source File: OnvifDevice.java    From onvif with Apache License 2.0 5 votes vote down vote up
public JaxWsProxyFactoryBean getServiceProxy(BindingProvider servicePort, String serviceAddr) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.getHandlers();

    if (serviceAddr != null) proxyFactory.setAddress(serviceAddr);
    proxyFactory.setServiceClass(servicePort.getClass());

    SoapBindingConfiguration config = new SoapBindingConfiguration();

    config.setVersion(Soap12.getInstance());
    proxyFactory.setBindingConfig(config);
    Client deviceClient = ClientProxy.getClient(servicePort);

    if (verbose) {
      // these logging interceptors are depreciated, but should be fine for debugging/development
      // use.
      proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
      proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    }

    HTTPConduit http = (HTTPConduit) deviceClient.getConduit();
    if (securityHandler != null) proxyFactory.getHandlers().add(securityHandler);
    HTTPClientPolicy httpClientPolicy = http.getClient();
    httpClientPolicy.setConnectionTimeout(36000);
    httpClientPolicy.setReceiveTimeout(32000);
    httpClientPolicy.setAllowChunking(false);

    return proxyFactory;
  }
 
Example 10
Source File: WSAClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoWsaFeature() throws Exception {
    ByteArrayOutputStream input = setupInLogging();
    ByteArrayOutputStream output = setupOutLogging();

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(AddNumbersPortType.class);
    factory.setAddress("http://localhost:" + PORT + "/jaxws/add");
    AddNumbersPortType port = (AddNumbersPortType) factory.create();

    assertEquals(3, port.addNumbers(1, 2));

    assertLogNotContains(output.toString(), "//wsa:Address");
    assertLogNotContains(input.toString(), "//wsa:RelatesTo");
}
 
Example 11
Source File: CustomerServiceIT.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void checkCustomerService() throws Exception {

	final JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
	jaxWsProxyFactoryBean.setServiceClass(CustomerService.class);
	jaxWsProxyFactoryBean.setAddress(webAppEnvironment.getBaseUrl()
			+ "/CustomerServicePort");

	final CustomerService customerService = (CustomerService) jaxWsProxyFactoryBean
			.create();

	final Customer originalCustomer = new Customer();

	// originalCustomer.setCustomerId(1);
	originalCustomer.setName("Scott Tiger");
	originalCustomer.getAddress().add("Hauptstr. 6");
	originalCustomer.getAddress().add("76133 Karlsruhe");
	originalCustomer.getAddress().add("Germany");
	originalCustomer.setNumOrders(15);
	originalCustomer.setRevenue(1234.56);
	originalCustomer.setTest(BigDecimal.valueOf(7890));
	originalCustomer.setBirthDate(DataTypeAdapter.parseDate("1970-01-01"));
	originalCustomer.setType(CustomerType.BUSINESS);

	final Integer customerId = customerService
			.updateCustomer(originalCustomer);

	assertNotNull(customerId);

	final Customer retrievedCustomer = customerService
			.getCustomerById(customerId);

	assertEquals(originalCustomer.getName(), retrievedCustomer.getName());
	assertEquals(originalCustomer.getAddress(), retrievedCustomer
			.getAddress());

	customerService.deleteCustomerById(retrievedCustomer.getCustomerId());

}
 
Example 12
Source File: NettyHttpConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testInovationWithNettyAddress() throws Exception {
    String address = "netty://http://localhost:" + PORT + "/SoapContext/SoapPort";
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(Greeter.class);
    factory.setAddress(address);
    Greeter greeter = factory.create(Greeter.class);
    String response = greeter.greetMe("test");
    assertEquals("Get a wrong response", "Hello test", response);
}
 
Example 13
Source File: JavaFirstSchemaValidationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static <T> T createClient(String port, Class<T> serviceClass, SchemaValidationType type,
        Feature ... features) {
    JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
    clientFactory.setServiceClass(serviceClass);


    clientFactory.setAddress(getAddress(port, serviceClass));

    if (features != null) {
        Collections.addAll(clientFactory.getFeatures(), features);
    }

    @SuppressWarnings("unchecked")
    T newClient = (T)clientFactory.create();

    Client proxy = ClientProxy.getClient(newClient);

    if (type != null) {
        proxy.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, type);
    }

    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    // give me longer debug times
    HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
    clientPolicy.setConnectionTimeout(1000000);
    clientPolicy.setReceiveTimeout(1000000);
    conduit.setClient(clientPolicy);

    return newClient;
}
 
Example 14
Source File: SimpleEventingIntegrationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to create a client for the testing Subscription Manager
 * which is located at local://SimpleSubscriptionManager.
 * You have to specify the reference parameters you obtained from the Event Source
 * when your subscription was created.
 *
 * @return a JAX-WS client set up for managing the subscription you had created using the Event Source
 */
public SubscriptionManagerEndpoint createSubscriptionManagerClient(ReferenceParametersType refs) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceClass(SubscriptionManagerEndpoint.class);
    factory.setAddress(URL_SUBSCRIPTION_MANAGER);
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    ReferenceParametersAddingHandler handler = new ReferenceParametersAddingHandler(refs);
    factory.getHandlers().add(handler);
    return (SubscriptionManagerEndpoint)factory.create();
}
 
Example 15
Source File: RoundTripTest.java    From steady with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
 
Example 16
Source File: RoundTripTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();

    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(ConfigurationConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);

    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
 
Example 17
Source File: TestUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected static ResourceFactory createResourceFactoryClient(String port) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(org.apache.cxf.ws.transfer.resourcefactory.ResourceFactory.class);
    factory.setAddress("http://localhost:" + port + "/ResourceFactory");
    return (ResourceFactory) factory.create();
}
 
Example 18
Source File: RoundTripTest.java    From steady with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
 
Example 19
Source File: UserNameTokenAuthorizationTest.java    From steady with Apache License 2.0 4 votes vote down vote up
public void setUpService(String expectedRoles,
                         boolean digest,
                         boolean encryptUsernameTokenOnly) throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new SimpleSubjectCreatingInterceptor();
    wsIn.setSupportDigestPasswords(digest);
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    
    service.getInInterceptors().add(wsIn);
     
    SimpleAuthorizingInterceptor sai = new SimpleAuthorizingInterceptor();
    sai.setMethodRolesMap(Collections.singletonMap("echo", expectedRoles));
    service.getInInterceptors().add(sai);
    
    
    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    if (digest) {
        wsOut.setProperty("password", "myAliasPassword");
    } else {
        wsOut.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    }
    
    if (encryptUsernameTokenOnly) {
        wsOut.setProperty(WSHandlerConstants.ENCRYPTION_USER, "myalias");
        wsOut.setProperty(
            WSHandlerConstants.ENCRYPTION_PARTS, 
            "{Content}{" + WSConstants.WSSE_NS + "}UsernameToken"
        );
    }
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    ((BindingProvider)echo).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);

    
    client = ClientProxy.getClient(echo);
    
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
 
Example 20
Source File: RoundTripTest.java    From steady with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}