org.apache.cxf.jaxrs.client.WebClient Java Examples

The following examples show how to use org.apache.cxf.jaxrs.client.WebClient. 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: JAXRSHTTPSignatureTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testPropertiesWrongSignatureVerification() {

    URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");

    List<Object> providers = new ArrayList<>();
    providers.add(new CreateSignatureInterceptor());
    providers.add(new VerifySignatureClientFilter());
    String address = "http://localhost:" + PORT + "/httpsigresponse/bookstore/books";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/xml").accept("application/xml");

    Map<String, Object> properties = new HashMap<>();
    properties.put("rs.security.signature.out.properties",
        "org/apache/cxf/systest/jaxrs/security/httpsignature/alice.httpsig.properties");
    properties.put("rs.security.signature.in.properties",
                   "org/apache/cxf/systest/jaxrs/security/httpsignature/alice.httpsig.properties");
    WebClient.getConfig(client).getRequestContext().putAll(properties);

    try {
        client.post(new Book("CXF", 126L));
        fail("Failure expected on the wrong signature verification keystore");
    } catch (Exception ex) {
        // expected
    }
}
 
Example #2
Source File: BrowseServiceTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Test
public void readArtifactContentTextPom()
    throws Exception
{
    BrowseService browseService = getBrowseService( authorizationHeader, true );

    WebClient.client( browseService ).accept( MediaType.TEXT_PLAIN );

    String text =
        browseService.getArtifactContentText( "commons-logging", "commons-logging", "1.1", null, "pom", null,
                                              TEST_REPO_ID ).getContent();

    log.info( "text: {}", text );

    assertThat( text ).contains(
        "<url>http://jakarta.apache.org/commons/${pom.artifactId.substring(8)}/</url>" ).contains(
        "<subscribe>[email protected]</subscribe>" );
}
 
Example #3
Source File: TestService.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: JAXRS20ClientServerBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testPreMatchContainerFilterThrowsException() {
    String address = "http://localhost:" + PORT + "/throwException";
    WebClient wc = WebClient.create(address);
    Response response = wc.get();
    assertEquals(500, response.getStatus());
    assertEquals("Prematch filter error", response.readEntity(String.class));
    assertEquals("prematch", response.getHeaderString("FilterException"));
    assertEquals("OK", response.getHeaderString("Response"));
    assertEquals("OK2", response.getHeaderString("Response2"));
    assertNull(response.getHeaderString("IOException"));
    assertNull(response.getHeaderString("DynamicResponse"));
    assertNull(response.getHeaderString("Custom"));
    assertEquals("serverWrite", response.getHeaderString("ServerWriterInterceptor"));
    assertEquals("serverWrite2", response.getHeaderString("ServerWriterInterceptor2"));
    assertEquals("serverWriteHttpResponse",
                 response.getHeaderString("ServerWriterInterceptorHttpResponse"));
    assertEquals("text/plain;charset=us-ascii", response.getMediaType().toString());
}
 
Example #5
Source File: Client.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final Tracer tracer = new Configuration("tracer-client") 
        .withSampler(new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(1))
        .withReporter(new ReporterConfiguration().withSender(
            new SenderConfiguration() {
                @Override
                public Sender getSender() {
                    return new Slf4jLogSender();
                }
            }
        ))
        .getTracer();
    final OpenTracingClientProvider provider = new OpenTracingClientProvider(tracer);

    final Response response = WebClient
        .create("http://localhost:9000/catalog", Arrays.asList(provider))
        .accept(MediaType.APPLICATION_JSON)
        .get();

    System.out.println(response.readEntity(String.class));
    response.close();
}
 
Example #6
Source File: MovieServiceTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidIssuer() throws Exception {
    final WebClient webClient = createWebClient(base);

    final String claims = "{" +
            "  \"sub\":\"Jane Awesome\"," +
            "  \"iss\":\"https://server.example.com\"," +
            "  \"groups\":[\"manager\",\"user\"]," +
            "  \"jti\":\"uB3r7zOr\"," +
            "  \"exp\":2552047942" +
            "}";

    final String token = Tokens.asToken(claims);
    final Response response = webClient.reset()
            .path("/api/movies")
            .header("Content-Type", "application/json")
            .header("Authorization", "Bearer " + token)
            .get();
    assertEquals(403, response.getStatus());
}
 
Example #7
Source File: PublicClientTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testAuthorizationCodeGrant() throws Exception {
    URL busFile = PublicClientTest.class.getResource("publicclient.xml");

    String address = "https://localhost:" + JCACHE_PORT + "/services/";
    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);

    // Get Authorization Code
    String code = OAuth2TestUtils.getAuthorizationCode(client);
    assertNotNull(code);

    // Now get the access token - note services2 doesn't require basic auth
    String address2 = "https://localhost:" + JCACHE_PORT + "/services2/";
    client = WebClient.create(address2, busFile.toString());

    ClientAccessToken accessToken =
        OAuth2TestUtils.getAccessTokenWithAuthorizationCode(client, code);
    assertNotNull(accessToken.getTokenKey());
}
 
Example #8
Source File: JAXRSHTTPSignatureTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testHttpSignature() 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(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(200, response.getStatus());

    Book returnedBook = response.readEntity(Book.class);
    assertEquals(126L, returnedBook.getId());
}
 
Example #9
Source File: PeerWebClient.java    From peer-os with Apache License 2.0 6 votes vote down vote up
public void joinP2PSwarm( final P2PConfig config ) throws PeerException
{
    WebClient client = null;
    Response response;
    try
    {
        remotePeer.checkRelation();
        String path = "/p2ptunnel";

        client = WebClientBuilder.buildPeerWebClient( peerInfo, path, provider );

        client.type( MediaType.APPLICATION_JSON );
        response = client.post( config );
    }
    catch ( Exception e )
    {
        LOG.error( e.getMessage(), e );
        throw new PeerException( String.format( "Error joining P2P swarm: %s", e.getMessage() ) );
    }
    finally
    {
        WebClientBuilder.close( client );
    }

    WebClientBuilder.checkResponse( response );
}
 
Example #10
Source File: JAXRSOAuth2Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJWTNoExpiry() throws Exception {
    String address = "https://localhost:" + port + "/oauth2-auth-jwt/token";
    WebClient wc = createWebClient(address);

    // Create the JWT Token
    String token = OAuth2TestUtils.createToken("resourceOwner", "alice",
                                               address, false, true);

    Map<String, String> extraParams = new HashMap<>();
    extraParams.put(Constants.CLIENT_AUTH_ASSERTION_TYPE,
                    "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
    extraParams.put(Constants.CLIENT_AUTH_ASSERTION_PARAM, token);

    try {
        OAuthClientUtils.getAccessToken(wc, new CustomGrant(), extraParams);
        fail("Failure expected on no expiry");
    } catch (Exception ex) {
        // expected
    }
}
 
Example #11
Source File: STSRESTTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testIssueSymmetricKeySaml1ShortKeyType() throws Exception {
    WebClient client = webClient()
        .path("saml1.1")
        .query("keyType", "SymmetricKey")
        .accept(MediaType.APPLICATION_XML);

    Document assertionDoc = client.get(Document.class);

    SamlAssertionWrapper assertion = validateSAMLToken(assertionDoc);
    assertTrue(assertion.getSaml2() == null && assertion.getSaml1() != null);

    List<String> methods = assertion.getConfirmationMethods();
    String confirmMethod = null;
    if (methods != null && !methods.isEmpty()) {
        confirmMethod = methods.get(0);
    }
    assertTrue(OpenSAMLUtil.isMethodHolderOfKey(confirmMethod));
    SAMLKeyInfo subjectKeyInfo = assertion.getSubjectKeyInfo();
    assertNotNull(subjectKeyInfo.getSecret());
}
 
Example #12
Source File: AbstractArchivaRestTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
protected CommonServices getCommonServices( String authzHeader )
{
    CommonServices service =
        JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
                                   CommonServices.class,
                                   Arrays.asList( new JacksonJaxbJsonProvider( ), new JacksonJaxbXMLProvider( ) )  );

    if ( authzHeader != null )
    {
        WebClient.client( service ).header( "Authorization", authzHeader );
    }
    WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
    WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
    WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
    WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
    return service;
}
 
Example #13
Source File: JAXRSHTTPSignatureTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testHttpSignatureRsaSha512ServiceProperties() 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 + "/httpsigrsasha512props/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(200, response.getStatus());

    Book returnedBook = response.readEntity(Book.class);
    assertEquals(126L, returnedBook.getId());
}
 
Example #14
Source File: JAXRSHTTPSignatureTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnknownKeyId() 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(keyId -> privateKey, "unknown-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 #15
Source File: JAXRSHttpsBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBook123WebClientFromSpringWildcard() throws Exception {
    ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext(new String[] {CLIENT_CONFIG_FILE5});
    Object bean = ctx.getBean("bookService.proxyFactory");
    assertNotNull(bean);
    JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean;

    WebClient wc = (WebClient)cfb.create();
    assertEquals("https://localhost:" + PORT, wc.getBaseURI().toString());

    wc.accept("application/xml");
    wc.path("bookstore/securebooks/123");
    TheBook b = wc.get(TheBook.class);

    assertEquals(b.getId(), 123);
    b = wc.get(TheBook.class);
    assertEquals(b.getId(), 123);
    ctx.close();
}
 
Example #16
Source File: JAXRSHTTPSignatureTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testWrongHTTPMethod() throws Exception {

    URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");

    ClientTestFilter signatureFilter = new ClientTestFilter();
    signatureFilter.setHttpMethod("GET");

    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(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 #17
Source File: JAXRSMultipartTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddGetJaxbBooksWebClient() throws Exception {
    String address = "http://localhost:" + PORT + "/bookstore/books/jaxbonly";
    WebClient client = WebClient.create(address);

    client.type("multipart/mixed;type=application/xml").accept("multipart/mixed");

    Book b = new Book("jaxb", 1L);
    Book b2 = new Book("jaxb2", 2L);
    List<Book> books = new ArrayList<>();
    books.add(b);
    books.add(b2);
    Collection<? extends Book> coll = client.postAndGetCollection(books, Book.class);
    List<Book> result = new ArrayList<>(coll);
    Book jaxb = result.get(0);
    assertEquals("jaxb", jaxb.getName());
    assertEquals(1L, jaxb.getId());
    Book jaxb2 = result.get(1);
    assertEquals("jaxb2", jaxb2.getName());
    assertEquals(2L, jaxb2.getId());
}
 
Example #18
Source File: RestRequestTandemUseSpringRest.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 删除已经部署的请假流程
 *
 * @return
 * @throws java.io.IOException
 */
private static void deleteLeaveDeployment() throws IOException {
    WebClient client = createClient("repository/deployments");
    Response response = client.get();
    printResult("查询leave.bpmn", response);

    response = client.get();
    InputStream stream = (InputStream) response.getEntity();
    JsonNode responseNode = objectMapper.readTree(stream);
    Iterator<JsonNode> elements = responseNode.elements();
    JsonNode next = elements.next();
    ArrayNode arrayNode = (ArrayNode) next;
    for (JsonNode jsonNode : arrayNode) {
        String deploymentId = jsonNode.get("id").asText();
        if (StringUtils.isBlank(deploymentId)) {
            continue;
        }
        String url = "/repository/deployments/" + deploymentId + "?cascade=true";
        client = createClient(url);
        response = client.delete();
        printResult("删除deployment", response);
    }
}
 
Example #19
Source File: JAXRSSamlTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidSAMLTokenAsHeader() throws Exception {
    String address = "https://localhost:" + PORT + "/samlheader/bookstore/books/123";

    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(address);

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JAXRSSamlTest.class.getResource("client.xml");
    Bus springBus = bf.createBus(busFile.toString());
    bean.setBus(springBus);

    WebClient wc = bean.createWebClient();
    wc.header("Authorization", "SAML invalid_grant");
    Response r = wc.get();
    assertEquals(401, r.getStatus());
}
 
Example #20
Source File: JAXRSClientServerResourceCreatedSpringProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private List<Element> getWadlResourcesInfo(String baseURI, String requestURI, int size) throws Exception {
    WebClient client = WebClient.create(requestURI + "?_wadl&_type=xml");
    WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(10000000);
    Document doc = StaxUtils.read(new InputStreamReader(client.get(InputStream.class), StandardCharsets.UTF_8));
    Element root = doc.getDocumentElement();
    assertEquals(WadlGenerator.WADL_NS, root.getNamespaceURI());
    assertEquals("application", root.getLocalName());
    List<Element> resourcesEls = DOMUtils.getChildrenWithName(root,
                                                              WadlGenerator.WADL_NS, "resources");
    assertEquals(1, resourcesEls.size());
    Element resourcesEl = resourcesEls.get(0);
    assertEquals(baseURI, resourcesEl.getAttribute("base"));
    List<Element> resourceEls =
        DOMUtils.getChildrenWithName(resourcesEl,
                                     WadlGenerator.WADL_NS, "resource");
    assertEquals(size, resourceEls.size());
    return resourceEls;
}
 
Example #21
Source File: JAXRSOAuth2Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSAMLAudRestr() throws Exception {
    String address = "https://localhost:" + port + "/oauth2-auth/token";
    WebClient wc = createWebClient(address);

    String audienceURI = "https://localhost:" + port + "/oauth2-auth/token2";
    String assertion = OAuth2TestUtils.createToken(audienceURI, true, true);
    String encodedAssertion = Base64UrlUtility.encode(assertion);

    Map<String, String> extraParams = new HashMap<>();
    extraParams.put(Constants.CLIENT_AUTH_ASSERTION_TYPE, Constants.CLIENT_AUTH_SAML2_BEARER);
    extraParams.put(Constants.CLIENT_AUTH_ASSERTION_PARAM, encodedAssertion);

    try {
        OAuthClientUtils.getAccessToken(wc, new CustomGrant(), extraParams);
        fail("Failure expected on a bad audience restriction");
    } catch (OAuthServiceException ex) {
        // expected
    }
}
 
Example #22
Source File: JAXRSClientServerQueryParamBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testListOfStringsWebClient() throws Exception {
    WebClient wc = createWebClient();
    
    Response r = wc
            .path("/bookstore/querysub/listofstrings")
            .query("value", "this is")
            .query("value", "the book")
            .query("value", "title")
            .accept("text/xml")
            .get();

    assertThat(wc.getCurrentURI().toString(), endsWith("value=this+is&value=the+book&value=title"));
    try (InputStream is = (InputStream)r.getEntity()) {
        XMLSource source = new XMLSource(is);
        assertEquals("this is the book title", source.getValue("Book/name"));
    }
}
 
Example #23
Source File: JAXRSHttpsBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomVerbProxyFromSpringWildcard() throws Exception {
    ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext(new String[] {CLIENT_CONFIG_FILE3});
    Object bean = ctx.getBean("bookService.proxyFactory");
    assertNotNull(bean);
    JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean;

    BookStore bs = cfb.create(BookStore.class);
    WebClient.getConfig(bs).getRequestContext().put("use.httpurlconnection.method.reflection", true);
    // 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(bs).getRequestContext().put("use.async.http.conduit", false);

    Book book = bs.retrieveBook(new Book("Retrieve", 123L));
    assertEquals("Retrieve", book.getName());

    ctx.close();
}
 
Example #24
Source File: JAXRSOAuth2Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicAuthClientCred() throws Exception {
    String address = "https://localhost:" + port + "/oauth2/token";
    WebClient wc = createWebClient(address);
    ClientCredentialsGrant grant = new ClientCredentialsGrant();
    // Pass client_id & client_secret as form properties
    // (instead WebClient can be initialized with username & password)
    grant.setClientId("bob");
    grant.setClientSecret("bobPassword");
    try {
        OAuthClientUtils.getAccessToken(wc, grant);
        fail("Form based authentication is not supported");
    } catch (OAuthServiceException ex) {
        assertEquals(OAuthConstants.UNAUTHORIZED_CLIENT, ex.getError().getError());
    }

    ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
                                                           new Consumer("bob", "bobPassword"),
                                                           new ClientCredentialsGrant(),
                                                           true);
    assertNotNull(at.getTokenKey());
}
 
Example #25
Source File: TestService.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Test
public void testHomeXML() {
    if (!waitForWADL()) {
        return;
    }

    WebClient client = WebClient.create(ENDPOINT_ADDRESS);

    client.header("Authorization", "Basic YWRtaW46YWRtaW4=");
    client.type("application/xml");
    client.accept("application/xml");

    client.path("home");

    String response = readReource("xml/response-home.xml");

    String webRespose = client.get(String.class);
    assertEquals(response, webRespose);
}
 
Example #26
Source File: JAXRSLocalTransportTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxyWithQuery() throws Exception {
    BookStore localProxy =
        JAXRSClientFactory.create("local://books", BookStore.class);

    WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);

    Book book = localProxy.getBookByURLQuery(new String[] {"1", "2", "3"});
    assertEquals(123L, book.getId());
}
 
Example #27
Source File: OidcUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static OidcProviderMetadata getOidcProviderMetadata(String issuerURL) {
    Response response = WebClient.create(issuerURL).path("/.well-known/openid-configuration")
        .accept(MediaType.APPLICATION_JSON).get();
    if (Status.OK.getStatusCode() != response.getStatus()) {
        throw ExceptionUtils.toWebApplicationException(response);
    }
    return new OidcProviderMetadata(new JsonMapObjectReaderWriter().fromJson(response.readEntity(String.class)));
}
 
Example #28
Source File: JAXRSLDAPUserTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSearchUser() throws Exception {
    WebClient wc = WebClient.create("http://localhost:" + PORT);

    User user = wc.path("users/search/name==alice").get(User.class);
    Assert.assertEquals("alice", user.getName());
    Assert.assertEquals("smith", user.getSurname());
}
 
Example #29
Source File: RestRequestTandemUseSpringRest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
private static JsonNode queryAssignedTask(String userId) {
    WebClient client = createClient("runtime/tasks?assignee=" + userId);

    Response response = client.get();

    // 转换并输出响应结果
    return printResult("读取用户[" + userId + "]的任务", response);
}
 
Example #30
Source File: StepConfigApiTest.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("https://virtserver.swaggerhub.com/binhthgc/opencps/1.0.0", StepConfigApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}