public MicroProfileClientProxyImpl(ClientState initialState, ClassLoader loader, ClassResourceInfo cri, boolean isRoot, boolean inheritHeaders, ExecutorService executorService, Configuration configuration, CDIInterceptorWrapper interceptorWrapper, Object... varValues) { super(initialState, loader, cri, isRoot, inheritHeaders, varValues); cfg.getRequestContext().put(EXECUTOR_SERVICE_PROPERTY, executorService); cfg.getRequestContext().putAll(configuration.getProperties()); this.interceptorWrapper = interceptorWrapper; } //CHECKSTYLE:ON
@Override public Builder property(String name, Object value) { Map<String, Object> contextProps = WebClient.getConfig(webClient).getRequestContext(); Map<String, Object> filterProps = CastUtils.cast((Map<?, ?>)contextProps.get(PROPERTY_KEY)); if (filterProps == null) { filterProps = new HashMap<>(); contextProps.put(PROPERTY_KEY, filterProps); } if (value == null) { filterProps.remove(name); } else { filterProps.put(name, value); } return this; }
@Test public void testJweRsaJwsRsaCertInHeaders() throws Exception { String address = "https://localhost:" + PORT + "/jwejwsrsaCertInHeaders"; BookStore bs = createJweJwsBookStore(address, null, null); WebClient.getConfig(bs).getRequestContext().put("rs.security.signature.include.cert", "true"); WebClient.getConfig(bs).getRequestContext().put("rs.security.encryption.include.cert", "true"); String text = bs.echoText("book"); assertEquals("book", text); } @Test
@Test public void testPostEmptyFormAsInStream() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/emptyform"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getRequestContext().put("org.apache.cxf.empty.request", true); wc.type(MediaType.APPLICATION_FORM_URLENCODED); Response r = wc.post(new ByteArrayInputStream("".getBytes())); assertEquals("empty form", r.readEntity(String.class)); }
public MicroProfileClientProxyImpl(ClientState initialState, ClassLoader loader, ClassResourceInfo cri, boolean isRoot, boolean inheritHeaders, ExecutorService executorService, Configuration configuration, CDIInterceptorWrapper interceptorWrapper, Object... varValues) { super(initialState, loader, cri, isRoot, inheritHeaders, varValues); cfg.getRequestContext().put(EXECUTOR_SERVICE_PROPERTY, executorService); cfg.getRequestContext().putAll(configuration.getProperties()); this.interceptorWrapper = interceptorWrapper; } //CHECKSTYLE:ON
@Override public Builder property(String name, Object value) { Map<String, Object> contextProps = WebClient.getConfig(webClient).getRequestContext(); Map<String, Object> filterProps = CastUtils.cast((Map<?, ?>)contextProps.get(PROPERTY_KEY)); if (filterProps == null) { filterProps = new HashMap<>(); contextProps.put(PROPERTY_KEY, filterProps); } if (value == null) { filterProps.remove(name); } else { filterProps.put(name, value); } return this; }
private Book doRetrieveBook(boolean useReflection) { String address = "http://localhost:" + PORT + "/bookstore/retrieve"; WebClient wc = WebClient.create(address); wc.type("application/xml").accept("application/xml"); if (!useReflection) { WebClient.getConfig(wc).getRequestContext().put("use.httpurlconnection.method.reflection", false); } // CXF RS Client code will set this property to true if the http verb is unknown // and this property is not already set. The async conduit is loaded in the tests module // but we do want to test HTTPUrlConnection reflection hence we set this property to false WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", false); WebClient.getConfig(wc).getRequestContext().put("response.stream.auto.close", true); return wc.invoke("RETRIEVE", new Book("Retrieve", 123L), Book.class); }
public MicroProfileClientProxyImpl(URI baseURI, ClassLoader loader, ClassResourceInfo cri, boolean isRoot, boolean inheritHeaders, ExecutorService executorService, Configuration configuration, CDIInterceptorWrapper interceptorWrapper, Object... varValues) { super(new LocalClientState(baseURI), loader, cri, isRoot, inheritHeaders, varValues); cfg.getRequestContext().put(EXECUTOR_SERVICE_PROPERTY, executorService); cfg.getRequestContext().putAll(configuration.getProperties()); this.interceptorWrapper = interceptorWrapper; }
private void doTestGetBook(String address, boolean useAsync) { WebClient wc = createWebClient(address); if (useAsync) { WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true); } Book book = wc.get(Book.class); assertEquals(124L, book.getId()); validateResponse(wc); }
@Test public void testAddBookWebClient() { InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/add_book.txt"); String address = "http://localhost:" + PORT + "/bookstore/books/jaxb"; WebClient client = WebClient.create(address); WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart", "true"); client.type("multipart/related;type=text/xml").accept("text/xml"); Book book = client.post(is1, Book.class); assertEquals("CXF in Action - 2", book.getName()); }
public MicroProfileClientProxyImpl(URI baseURI, ClassLoader loader, ClassResourceInfo cri, boolean isRoot, boolean inheritHeaders, ExecutorService executorService, Configuration configuration, CDIInterceptorWrapper interceptorWrapper, Object... varValues) { super(new LocalClientState(baseURI), loader, cri, isRoot, inheritHeaders, varValues); cfg.getRequestContext().put(EXECUTOR_SERVICE_PROPERTY, executorService); cfg.getRequestContext().putAll(configuration.getProperties()); this.interceptorWrapper = interceptorWrapper; }
@Test public void testProxyServerOutFaultDirectDispacth() throws Exception { BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class); WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, "true"); Response r = localProxy.outfault(); assertEquals(403, r.getStatus()); }
@Test public void testWebClientDirectDispatch() throws Exception { WebClient localClient = WebClient.create("local://books"); WebClient.getConfig(localClient).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE); localClient.path("bookstore/books/123"); Book book = localClient.get(Book.class); assertEquals(123L, book.getId()); }
@Test public void testWebClientDirectDispatchBookType() throws Exception { WebClient localClient = WebClient.create("local://books", Collections.singletonList(new JacksonJsonProvider())); WebClient.getConfig(localClient).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE); localClient.path("bookstore/booktype"); BookType book = localClient.get(BookType.class); assertEquals(124L, book.getId()); }
@Test public void testPatchBookInputStream() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/patch"; WebClient wc = WebClient.create(address); wc.type("application/xml"); WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true); Book book = wc.invoke("PATCH", new ByteArrayInputStream( "<Book><name>Patch</name><id>123</id></Book>".getBytes()), Book.class); assertEquals("Patch", book.getName()); wc.close(); }
@org.junit.Test public void testBadEncryptingKey() throws Exception { URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml"); List<Object> providers = new ArrayList<>(); providers.add(new JacksonJsonProvider()); providers.add(new JweWriterInterceptor()); String address = "http://localhost:" + PORT + "/jweoaepgcm/bookstore/books"; WebClient client = WebClient.create(address, providers, busFile.toString()); client.type("application/json").accept("application/json"); Map<String, Object> properties = new HashMap<>(); properties.put("rs.security.keystore.type", "jwk"); properties.put("rs.security.keystore.alias", "AliceCert"); properties.put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt"); properties.put("rs.security.encryption.content.algorithm", "A128GCM"); properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP"); WebClient.getConfig(client).getRequestContext().putAll(properties); Response response = client.post(new Book("book", 123L)); assertNotEquals(response.getStatus(), 200); }
@Test public void testProxyServerInFaultDirectDispatch() throws Exception { BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class); WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, "true"); WebClient.getConfig(localProxy).getInFaultInterceptors().add(new TestFaultInInterceptor()); Response r = localProxy.infault2(); assertEquals(500, r.getStatus()); }
@org.junit.Test public void testWrongKeyEncryptionAlgorithm() throws Exception { URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml"); List<Object> providers = new ArrayList<>(); providers.add(new JacksonJsonProvider()); providers.add(new JweWriterInterceptor()); String address = "http://localhost:" + PORT + "/jweoaepgcm/bookstore/books"; WebClient client = WebClient.create(address, providers, busFile.toString()); client.type("application/json").accept("application/json"); Map<String, Object> properties = new HashMap<>(); properties.put("rs.security.keystore.type", "jwk"); properties.put("rs.security.keystore.alias", "2011-04-29"); properties.put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt"); properties.put("rs.security.encryption.content.algorithm", "A128GCM"); properties.put("rs.security.encryption.key.algorithm", "RSA1_5"); WebClient.getConfig(client).getRequestContext().putAll(properties); Response response = client.post(new Book("book", 123L)); assertNotEquals(response.getStatus(), 200); }
@Test public void testAddGetImageWebClient() throws Exception { InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"); String address = "http://localhost:" + PORT + "/bookstore/books/image"; WebClient client = WebClient.create(address); client.type("multipart/mixed").accept("multipart/mixed"); WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart", "true"); InputStream is2 = client.post(is1, InputStream.class); byte[] image1 = IOUtils.readBytesFromStream( getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg")); byte[] image2 = IOUtils.readBytesFromStream(is2); assertTrue(Arrays.equals(image1, image2)); }
@org.junit.Test public void testSmallEncryptionKeySize() throws Exception { URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml"); List<Object> providers = new ArrayList<>(); providers.add(new JacksonJsonProvider()); providers.add(new JweWriterInterceptor()); String address = "http://localhost:" + PORT + "/jwesmallkey/bookstore/books"; WebClient client = WebClient.create(address, providers, busFile.toString()); client.type("application/json").accept("application/json"); Map<String, Object> properties = new HashMap<>(); properties.put("rs.security.keystore.type", "jks"); properties.put("rs.security.keystore.alias", "smallkey"); properties.put("rs.security.keystore.password", "security"); properties.put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/smallkeysize.jks"); properties.put("rs.security.encryption.content.algorithm", "A128GCM"); properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP"); WebClient.getConfig(client).getRequestContext().putAll(properties); Response response = client.post(new Book("book", 123L)); assertNotEquals(response.getStatus(), 200); }