Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

In this page you can find the example usage for java.net URI URI.

Prototype

public URI(String str) throws URISyntaxException 

Source Link

Document

Constructs a URI by parsing the given string.

Usage

From source file:oracle.custom.ui.oauth.vo.OpenIdConfiguration.java

public static OpenIdConfiguration getInstance(String tenantName) throws Exception {
    if (configMap.containsKey(tenantName.toLowerCase())) {
        return configMap.get(tenantName.toLowerCase());
    }/* w ww  . ja va  2 s. c  om*/
    String url = ServerUtils.getIDCSBaseURL(tenantName) + endpoint;
    System.out.println("URL for tenant '" + tenantName + "' is '" + url + "'");
    HttpClient client = ServerUtils.getClient(tenantName);
    URI uri = new URI(url);
    HttpGet get = new HttpGet(uri);
    HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    HttpResponse response = client.execute(host, get);
    try {
        HttpEntity entity2 = response.getEntity();
        String res = EntityUtils.toString(entity2);
        EntityUtils.consume(entity2);
        ObjectMapper mapper = new ObjectMapper();
        //res = res.replaceAll("secureoracle.idcs.internal.oracle.com:443", "oc-140-86-12-131.compute.oraclecloud.com");
        OpenIdConfiguration openIdConfigInstance = mapper.readValue(res, OpenIdConfiguration.class);

        configMap.put(tenantName.toLowerCase(), openIdConfigInstance);
        return openIdConfigInstance;
    } finally {
        if (response instanceof CloseableHttpResponse) {
            ((CloseableHttpResponse) response).close();
        }
    }
}

From source file:org.epop.dataprovider.HTMLPage.java

public HTMLPage(String uri)
        throws ClientProtocolException, IOException, ParserConfigurationException, URISyntaxException {
    this(new URI(uri));
}

From source file:xworker.app.model.tree.http.HttpExtjsJsonTreeModelActions.java

/**
 * ????/*from  w w w. j a v  a  2  s . com*/
 * 
 * @param url
 * @param self
 * @param actionContext
 * @return
 * @throws IOException 
 */
@SuppressWarnings("unchecked")
public static Object getTreeDatas(String prefixUrl, String url, Thing self, ActionContext actionContext)
        throws IOException {
    HttpClient httpClient = getHttpClient(self, actionContext);
    if (httpClient != null) {
        HttpGet httpGet = new HttpGet(url);
        HttpEntity entity = null;
        try {
            HttpResponse response = httpClient.execute(httpGet);
            entity = response.getEntity();
            String content = EntityUtils.toString(entity);
            Object datas = JsonFormator.parse(content, actionContext);
            URI uri = null;
            if (prefixUrl != null && !"".equals(prefixUrl)) {
                //prefixUrl
                uri = new URI(prefixUrl);
            } else {
                uri = new URI(url);
            }

            if (datas instanceof List) {
                checkImageUrl((List<Map<String, Object>>) datas, uri);
            } else {
                checkImageUrl((Map<String, Object>) datas, uri);
            }

            return datas;
        } catch (Exception e) {
            logger.error("Get tree content error", e);
        } finally {
            if (entity != null) {
                EntityUtils.consume(entity);
            }
        }
    }

    return null;
}

From source file:org.bitcoinrt.client.JettyMtgoxClient.java

@Override
public void start() {
    try {//w  ww.j  a va  2s.  c o m
        webSocketClient.setConnectTimeout(10000);
        webSocketClient.start();
        webSocketClient.connect(new MtgoxWebSocket(), new URI(MTGOX_URL));
    } catch (Exception ex) {
        logger.error("Failed to start WebSocketClientFactory", ex);
    }
}

From source file:com.lazerycode.selenium.filedownloader.FileUploaderTest.java

@BeforeClass
public static void start() throws Exception {
    appContext = "/web";
    localWebServer = new JettyServer(webServerPort, appContext, null);
    downloadURI200 = new URI(webServerURL + ":" + webServerPort + appContext + "/downloadTest.html");
    downloadURI404 = new URI(webServerURL + ":" + webServerPort + appContext + "/doesNotExist.html");
    destURL += appContext;//from   w w  w. j a va2  s  . c o m

}

From source file:com.brightcove.com.uploader.helper.LoginHelperTest.java

@Test
public void testBasic() throws URISyntaxException, IOException, BadEnvironmentException, MediaAPIError {
    final URI targetURL = new URI("http://test.com");

    DefaultHttpClient client = new DefaultHttpClient();
    LoginHelper lh = new LoginHelper();
    assertNull(lh.getToken());//from  w  ww  .  ja  v a  2 s  .co m
    lh.setClient(client);
    assertEquals(client, lh.getClient());

}

From source file:com.yaauie.unfurl.UrlExpander.java

public String expand(String url) throws URISyntaxException, IOException {
    return expand(new URI(url)).toString();
}

From source file:fr.ippon.wip.http.request.GetRequestBuilder.java

public HttpRequestBase buildHttpRequest() throws URISyntaxException {
    URI encodedURI = new URI(getRequestedURL());
    URIBuilder uriBuilder = new URIBuilder(encodedURI);
    if (parameterMap != null)
        for (Map.Entry<String, String> entry : parameterMap.entries())
            uriBuilder.addParameter(entry.getKey(), entry.getValue());

    return new HttpGet(uriBuilder.build());
}

From source file:org.jboss.tools.feedhenry.ui.model.HttpUtil.java

/**
 * Set the proxy settings from ProxyService.
 * This method sets a {@link HttpRoutePlanner} to the client
 * //from  ww w.ja  v a 2 s  .c o m
 * @param client
 */
static void setupProxy(final DefaultHttpClient client) {
    client.setRoutePlanner(new HttpRoutePlanner() {

        /* (non-Javadoc)
         * @see org.apache.http.conn.routing.HttpRoutePlanner#determineRoute(org.apache.http.HttpHost, org.apache.http.HttpRequest, org.apache.http.protocol.HttpContext)
         */
        @Override
        public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context)
                throws HttpException {

            //use forced route if one exists
            HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
            if (route != null)
                return route;

            // if layered, is it secure?
            final Scheme scheme = client.getConnectionManager().getSchemeRegistry().getScheme(target);
            final boolean secure = scheme.isLayered();

            final IProxyService proxy = FHPlugin.getDefault().getProxyService();
            HttpHost host = null;
            if (proxy != null) {
                try {
                    IProxyData[] proxyDatas = proxy.select(new URI(target.toURI()));
                    for (IProxyData data : proxyDatas) {
                        if (data.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
                            host = new HttpHost(data.getHost(), data.getPort());
                            break;
                        }
                    }
                } catch (URISyntaxException e) {
                    FHPlugin.log(IStatus.ERROR, "Incorrect URI", e);
                }
            }
            if (host == null) {
                return new HttpRoute(target, null, secure);
            }
            return new HttpRoute(target, null, host, secure);
        }
    });

}

From source file:org.stem.api.BaseHttpClient.java

public BaseHttpClient(String uri) {
    try {/*from w  w  w  . j a v  a  2 s . c o m*/
        this.root = new URI(uri);
        client = HttpClients.createDefault();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}