Package org.apache.cxf.jaxrs.client

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


            // Only testing the endpoints, not the clients here
            return;
        }
        String address = "https://localhost:" + test.port + "/xmlsig";
       
        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.setServiceClass(BookStore.class);
       
        BookStore store = bean.create(BookStore.class);
        try {
            store.addBook(new Book("CXF", 126L));
            fail("Failure expected on no Signature");
        } catch (WebApplicationException ex) {
            // expected
View Full Code Here


            // Only testing the endpoints, not the clients here
            return;
        }
        String address = "https://localhost:" + test.port + "/xmlsec-validate";
       
        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.encryption.username", "bob");
        properties.put("ws-security.encryption.properties",
                       "org/apache/cxf/systest/jaxrs/security/bob.properties");
        properties.put("ws-security.signature.properties",
                       "org/apache/cxf/systest/jaxrs/security/alice.properties");
        bean.setProperties(properties);
       
        XmlEncOutInterceptor encInterceptor = new XmlEncOutInterceptor();
        encInterceptor.setKeyIdentifierType(SecurityUtils.X509_CERT);
        encInterceptor.setSymmetricEncAlgorithm(XMLCipher.AES_128);
        bean.getOutInterceptors().add(encInterceptor);
        bean.getInInterceptors().add(new XmlEncInInterceptor());
        bean.getInInterceptors().add(new XmlSigInInterceptor());

        bean.setServiceClass(BookStore.class);
       
        BookStore store = bean.create(BookStore.class);
        try {
            store.addBook(new Book("CXF", 126L));
            fail("Failure expected on no Signature");
        } catch (WebApplicationException ex) {
            // expected
View Full Code Here

            // Only testing the endpoints, not the clients here
            return;
        }
        String address = "https://localhost:" + test.port + "/xmlsec-validate";
       
        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.encryption.username", "bob");
        properties.put("ws-security.encryption.properties",
                       "org/apache/cxf/systest/jaxrs/security/bob.properties");
        properties.put("ws-security.signature.properties",
                       "org/apache/cxf/systest/jaxrs/security/alice.properties");
        bean.setProperties(properties);
       
        XmlSigOutInterceptor sigInterceptor = new XmlSigOutInterceptor();
        bean.getOutInterceptors().add(sigInterceptor);
        bean.getInInterceptors().add(new XmlEncInInterceptor());
        bean.getInInterceptors().add(new XmlSigInInterceptor());

        bean.setServiceClass(BookStore.class);
       
        BookStore store = bean.create(BookStore.class);
        try {
            store.addBook(new Book("CXF", 126L));
            fail("Failure expected on no Encryption");
        } catch (WebApplicationException ex) {
            // expected
View Full Code Here

    }
   
    @Test
    public void testGetBookFastinfoset() throws Exception {
       
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress("http://localhost:" + PORT + "/test/services/rest3/bookstore/fastinfoset2");
        bean.getInInterceptors().add(new FIStaxInInterceptor());
        JAXBElementProvider p = new JAXBElementProvider();
        p.setConsumeMediaTypes(Collections.singletonList("application/fastinfoset"));
        bean.setProvider(p);
       
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(FIStaxInInterceptor.FI_GET_SUPPORTED, Boolean.TRUE);
        bean.setProperties(props);
       
        WebClient client = bean.createWebClient();
        Book b = client.accept("application/fastinfoset").get(Book.class);
        assertEquals("CXF2", b.getName());
        assertEquals(2L, b.getId());
    }
View Full Code Here

    }
   
    @Test
    public void testPostGetBookFastinfoset() throws Exception {
       
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress("http://localhost:" + PORT + "/test/services/rest3/bookstore/fastinfoset");
        bean.getOutInterceptors().add(new FIStaxOutInterceptor());
        bean.getInInterceptors().add(new FIStaxInInterceptor());
        JAXBElementProvider p = new JAXBElementProvider();
        p.setConsumeMediaTypes(Collections.singletonList("application/fastinfoset"));
        p.setProduceMediaTypes(Collections.singletonList("application/fastinfoset"));
        bean.setProvider(p);
       
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(FIStaxOutInterceptor.FI_ENABLED, Boolean.TRUE);
        bean.setProperties(props);
       
        WebClient client = bean.createWebClient();
        Book b = new Book("CXF", 1L);
        Book b2 = client.type("application/fastinfoset").accept("application/fastinfoset")
            .post(b, Book.class);
        assertEquals(b2.getName(), b.getName());
        assertEquals(b2.getId(), b.getId());
View Full Code Here

    }
   
    @Test
    public void testNoBook357WebClient() throws Exception {
       
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("org.apache.cxf.http.throw_io_exceptions", Boolean.TRUE);
        bean.setProperties(properties);
        bean.setAddress("http://localhost:" + PORT + "/test/services/rest/bookstore/356");
        WebClient wc = bean.createWebClient();
        Response response = wc.get();
        assertEquals(404, response.getStatus());
        String msg = IOUtils.readStringFromStream((InputStream)response.getEntity());
        assertEquals("No Book with id 356 is available", msg);
       
View Full Code Here

   
    @Test
    public void testOtherInterceptorDrainingStream() throws Exception {

        String baseAddress = "http://localhost:" + PORT + "/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:" + PORT + "/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:" + PORT + "/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:" + PORT + "/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();
        WebClient.getConfig(proxy).getRequestContext().put("org.apache.cxf.http.no_io_exceptions", false);
        try {
            //321 is special case - causes error code of 525
            proxy.getBook(new Long(param));
            fail("Method should have thrown an exception");
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.