List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder
public URIBuilder()
From source file:org.wso2.security.tools.product.manager.NotificationManager.java
private static void notifyStatus(String path, boolean status) throws NotificationManagerException { int i = 0;/*from w w w. ja v a 2 s. c om*/ while (i < 10) { try { URI uri = (new URIBuilder()).setHost(automationManagerHost).setPort(automationManagerPort) .setScheme("http").setPath(path).addParameter("containerId", myContainerId) .addParameter("status", String.valueOf(status)).build(); HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet get = new HttpGet(uri); HttpResponse response = httpClient.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { LOGGER.info("Notified successfully"); return; } else { i++; } Thread.sleep(2000); } catch (URISyntaxException | InterruptedException | IOException e) { e.printStackTrace(); LOGGER.error(e.toString()); i++; } } throw new NotificationManagerException("Error occurred while notifying status to Automation Manager"); }
From source file:com.uber.stream.kafka.mirrormaker.common.utils.HttpClientUtils.java
public static String getData(final HttpClient httpClient, final RequestConfig requestConfig, final String host, final int port, final String path) throws IOException, URISyntaxException { URI uri = new URIBuilder().setScheme("http").setHost(host).setPort(port).setPath(path).build(); HttpGet httpGet = new HttpGet(uri); httpGet.setConfig(requestConfig);//from w ww. j a va2 s .c om return httpClient.execute(httpGet, HttpClientUtils.createResponseBodyExtractor()); }
From source file:io.soabase.example.hello.HelloResourceApache.java
@GET public String getHello(@Context HttpHeaders headers) throws Exception { String result = "Service Name: " + info.getServiceName() + "\nInstance Name: " + info.getInstanceName() + "\nRequest Id: " + SoaRequestId.get(headers) + "\n"; URI uri = new URIBuilder().setHost(ClientUtils.serviceNameToHost("goodbye")).setPath("/goodbye").build(); HttpGet get = new HttpGet(uri); ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override/* ww w . ja va2s . c o m*/ public String handleResponse(HttpResponse response) throws IOException { return CharStreams.toString(new InputStreamReader(response.getEntity().getContent())); } }; String value = client.execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), get, responseHandler); return result + "\nGoodbye app says: \n\t" + value; }
From source file:org.wso2.carbon.dynamic.client.web.proxy.OAuthEndpointProxy.java
@POST @Consumes("application/x-www-form-urlencoded") @Produces("application/json") public Response issueAccessToken(MultivaluedMap<String, String> paramMap) { DefaultHttpClient httpClient = DCRProxyUtils.getHttpsClient(); String host = DCRProxyUtils.getKeyManagerHost(); Response response;//from w w w . jav a2 s . c om try { URI uri = new URIBuilder().setScheme(Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL) .setHost(host).setPath(Constants.RemoteServiceProperties.OAUTH2_TOKEN_ENDPOINT).build(); HttpHost httpHost = new HttpHost(uri.toString()); CloseableHttpResponse serverResponse = httpClient.execute(httpHost, null); HttpEntity responseData = serverResponse.getEntity(); int status = serverResponse.getStatusLine().getStatusCode(); String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF_8); response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build(); } catch (URISyntaxException | IOException e) { String msg = "Service invoke error occurred while registering client"; log.error(msg, e); response = Response.status(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } finally { httpClient.close(); } return response; }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesProviderUtils.java
static URI proxyServiceEndpoint(Proxy proxy, String namespace, String serviceName, int servicePort) { try {/*w ww. ja v a 2 s .c om*/ return new URIBuilder().setPort(proxy.getPort()).setHost("localhost").setScheme("http").setPath( "/api/v1/proxy/namespaces/" + namespace + "/services/" + serviceName + ":" + servicePort) .build(); } catch (URISyntaxException e) { throw new HalException(Severity.FATAL, "Malformed service details: " + e.getMessage()); } }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v1.KubernetesV1ProviderUtils.java
static URI proxyServiceEndpoint(Proxy proxy, String namespace, String serviceName, int servicePort) { try {//from ww w . j av a2s . c o m return new URIBuilder().setPort(proxy.getPort()).setHost("localhost").setScheme("http").setPath( "/api/v1/namespaces/" + namespace + "/services/" + serviceName + ":" + servicePort + "/proxy") .build(); } catch (URISyntaxException e) { throw new HalException(Severity.FATAL, "Malformed service details: " + e.getMessage()); } }
From source file:ar.edu.ubp.das.src.chat.actions.MessagesListAction.java
@Override public ForwardConfig execute(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException, RuntimeException { try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { Gson gson = new Gson(); //prepare http get SalaBean sala = (SalaBean) request.getSession().getAttribute("sala"); String login_tmst = (String) request.getSession().getAttribute("login_tmst"); String authToken = String.valueOf(request.getSession().getAttribute("token")); URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost("25.136.78.82").setPort(8080) .setPath("/mensajes/sala/" + sala.getId()); builder.setParameter("fecha_desde", login_tmst); HttpGet getRequest = new HttpGet(); getRequest.setURI(builder.build()); getRequest.addHeader("Authorization", "BEARER " + authToken); getRequest.addHeader("accept", "application/json; charset=ISO-8859-1"); CloseableHttpResponse getResponse = httpClient.execute(getRequest); HttpEntity responseEntity = getResponse.getEntity(); StatusLine responseStatus = getResponse.getStatusLine(); String restResp = EntityUtils.toString(responseEntity); if (responseStatus.getStatusCode() != 200) { throw new RuntimeException(restResp); }/* w w w. j ava 2s .c o m*/ //parse message data from response Type listType = new TypeToken<LinkedList<MensajeBean>>() { }.getType(); List<MensajeBean> mensajes = gson.fromJson(restResp, listType); if (!mensajes.isEmpty()) { request.getSession().setAttribute("ultimo_mensaje", mensajes.get(mensajes.size() - 1).getId_mensaje()); } request.setAttribute("mensajes", mensajes); return mapping.getForwardByName("success"); } catch (IOException | URISyntaxException | RuntimeException e) { request.setAttribute("message", "Error al intentar mostrar mensajes: " + e.getMessage()); response.setStatus(400); return mapping.getForwardByName("error"); } }
From source file:lh.api.showcase.server.api.lh.ApiRequestFactoryLhAbstract.java
@Override public URI getRequestUri(ApiDataArea area, NameValuePair resourceNameKey, List<NameValuePair> subResourceNameKey, List<NameValuePair> optionKeyValue) throws URISyntaxException { Preconditions.checkNotNull(area);// w w w .j a v a 2 s .co m Preconditions.checkNotNull(resourceNameKey); Preconditions.checkArgument(StringUtils.isNotEmpty(resourceNameKey.getName())); URIBuilder urib = new URIBuilder(); urib.setScheme(getScheme()); urib.setHost(getHost()); StringBuilder sb = new StringBuilder(); // build path sb.append("/"); sb.append(getVersion()); sb.append("/"); // area sb.append(area.toString().toLowerCase()); sb.append("/"); // resource sb.append(resourceNameKey.getName()); if (StringUtils.isNotEmpty(resourceNameKey.getValue())) { sb.append("/"); sb.append(resourceNameKey.getValue()); } // sub resources if (subResourceNameKey != null) { for (NameValuePair vp : subResourceNameKey) { if (StringUtils.isEmpty(vp.getName())) { continue; } sb.append("/"); sb.append(vp.getName()); if (StringUtils.isNotEmpty(vp.getValue())) { sb.append("/"); sb.append(vp.getValue()); } } } urib.setPath(sb.toString()); // parameters if (optionKeyValue != null && !optionKeyValue.isEmpty()) { urib.setParameters(optionKeyValue); } return urib.build(); }
From source file:com.m3958.apps.anonymousupload.integration.java.FileUploadTest.java
@Test public void testPostOne() throws ClientProtocolException, IOException, URISyntaxException { File f = new File("README.md"); Assert.assertTrue(f.exists());/*from w w w . ja v a 2 s.c o m*/ String c = Request.Post(new URIBuilder().setScheme("http").setHost("localhost").setPort(8080).build()) .body(MultipartEntityBuilder.create() .addBinaryBody("afile", f, ContentType.MULTIPART_FORM_DATA, f.getName()).build()) .execute().returnContent().asString(); String url = c.trim(); Assert.assertTrue(url.endsWith(".md")); String cc = Request.Get(url).execute().returnContent().asString(); Assert.assertTrue(cc.contains("vertx runmod")); testComplete(); }
From source file:org.apache.james.jmap.ContainerTest.java
@Test public void containerShouldBeReachableOnExposedPort() throws IOException, URISyntaxException { String containerIpAddress = container.getContainerIpAddress(); Integer containerPort = container.getMappedPort(80); Response response = Request .Get(new URIBuilder().setScheme("http").setHost(containerIpAddress).setPort(containerPort).build()) .execute();//from w w w . jav a 2s . co m assertThat(response.returnResponse().getStatusLine().getStatusCode()).isEqualTo(200); }