Java Code Examples for javax.ws.rs.client.ClientBuilder#newClient()
The following examples show how to use
javax.ws.rs.client.ClientBuilder#newClient() .
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: ApiIT.java From greenmail with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // Check if executed inside target directory or module directory String pathPrefix =new File(".").getCanonicalFile().getName().equals("target") ? "../" : "./"; server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(18080); connector.setHost("localhost"); server.setConnectors(new Connector[]{connector}); WebAppContext context = new WebAppContext(); context.setDescriptor(pathPrefix + "src/main/webapp/WEB-INF/web.xml"); context.setResourceBase(pathPrefix + "src/main/webapp"); context.setContextPath("/"); context.setParentLoaderPriority(true); server.setHandler(context); server.start(); client = ClientBuilder.newClient(); root = client.target("http://" + connector.getHost() + ':' + connector.getPort() + '/'); }
Example 2
Source File: SimpleClientTest.java From resteasy-examples with Apache License 2.0 | 6 votes |
@Test public void testResponse() throws Exception { // fill out a query param and execute a get request Client client = ClientBuilder.newClient(); WebTarget target = client.target("http://localhost:9095/customers"); Response response = target.queryParam("name", "Bill").request().get(); try { Assert.assertEquals(200, response.getStatus()); Customer cust = response.readEntity(Customer.class); Assert.assertEquals("Bill", cust.getName()); } finally { response.close(); client.close(); } }
Example 3
Source File: JAXRS20ClientServerBookTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testGetSetEntityStream() { String address = "http://localhost:" + PORT + "/bookstore/entityecho"; String entity = "BOOKSTORE"; Client client = ClientBuilder.newClient(); client.register(new ClientRequestFilter() { @Override public void filter(ClientRequestContext context) throws IOException { context.setEntityStream(new ReplacingOutputStream( context.getEntityStream(), 'X', 'O')); } }); WebTarget target = client.target(address); Response response = target.request().post( Entity.entity(entity.replace('O', 'X'), "text/plain")); assertEquals(entity, response.readEntity(String.class)); }
Example 4
Source File: EndpointInputValidationTest.java From tool.accelerate.core with Apache License 2.0 | 5 votes |
private Response callEndpoint(String endpoint) throws Exception { Client client = ClientBuilder.newClient(); String port = System.getProperty("liberty.test.port"); String url = "http://localhost:" + port + endpoint; System.out.println("Testing " + url); Response response = client.target(url).request().get(); return response; }
Example 5
Source File: JAXRS20ClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookSpecProviderWithFeature() { String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple"; Client client = ClientBuilder.newClient(); client.register(new ClientTestFeature()); WebTarget target = client.target(address); BookInfo book = target.request("application/xml").get(BookInfo.class); assertEquals(124L, book.getId()); book = target.request("application/xml").get(BookInfo.class); assertEquals(124L, book.getId()); }
Example 6
Source File: SendWithRemoteEnclaveReconnectIT.java From tessera with Apache License 2.0 | 5 votes |
@Test public void sendTransactiuonToSelfWhenEnclaveIsDown() throws InterruptedException { LOGGER.info("Stopping Enclave node"); enclaveExecManager.stop(); LOGGER.info("Stopped Enclave node"); RestUtils utils = new RestUtils(); byte[] transactionData = utils.createTransactionData(); final SendRequest sendRequest = new SendRequest(); sendRequest.setFrom(party.getPublicKey()); sendRequest.setPayload(transactionData); Client client = ClientBuilder.newClient(); final Response response = client.target(party.getQ2TUri()) .path("send") .request() .post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON)); assertThat(response.getStatus()).isEqualTo(503); // LOGGER.info("Starting Enclave node"); // enclaveExecManager.start(); // LOGGER.info("Started Enclave node"); // // final Response secondresponse = // client.target(party.getQ2TUri()) // .path("send") // .request() // .post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON)); // // assertThat(secondresponse.getStatus()).isEqualTo(201); }
Example 7
Source File: OmniturePollingConsumer.java From datacollector with Apache License 2.0 | 5 votes |
/** * Constructor for unauthenticated connections. * @param resourceUrl URL of streaming JSON resource. * @param reportDescription * @param responseTimeoutMillis How long to wait for a response from http endpoint. * @param username * @param sharedSecret * @param entityQueue A queue to place received chunks (usually a single JSON object) into. */ public OmniturePollingConsumer( final String resourceUrl, final String reportDescription, final long responseTimeoutMillis, final CredentialValue username, final CredentialValue sharedSecret, BlockingQueue<String> entityQueue, boolean useProxy, String proxyUri, String proxyUsername, String proxyPassword ) { this.responseTimeoutMillis = responseTimeoutMillis; this.username = username; this.sharedSecret = sharedSecret; this.reportDescription = reportDescription; this.entityQueue = entityQueue; ClientConfig config = new ClientConfig(); if(useProxy) { configureProxy( config, proxyUri, proxyUsername, proxyPassword ); } Client client = ClientBuilder.newClient(config); queueResource = client.target(resourceUrl + "?method=Report.Queue"); getResource = client.target(resourceUrl + "?method=Report.Get"); }
Example 8
Source File: RestIntegrationTest.java From streamline with Apache License 2.0 | 5 votes |
@Test public void testTopologyComponentTypes () throws Exception { Client client = ClientBuilder.newClient(new ClientConfig()); String url = rootUrl + "streams/componentbundles"; String response = client.target(url).request().get(String.class); Object expected = Arrays.asList(TopologyComponentBundle.TopologyComponentType.values()); Object actual = getEntities(response, TopologyComponentBundle.TopologyComponentType.class); Assert.assertEquals(expected, actual); }
Example 9
Source File: JsonStructureEndpointTest.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
private String slurp(final String url) { final Client client = ClientBuilder.newClient(); try { return client.target(url).request(APPLICATION_JSON_TYPE).get(String.class); } finally { client.close(); } }
Example 10
Source File: RxJava2HttpBinService.java From spring-cloud-circuitbreaker-demo with Apache License 2.0 | 4 votes |
public RxJava2HttpBinService() { this.client = ClientBuilder.newClient(); this.client.register(RxObservableInvokerProvider.class); this.client.register(RxFlowableInvokerProvider.class); }
Example 11
Source File: BankBillDataService.java From Java-EE-8-Design-Patterns-and-Best-Practices with MIT License | 4 votes |
private Response callMicroservice (String path, Object entity) { Client client = ClientBuilder.newClient(); WebTarget target = client.target (BASE_PATH); Response resp = target.path (path).request().post(Entity.json (entity)); return resp; }
Example 12
Source File: CallbackServlet.java From tutorials with MIT License | 4 votes |
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String clientId = config.getValue("client.clientId", String.class); String clientSecret = config.getValue("client.clientSecret", String.class); //Error: String error = request.getParameter("error"); if (error != null) { request.setAttribute("error", error); dispatch("/", request, response); return; } String localState = (String) request.getSession().getAttribute("CLIENT_LOCAL_STATE"); if (!localState.equals(request.getParameter("state"))) { request.setAttribute("error", "The state attribute doesn't match !!"); dispatch("/", request, response); return; } String code = request.getParameter("code"); Client client = ClientBuilder.newClient(); WebTarget target = client.target(config.getValue("provider.tokenUri", String.class)); Form form = new Form(); form.param("grant_type", "authorization_code"); form.param("code", code); form.param("redirect_uri", config.getValue("client.redirectUri", String.class)); try { JsonObject tokenResponse = target.request(MediaType.APPLICATION_JSON_TYPE) .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeaderValue(clientId, clientSecret)) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), JsonObject.class); request.getSession().setAttribute("tokenResponse", tokenResponse); } catch (Exception ex) { System.out.println(ex.getMessage()); request.setAttribute("error", ex.getMessage()); } dispatch("/", request, response); }
Example 13
Source File: SimpleApiClient.java From raml-java-client-generator with Apache License 2.0 | 4 votes |
protected Client getClient() { return ClientBuilder.newClient(); }
Example 14
Source File: FooClient.java From raml-java-client-generator with Apache License 2.0 | 4 votes |
protected Client getClient() { return ClientBuilder.newClient(); }
Example 15
Source File: RestAgent.java From micro-server with Apache License 2.0 | 3 votes |
public<T> T post(String url, Object payload,Class<T> type) { Client client = ClientBuilder.newClient(); WebTarget resource = client.target(url); Builder request = resource.request(); request.accept(MediaType.APPLICATION_JSON); return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); }
Example 16
Source File: RestAgent.java From micro-server with Apache License 2.0 | 3 votes |
public<T> T post(String url, Object payload,Class<T> type) { Client client = ClientBuilder.newClient(); WebTarget resource = client.target(url); Builder request = resource.request(); request.accept(MediaType.APPLICATION_JSON); return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); }
Example 17
Source File: RestAgent.java From micro-server with Apache License 2.0 | 3 votes |
public String get(String url) { Client client = ClientBuilder.newClient(); WebTarget resource = client.target(url); Builder request = resource.request(); request.accept(MediaType.TEXT_PLAIN); return request.get(String.class); }
Example 18
Source File: RestAgent.java From micro-server with Apache License 2.0 | 3 votes |
public String get(String url) { Client client = ClientBuilder.newClient(); WebTarget resource = client.target(url); Builder request = resource.request(); request.accept(MediaType.TEXT_PLAIN); return request.get(String.class); }
Example 19
Source File: RestAgent.java From micro-server with Apache License 2.0 | 3 votes |
public String get(String url) { Client client = ClientBuilder.newClient(); WebTarget resource = client.target(url); Builder request = resource.request(); request.accept(MediaType.TEXT_PLAIN); return request.get(String.class); }
Example 20
Source File: RestAgent.java From micro-server with Apache License 2.0 | 3 votes |
public String getJson(String url) { Client client = ClientBuilder.newClient(); WebTarget resource = client.target(url); Builder request = resource.request(); request.accept(MediaType.APPLICATION_JSON); return request.get(String.class); }