Package org.apache.cxf.jaxrs.client

Examples of org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean


    public JAXRSClientFactoryBean createJAXRSClientFactoryBean() {
        return createJAXRSClientFactoryBean(getAddress());
    }
   
    public JAXRSClientFactoryBean createJAXRSClientFactoryBean(String address) {
        JAXRSClientFactoryBean answer = newJAXRSClientFactoryBean();
        setupJAXRSClientFactoryBean(answer, address);
        if (isLoggingFeatureEnabled()) {
            if (getLoggingSizeLimit() > 0) {
                answer.getFeatures().add(new LoggingFeature(getLoggingSizeLimit()));
            } else {
                answer.getFeatures().add(new LoggingFeature());
            }
        }
        return answer;
    }
View Full Code Here


   
    @Test
    public void testOtherInterceptorDrainingStream() throws Exception {

        String baseAddress = "http://localhost:9092/test/services/rest";
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(baseAddress);
        bean.getInInterceptors().add(new TestStreamDrainInterptor());
        WebClient client = bean.createWebClient();
        client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE);
        Book b = client.get(Book.class);
        assertEquals(123, b.getId());
        assertEquals("CXF in Action", b.getName());
    }   
View Full Code Here

    }
   
    @Test
    public void testAddFeatureToClient() throws Exception {
        String baseAddress = "http://localhost:9092/test/services/rest";
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(baseAddress);
        bean.setResourceClass(BookStoreJaxrsJaxws.class);
        TestFeature testFeature = new TestFeature();
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        features.add((AbstractFeature)testFeature);
        bean.setFeatures(features);
        BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws)bean.create();
        Book b = proxy.getBook(new Long("123"));
        assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
        assertTrue("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());   
        assertEquals(123, b.getId());
        assertEquals("CXF in Action", b.getName());
View Full Code Here

   
    @Test
    public void testClientFaultOutInterceptor() throws Exception {
        //testing faults created by client out interceptor chain handled correctly
        String baseAddress = "http://localhost:9092/test/services/rest";
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(baseAddress);
        bean.setResourceClass(BookStoreJaxrsJaxws.class);
        final boolean addBadOutInterceptor = true;
        TestFeature testFeature = new TestFeature(addBadOutInterceptor);
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        features.add((AbstractFeature)testFeature);
        bean.setFeatures(features);
        BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws)bean.create();
        try {
            //321 is special case - causes error code of 525
            proxy.getBook(new Long("123"));
            fail("Method should have thrown an exception");
        } catch (Exception e) {
View Full Code Here

        }
    }
   
    private void serverFaultInInterceptorTest(String param) {
        String baseAddress = "http://localhost:9092/test/services/rest";
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(baseAddress);
        bean.setResourceClass(BookStoreJaxrsJaxws.class);
        TestFeature testFeature = new TestFeature();
        List<AbstractFeature> features = new ArrayList<AbstractFeature>();
        features.add((AbstractFeature)testFeature);
        bean.setFeatures(features);
        BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws)bean.create();
        try {
            //321 is special case - causes error code of 525
            proxy.getBook(new Long(param));
            fail("Method should have thrown an exception");
        } catch (Exception e) {
View Full Code Here

        assertEquals(204, response.getStatus());
    }
   
    @Test
    public void testEmptyPostProxy() throws Exception {
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress("http://localhost:" + PORT);
        bean.setResourceClass(BookStore.class);
        BookStore store = bean.create(BookStore.class);
        store.emptypost();
        assertEquals(204, WebClient.client(store).getResponse().getStatus());
    }
View Full Code Here

    }
   
    @Test
    public void testXopWebClient() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/xop";
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(address);
        bean.setProperties(Collections.singletonMap(org.apache.cxf.message.Message.MTOM_ENABLED,
                                                    (Object)"true"));
        WebClient client = bean.createWebClient();
        HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
        conduit.getClient().setReceiveTimeout(1000000);
        conduit.getClient().setConnectionTimeout(1000000);
       
        client.type("multipart/related").accept("multipart/related");
View Full Code Here

        doTestSignatureProxy(address, true, "file:", test.streaming);
    }
   
    private void doTestSignatureProxy(String address, boolean enveloping,
                                      String cryptoUrlPrefix, boolean streaming) throws Exception {
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(address);
       
        SpringBusFactory bf = new SpringBusFactory();
        URL busFile = JAXRSXmlSecTest.class.getResource("client.xml");
        Bus springBus = bf.createBus(busFile.toString());
        bean.setBus(springBus);

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("ws-security.callback-handler",
                       "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
        properties.put("ws-security.signature.username", "alice");
       
        String cryptoUrl = "org/apache/cxf/systest/jaxrs/security/alice.properties";
        if (cryptoUrlPrefix != null) {
            cryptoUrl = cryptoUrlPrefix + this.getClass().getResource("/" + cryptoUrl).toURI().getPath();
        }
        properties.put("ws-security.signature.properties", cryptoUrl);
        bean.setProperties(properties);
       
        if (streaming) {
            XmlSecOutInterceptor sigInterceptor = new XmlSecOutInterceptor();
            sigInterceptor.setSignRequest(true);
            bean.getOutInterceptors().add(sigInterceptor);
        } else {
            XmlSigOutInterceptor sigInterceptor = new XmlSigOutInterceptor();
            if (enveloping) {
                sigInterceptor.setStyle(XmlSigOutInterceptor.ENVELOPING_SIG);
            }
            bean.getOutInterceptors().add(sigInterceptor);
        }
        bean.setServiceClass(BookStore.class);
       
        BookStore store = bean.create(BookStore.class);
        try {
            Book book = store.addBook(new Book("CXF", 126L));
            assertEquals(126L, book.getId());
        } catch (WebApplicationException ex) {
            fail(ex.getMessage());
View Full Code Here

    private void doTestSignature(String address,
                                 boolean enveloping,
                                 boolean fromResponse,
                                 boolean useKeyInfo,
                                 boolean streaming) {
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(address);
       
        SpringBusFactory bf = new SpringBusFactory();
        URL busFile = JAXRSXmlSecTest.class.getResource("client.xml");
        Bus springBus = bf.createBus(busFile.toString());
        bean.setBus(springBus);

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("ws-security.callback-handler",
                       "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
        properties.put("ws-security.signature.username", "alice");
        properties.put("ws-security.signature.properties",
                       "org/apache/cxf/systest/jaxrs/security/alice.properties");
        bean.setProperties(properties);
        if (streaming) {
            XmlSecOutInterceptor sigOutInterceptor = new XmlSecOutInterceptor();
            sigOutInterceptor.setSignRequest(true);
            sigOutInterceptor.setKeyInfoMustBeAvailable(useKeyInfo);
            bean.getOutInterceptors().add(sigOutInterceptor);
           
            XmlSecInInterceptor sigInInterceptor = new XmlSecInInterceptor();
            sigInInterceptor.setRequireSignature(true);
            if (!useKeyInfo) {
                sigInInterceptor.setSignatureVerificationAlias("alice");
            }
            bean.getInInterceptors().add(sigInInterceptor);
        } else {
            XmlSigOutInterceptor sigOutInterceptor = new XmlSigOutInterceptor();
            if (enveloping) {
                sigOutInterceptor.setStyle(XmlSigOutInterceptor.ENVELOPING_SIG);
            }
            sigOutInterceptor.setKeyInfoMustBeAvailable(useKeyInfo);
            bean.getOutInterceptors().add(sigOutInterceptor);
           
            XmlSigInInterceptor sigInInterceptor = new XmlSigInInterceptor();
            sigInInterceptor.setKeyInfoMustBeAvailable(useKeyInfo);
            bean.getInInterceptors().add(sigInInterceptor);
        }
       
        WebClient wc = bean.createWebClient();
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
        try {
            Book book;
            if (!fromResponse) {
                book = wc.post(new Book("CXF", 126L), Book.class);
View Full Code Here

        String address, boolean sign, Map<String, Object> properties,
        EncryptionProperties encryptionProperties,
        boolean propagateException,
        boolean streaming
    ) throws Exception {
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(address);
       
        SpringBusFactory bf = new SpringBusFactory();
        URL busFile = JAXRSXmlSecTest.class.getResource("client.xml");
        Bus springBus = bf.createBus(busFile.toString());
        bean.setBus(springBus);

        bean.setProperties(properties);
        if (streaming) {
            XmlSecOutInterceptor encInterceptor = new XmlSecOutInterceptor();
            encInterceptor.setEncryptionKeyIdentifierType(encryptionProperties.getEncryptionKeyIdType());
            encInterceptor.setSymmetricEncAlgorithm(encryptionProperties.getEncryptionSymmetricKeyAlgo());
            encInterceptor.setEncryptionDigestAlgorithm(encryptionProperties.getEncryptionDigestAlgo());
            encInterceptor.setEncryptRequest(true);
            if (sign) {
                encInterceptor.setSignRequest(true);
            }
            bean.getOutInterceptors().add(encInterceptor);
           
            XmlSecInInterceptor encInInterceptor = new XmlSecInInterceptor();
            encInInterceptor.setRequireEncryption(true);
            bean.getInInterceptors().add(encInInterceptor);
        } else {
            if (sign) {
                bean.getOutInterceptors().add(new XmlSigOutInterceptor());
            }
            XmlEncOutInterceptor encInterceptor = new XmlEncOutInterceptor();
            encInterceptor.setKeyIdentifierType(encryptionProperties.getEncryptionKeyIdType());
            encInterceptor.setSymmetricEncAlgorithm(encryptionProperties.getEncryptionSymmetricKeyAlgo());
            encInterceptor.setDigestAlgorithm(encryptionProperties.getEncryptionDigestAlgo());
            bean.getOutInterceptors().add(encInterceptor);
           
            bean.getInInterceptors().add(new XmlEncInInterceptor());
            if (sign) {
                bean.getInInterceptors().add(new XmlSigInInterceptor());
            }
        }
       
        WebClient wc = bean.createWebClient();
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
        try {
            Book book = wc.post(new Book("CXF", 126L), Book.class);
            assertEquals(126L, book.getId());
        } catch (WebApplicationException ex) {
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.