Java Code Examples for org.apache.cxf.jaxrs.client.WebClient#create()
The following examples show how to use
org.apache.cxf.jaxrs.client.WebClient#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: OIDCKeysServiceTest.java From cxf with Apache License 2.0 | 6 votes |
@org.junit.Test public void testGetRSAPublicKey() throws Exception { URL busFile = OIDCFlowTest.class.getResource("client.xml"); String address = "https://localhost:" + JCACHE_SERVER.getPort() + "/services/"; WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", busFile.toString()); client.accept("application/json"); client.path("keys/"); Response response = client.get(); JsonWebKeys jsonWebKeys = response.readEntity(JsonWebKeys.class); assertEquals(1, jsonWebKeys.getKeys().size()); JsonWebKey jsonWebKey = jsonWebKeys.getKeys().get(0); assertEquals(KeyType.RSA, jsonWebKey.getKeyType()); assertEquals("alice", jsonWebKey.getKeyId()); assertNotNull(jsonWebKey.getProperty("n")); assertNotNull(jsonWebKey.getProperty("e")); // Check we don't send the private key back checkPrivateKeyParametersNotPresent(jsonWebKeys); }
Example 2
Source File: CommonSteps.java From attic-rave with Apache License 2.0 | 6 votes |
@Given("the user \"$username\" with the password of \"$password\" is logged into the system expecting \"$datatype\"") public void userIsLoggedIn(String username, String password, String datatype) { WebClient client; if (datatype.equals("JSON")) { JacksonJsonProvider json = new JacksonJsonProvider(); client = WebClient.create(baseURL, Collections.singletonList(json), true); client.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE); } else { client = WebClient.create(baseURL, true); client.type(MediaType.APPLICATION_XML_TYPE).accept(MediaType.APPLICATION_XML_TYPE); } String authorizationHeader = "Basic " + org.apache.cxf.common.util.Base64Utility.encode((username + ":" + password).getBytes()); client.header("Authorization", authorizationHeader); getState().put(KEY_WEB_CLIENT, client); }
Example 3
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testSetManyCookiesWebClient() throws Exception { WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/setmanycookies"); Response r = client.type("*/*").get(); assertEquals(200, r.getStatus()); List<Object> cookies = r.getMetadata().get("Set-Cookie"); assertNotNull(cookies); assertEquals(3, cookies.size()); boolean hasDummy1 = false; boolean hasDummy2 = false; boolean hasJSESSION = false; for (Object o : cookies) { String c = o.toString(); hasDummy1 |= c.contains("=dummy;"); hasDummy2 |= c.contains("=dummy2;"); hasJSESSION |= c.contains("JSESSIONID"); } assertTrue("Did not contain JSESSIONID", hasJSESSION); assertTrue("Did not contain dummy", hasDummy1); assertTrue("Did not contain dummy2", hasDummy2); }
Example 4
Source File: TestService.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test public void testGetDecisionByAttributesBooleanXML() { if (!waitForWADL()) { return; } WebClient client = WebClient.create(ENDPOINT_ADDRESS); client.header("Authorization", "Basic YWRtaW46YWRtaW4="); client.type("application/xml"); client.accept("application/xml"); client.path("by-attrib-boolean"); String request = readReource("xml/request-by-attrib-bool-1.xml"); String response = readReource("xml/response-by-attrib-bool-1.xml"); String webRespose = client.post(request, String.class); assertEquals(response, webRespose); }
Example 5
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testNonMatchingSignatureAlgorithm() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner("rsa-sha512", keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsig/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(400, response.getStatus()); }
Example 6
Source File: SakaiScriptSetUserTimeZoneTest.java From sakai with Educational Community License v2.0 | 6 votes |
@Test public void testSetUserTimeZone() { WebClient client = WebClient.create(getFullEndpointAddress()); addClientMocks(client); // client call client.accept("text/plain"); client.path("/" + getOperation()); client.query("sessionid", SESSION_ID); client.query("eid", "admin"); client.query("timeZoneId", "Europe/Oslo"); // client result String result = client.get(String.class); // test verifications assertNotNull(result); assertEquals("success", result); }
Example 7
Source File: DigestAuthSupplierSpringTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void test() { WebClient client = WebClient.create("http://localhost:" + port, (String) null); assertThrows(NotAuthorizedException.class, () -> client.get(String.class)); HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit(); conduit.setAuthSupplier(new DigestAuthSupplier()); conduit.getAuthorization().setUserName(USER); conduit.getAuthorization().setPassword(PWD); assertEquals(Controller.RESPONSE, client.get(String.class)); }
Example 8
Source File: JWTAlgorithmTest.java From cxf with Apache License 2.0 | 5 votes |
@org.junit.Test public void testSignatureProperties() throws Exception { URL busFile = JWTAlgorithmTest.class.getResource("client.xml"); List<Object> providers = new ArrayList<>(); providers.add(new JacksonJsonProvider()); providers.add(new JwtAuthenticationClientFilter()); String address = "https://localhost:" + PORT + "/signedjwt/bookstore/books"; WebClient client = WebClient.create(address, providers, busFile.toString()); client.type("application/json").accept("application/json"); // Create the JWT Token JwtClaims claims = new JwtClaims(); claims.setSubject("alice"); claims.setIssuer("DoubleItSTSIssuer"); claims.setIssuedAt(Instant.now().getEpochSecond()); claims.setAudiences(toList(address)); JwtToken token = new JwtToken(claims); Map<String, Object> properties = new HashMap<>(); properties.put("rs.security.signature.properties", "org/apache/cxf/systest/jaxrs/security/alice.jwk.properties"); properties.put(JwtConstants.JWT_TOKEN, token); WebClient.getConfig(client).getRequestContext().putAll(properties); Response response = client.post(new Book("book", 123L)); assertEquals(response.getStatus(), 200); Book returnedBook = response.readEntity(Book.class); assertEquals(returnedBook.getName(), "book"); assertEquals(returnedBook.getId(), 123L); }
Example 9
Source File: JAXRSSoapBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookTransform() throws Exception { String address = "http://localhost:" + PORT + "/test/v1/rest-transform/bookstore/books/123"; WebClient client = WebClient.create(address); Response r = client.get(); String str = getStringFromInputStream((InputStream)r.getEntity()); assertTrue(str.contains("TheBook")); }
Example 10
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookByHeaderPerRequestConstructorFault() throws Exception { String address = "http://localhost:" + PORT + "/bookstore2/bookheaders"; WebClient wc = WebClient.create(address); wc.accept("application/xml"); wc.header("BOOK", "1", "2", "4"); Response r = wc.get(); assertEquals(400, r.getStatus()); assertEquals("Constructor: Header value 3 is required", r.readEntity(String.class)); }
Example 11
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookFromResponseWithWebClientAndReader() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/genericresponse/123"; WebClient wc = WebClient.create(address); Response r = wc.accept("application/xml").get(); assertEquals(200, r.getStatus()); Book book = r.readEntity(Book.class); assertEquals(123L, book.getId()); }
Example 12
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testEchoBookElementWebClient() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/element/echo"); wc.type("application/xml").accept("application/json"); Book book = wc.post(new Book("\"Jack\" & \"Jill\"", 123L), Book.class); assertEquals(123L, book.getId()); assertEquals("\"Jack\" & \"Jill\"", book.getName()); wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/element/echo"); wc.type("application/xml").accept("application/xml"); book = wc.post(new Book("Jack & Jill", 123L), Book.class); assertEquals(123L, book.getId()); assertEquals("Jack & Jill", book.getName()); }
Example 13
Source File: JweJwsReferenceTest.java From cxf with Apache License 2.0 | 5 votes |
@org.junit.Test public void testEncryptionIncludeCertSha1NegativeTest() throws Exception { URL busFile = JweJwsReferenceTest.class.getResource("client.xml"); List<Object> providers = new ArrayList<>(); providers.add(new JacksonJsonProvider()); providers.add(new JweWriterInterceptor()); String address = "http://localhost:" + PORT + "/jweincludecert/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", "alice"); properties.put("rs.security.keystore.password", "password"); properties.put("rs.security.key.password", "password"); properties.put("rs.security.keystore.file", "keys/alice.jks"); properties.put("rs.security.encryption.content.algorithm", "A128GCM"); properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP"); properties.put("rs.security.encryption.include.cert.sha1", "true"); WebClient.getConfig(client).getRequestContext().putAll(properties); // Failure expected as we are encrypting to "alice" instead of "bob" Response response = client.post(new Book("book", 123L)); assertNotEquals(response.getStatus(), 200); }
Example 14
Source File: JAXRSRxJava2FlowableTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetHelloWorldJsonSingle() throws Exception { String address = "http://localhost:" + PORT + "/rx22/flowable/textJsonSingle"; WebClient wc = WebClient.create(address, Collections.singletonList(new JacksonJsonProvider())); HelloWorldBean bean = wc.accept("application/json").get(HelloWorldBean.class); assertEquals("Hello", bean.getGreeting()); assertEquals("World", bean.getAudience()); }
Example 15
Source File: HelloWorldIT.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testPing() throws Exception { WebClient client = WebClient.create(endpointUrl + "/hello/echo/SierraTangoNevada"); Response r = client.accept("text/plain").get(); assertEquals(Response.Status.OK.getStatusCode(), r.getStatus()); String value = IOUtils.toString((InputStream)r.getEntity()); assertEquals("SierraTangoNevada", value); }
Example 16
Source File: JAXRS20ClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testBookExistsServerStreamReplace() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/books/check2"; WebClient wc = WebClient.create(address); wc.accept("text/plain").type("text/plain"); assertTrue(wc.post("s", Boolean.class)); }
Example 17
Source File: JAXRS20ClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
private void doTestGetGenericBook(String address, long bookId, boolean checkAnnotations) throws Exception { WebClient wc = WebClient.create(address); wc.accept("application/xml"); Book book = wc.get(Book.class); assertEquals(bookId, book.getId()); MediaType mt = wc.getResponse().getMediaType(); assertEquals("application/xml;charset=ISO-8859-1", mt.toString()); if (checkAnnotations) { assertEquals("OK", wc.getResponse().getHeaderString("Annotations")); } else { assertNull(wc.getResponse().getHeaderString("Annotations")); } }
Example 18
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetHeadBook123WebClient() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/getheadbook/"; WebClient client = WebClient.create(address); Response r = client.head(); assertEquals("HEAD_HEADER_VALUE", r.getMetadata().getFirst("HEAD_HEADER")); }
Example 19
Source File: OIDCFlowTest.java From cxf with Apache License 2.0 | 5 votes |
@org.junit.Test public void testAuthorizationCodeFlowUnsignedJWT() throws Exception { URL busFile = OIDCFlowTest.class.getResource("client.xml"); String address = "https://localhost:" + port + "/unsignedjwtservices/"; WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", busFile.toString()); // Save the Cookie for the second request... WebClient.getConfig(client).getRequestContext().put( org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE); JwtClaims claims = new JwtClaims(); claims.setIssuer("consumer-id"); claims.setIssuedAt(Instant.now().getEpochSecond()); claims.setAudiences( Collections.singletonList("https://localhost:" + port + "/unsignedjwtservices/")); JwsHeaders headers = new JwsHeaders(); headers.setAlgorithm("none"); JwtToken token = new JwtToken(headers, claims); JwsJwtCompactProducer jws = new JwsJwtCompactProducer(token); String request = jws.getSignedEncodedJws(); // Get Authorization Code AuthorizationCodeParameters parameters = new AuthorizationCodeParameters(); parameters.setConsumerId("consumer-id"); parameters.setScope("openid"); parameters.setResponseType("code"); parameters.setPath("authorize/"); parameters.setRequest(request); String location = OAuth2TestUtils.getLocation(client, parameters); String code = OAuth2TestUtils.getSubstring(location, "code"); assertNotNull(code); }
Example 20
Source File: CrossOriginSimpleTest.java From cxf with Apache License 2.0 | 4 votes |
@Before public void before() { List<Object> providers = new ArrayList<>(); providers.add(new JacksonJsonProvider()); configClient = WebClient.create("http://localhost:" + PORT + "/config", providers); }