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

The following examples show how to use org.apache.cxf.jaxws.JaxWsProxyFactoryBean#create() . 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: SoapClient.java    From document-management-software with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Standard service initialization. Concrete implementations can change the
 * client initialization logic
 */
@SuppressWarnings("unchecked")
protected void initClient(Class<T> serviceClass, int gzipThreshold, boolean log) {
	// Needed to get rig of CXF exception
	// "Cannot create a secure XMLInputFactory"
	System.setProperty("org.apache.cxf.stax.allowInsecureParser", "true");

	JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
	if (log) {
		factory.getInInterceptors().add(new LoggingInInterceptor());
		factory.getOutInterceptors().add(new LoggingOutInterceptor());
	}

	if (gzipThreshold >= 0) {
		factory.getInInterceptors().add(new GZIPInInterceptor());
		factory.getOutInterceptors().add(new GZIPOutInterceptor(gzipThreshold));
	}

	factory.setServiceClass(serviceClass);
	factory.setAddress(endpoint);
	client = (T) factory.create();
}
 
Example 2
Source File: Client.java    From servicemix with Apache License 2.0 6 votes vote down vote up
public void sendRequest() throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(HelloWorld.class);
    factory.setAddress("http://localhost:8181/cxf/HelloWorldSecurity");
    HelloWorld client = (HelloWorld) factory.create();
    
    Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put("action", "UsernameToken");

    //add a CustomerSecurityInterceptor for client side to init wss4j staff
    //retrieve and set user/password,  users can easily add this interceptor
    //through spring configuration also
    ClientProxy.getClient(client).getOutInterceptors().add(new CustomerSecurityInterceptor());
    ClientProxy.getClient(client).getOutInterceptors().add(new WSS4JOutInterceptor());
    String ret = client.sayHi("ffang");
    System.out.println(ret);
}
 
Example 3
Source File: SpringBeansTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientFromFactory() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxws/spring/clients.xml"});


    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

    Greeter g = factory.create(Greeter.class);
    ClientImpl c = (ClientImpl)ClientProxy.getClient(g);
    for (Interceptor<? extends Message> i : c.getInInterceptors()) {
        if (i instanceof LoggingInInterceptor) {
            ctx.close();
            return;
        }
    }
    ctx.close();
    fail("Did not configure the client");
}
 
Example 4
Source File: ExceptionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test(expected = HelloException.class)
public void testJaxws() throws Exception {
    JaxWsServerFactoryBean sfbean = new JaxWsServerFactoryBean();
    sfbean.setServiceClass(ExceptionService.class);
    setupAegis(sfbean);
    sfbean.setAddress("local://ExceptionService4");
    Server server = sfbean.create();
    Service service = server.getEndpoint().getService();
    service.setInvoker(new BeanInvoker(new ExceptionServiceImpl()));

    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setAddress("local://ExceptionService4");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());
    ExceptionService clientInterface = proxyFac.create(ExceptionService.class);

    clientInterface.sayHiWithException();
}
 
Example 5
Source File: QuerySubscription.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
     * Poll a query using local transport.
     */
    protected QueryResults executePoll(Poll poll) throws ImplementationExceptionResponse,
            QueryTooComplexExceptionResponse, QueryTooLargeExceptionResponse, SecurityExceptionResponse,
            ValidationExceptionResponse, NoSuchNameExceptionResponse, QueryParameterExceptionResponse {
        // we use CXF's local transport feature here
//        EPCglobalEPCISService service = new EPCglobalEPCISService();
//        QName portName = new QName("urn:epcglobal:epcis:wsdl:1", "EPCglobalEPCISServicePortLocal");
//        service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://query");
//        EPCISServicePortType servicePort = service.getPort(portName, EPCISServicePortType.class);

        // the same using CXF API
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setAddress("local://query");
         factory.setServiceClass(EPCISServicePortType.class);
         EPCISServicePortType servicePort = (EPCISServicePortType)
         factory.create();

        return servicePort.poll(poll);
    }
 
Example 6
Source File: StudentTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnMapDocLiteral() throws Exception {

    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceClass(StudentServiceDocLiteral.class);
    sf.setServiceBean(new StudentServiceDocLiteralImpl());
    sf.setAddress("local://StudentServiceDocLiteral");
    setupAegis(sf);
    Server server = sf.create();
    server.start();

    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setAddress("local://StudentServiceDocLiteral");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    StudentServiceDocLiteral clientInterface = proxyFac.create(StudentServiceDocLiteral.class);
    Map<Long, Student> fullMap = clientInterface.getStudentsMap();
    assertNotNull(fullMap);
    Student one = fullMap.get(Long.valueOf(1));
    assertNotNull(one);
    assertEquals("Student1", one.getName());

}
 
Example 7
Source File: UDPTransportTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBroadcastUDP() throws Exception {
    // Disable the test on Redhat Enterprise Linux which doesn't enable the UDP broadcast by default
    if ("Linux".equals(System.getProperties().getProperty("os.name"))
        && System.getProperties().getProperty("os.version").indexOf("el") > 0) {
        System.out.println("Skipping broadcast test for REL");
        return;
    }

    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    int count = 0;
    while (interfaces.hasMoreElements()) {
        NetworkInterface networkInterface = interfaces.nextElement();
        if (!networkInterface.isUp() || networkInterface.isLoopback()) {
            continue;
        }
        count++;
    }
    if (count == 0) {
        //no non-loopbacks, cannot do broadcasts
        System.out.println("Skipping broadcast test");
        return;
    }

    JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
    fact.setAddress("udp://:" + PORT + "/foo");
    Greeter g = fact.create(Greeter.class);
    assertEquals("Hello World", g.greetMe("World"));

    ((java.io.Closeable)g).close();
}
 
Example 8
Source File: SimpleBootCxfSystemTestConfiguration.java    From tutorial-soap-spring-boot-cxf with MIT License 5 votes vote down vote up
@Bean
public WeatherService weatherServiceSystemTestClient() {
    JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean();
    jaxWsProxyFactory.setServiceClass(WeatherService.class);
    jaxWsProxyFactory.setAddress("http://localhost:8090" + cxfAutoConfiguration.getBaseUrl() + SimpleBootCxfConfiguration.SERVICE_URL);
    return (WeatherService) jaxWsProxyFactory.create();
}
 
Example 9
Source File: SoapActionTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testEndpoint() throws Exception {
    JaxWsProxyFactoryBean pf = new JaxWsProxyFactoryBean();
    pf.setServiceClass(Greeter.class);
    pf.setAddress(add11);
    pf.setBus(bus);
    Greeter greeter = (Greeter) pf.create();

    assertEquals("sayHi", greeter.sayHi("test"));
    assertEquals("sayHi2", greeter.sayHi2("test"));
}
 
Example 10
Source File: CreateSubscriptionServlet.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    try {
        resp.getWriter().append("<html><body>");


        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(EventSourceEndpoint.class);
        factory.setAddress("http://localhost:8080/ws_eventing/services/EventSource");
        EventSourceEndpoint requestorClient = (EventSourceEndpoint)factory.create();

        String expires = null;
        if (req.getParameter("expires-set") == null) {
            expires = req.getParameter("expires");
        } else {
            if (!"false".equals(req.getParameter("expires-set"))) {
                expires = req.getParameter("expires");
            }
        }

        Subscribe sub = createSubscribeMessage(req.getParameter("targeturl"),
                req.getParameter("filter-set") == null ? req.getParameter("filter") : null,
                expires);

        resp.getWriter().append("<h3>Subscription request</h3>");
        resp.getWriter().append(convertJAXBElementToStringAndEscapeHTML(sub));

        SubscribeResponse subscribeResponse = requestorClient.subscribeOp(sub);

        resp.getWriter().append("<h3>Response from Event Source</h3>");
        resp.getWriter().append(convertJAXBElementToStringAndEscapeHTML(subscribeResponse));

        resp.getWriter().append("<br/><a href=\"index.jsp\">Back to main page</a>");
        resp.getWriter().append("</body></html>");
    } catch (Exception e) {
        throw new ServletException(e);
    }

}
 
Example 11
Source File: RemoteTestHarness.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
/**
 * Creates a published endpoint from the passed in serviceImplementation and also returns a proxy implementation
 * of the passed in interface for clients to use to hit the created endpoint.
 */
public <T> T publishEndpointAndReturnProxy(Class<T> jaxWsAnnotatedInterface, T serviceImplementation) {
    if (jaxWsAnnotatedInterface.isInterface() &&
            jaxWsAnnotatedInterface.getAnnotation(WebService.class) != null &&
            jaxWsAnnotatedInterface.isInstance(serviceImplementation)) {

        String endpointUrl = getAvailableEndpointUrl();
        LOG.info("Publishing service to: " + endpointUrl);
        endpoint = Endpoint.publish(endpointUrl, serviceImplementation);

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(jaxWsAnnotatedInterface);
        factory.setAddress(endpointUrl);

        T serviceProxy = (T) factory.create();

        /* Add the ImmutableCollectionsInInterceptor to mimic interceptors added in the KSB */
        Client cxfClient = ClientProxy.getClient(serviceProxy);
        cxfClient.getInInterceptors().add(new ImmutableCollectionsInInterceptor());

        return serviceProxy;
    } else {
        throw new IllegalArgumentException("Passed in interface class type must be annotated with @WebService " +
                "and object reference must be an implementing class of that interface.");

    }
}
 
Example 12
Source File: AegisClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericPair() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(SportsService.class);
    proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports");
    proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    SportsService service = (SportsService) proxyFactory.create();
    Pair<String, Integer> ret = service.getReturnGenericPair("ffang", 111);
    assertEquals("ffang", ret.getFirst());
    assertEquals(Integer.valueOf(111), ret.getSecond());
}
 
Example 13
Source File: AegisWSDLNSTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setupForTest(boolean specifyWsdl) throws Exception {

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(AegisJaxWsWsdlNs.class);
        if (specifyWsdl) {
            factory.setServiceName(new QName("http://v1_1_2.rtf2pdf.doc.ws.daisy.marbes.cz",
                                             "AegisJaxWsWsdlNsImplService"));
            factory.setWsdlLocation("http://localhost:" + PORT + "/aegisJaxWsWSDLNS?wsdl");
        }
        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
        factory.setAddress("http://localhost:" + PORT + "/aegisJaxWsWSDLNS");
        client = (AegisJaxWsWsdlNs)factory.create();
    }
 
Example 14
Source File: WebServiceIntegrationTestConfiguration.java    From tutorial-soap-spring-boot-cxf with MIT License 5 votes vote down vote up
@Bean
public WeatherService weatherServiceIntegrationTestClient() {
    JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean();
    jaxWsProxyFactory.setServiceClass(WeatherService.class);
    jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL);
    return (WeatherService) jaxWsProxyFactory.create();
}
 
Example 15
Source File: MEXTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGet() {
    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setBus(getStaticBus());
    proxyFac.setAddress("http://localhost:" + PORT + "/jaxws/addmex");
    proxyFac.getFeatures().add(new LoggingFeature());
    MetadataExchange exc = proxyFac.create(MetadataExchange.class);
    Metadata metadata = exc.get2004();
    assertNotNull(metadata);
    assertEquals(2, metadata.getMetadataSection().size());


    assertEquals("http://schemas.xmlsoap.org/wsdl/",
                 metadata.getMetadataSection().get(0).getDialect());
    assertEquals("http://apache.org/cxf/systest/ws/addr_feature/",
                 metadata.getMetadataSection().get(0).getIdentifier());
    assertEquals("http://www.w3.org/2001/XMLSchema",
                 metadata.getMetadataSection().get(1).getDialect());

    GetMetadata body = new GetMetadata();
    body.setDialect("http://www.w3.org/2001/XMLSchema");
    metadata = exc.getMetadata(body);
    assertEquals(1, metadata.getMetadataSection().size());
    assertEquals("http://www.w3.org/2001/XMLSchema",
                 metadata.getMetadataSection().get(0).getDialect());
}
 
Example 16
Source File: TestUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static Resource createResourceClient(EndpointReferenceType ref) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(Resource.class);
    factory.setAddress(ref.getAddress().getValue());
    Resource proxy = (Resource) factory.create();

    // Add reference parameters
    AddressingProperties addrProps = new AddressingProperties();
    addrProps.setTo(ref);
    ((BindingProvider) proxy).getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProps);

    return proxy;
}
 
Example 17
Source File: XKMSClientFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static XKMSPortType create(String endpointAddress, Bus bus) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceClass(XKMSPortType.class);
    factory.setAddress(endpointAddress);

    Map<String, Object> properties = new HashMap<>();
    properties.put("jaxb.additionalContextClasses",
                   new Class[] {ResultDetails.class});
    factory.setProperties(properties);

    return (XKMSPortType)factory.create();
}
 
Example 18
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 19
Source File: JmsServiceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Greeter greeterJms() {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(Greeter.class);
    factory.setAddress("jms:queue:greeter");
    ConnectionFactory connectionFactory = createConnectionFactory();
    factory.setFeatures(Collections.singletonList(new ConnectionFactoryFeature(connectionFactory)));
    return factory.create(Greeter.class);
}
 
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());
}