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:com.blackducksoftware.integration.jira.common.HubUrlParser.java

public static String getRelativeUrl(final String url) throws HubIntegrationException {
    if (url == null) {
        return null;
    }//  ww w.  j av a  2  s .c om
    try {
        final String baseUrl = getBaseUrl(url);
        final URI baseUri = new URI(baseUrl);
        final URI origUri = new URI(url);
        final URI relativeUri = baseUri.relativize(origUri);
        return relativeUri.toString();
    } catch (URISyntaxException e) {
        throw new HubIntegrationException("Invalid URI syntax exception on " + url + ": " + e.getMessage());
    }
}

From source file:com.cooksys.httpserver.ParsedHttpRequest.java

public static ParsedHttpRequest parseHttpRequest(HttpRequest request, String messageBody) {
    ParsedHttpRequest parsedRequest = new ParsedHttpRequest();

    parsedRequest.requestLine = request.getRequestLine().toString();
    parsedRequest.method = request.getRequestLine().getMethod();

    try {/* w  w w.  j  a va 2s  .  c o  m*/
        //Parse the URI
        URI uri = new URI(request.getRequestLine().getUri());
        parsedRequest.uriPath = uri.getPath();
        parsedRequest.uriParams = parseUrlParameters(uri);
        parsedRequest.headers = (parseHeaders(request));
        parsedRequest.messageBody = messageBody;
    } catch (URISyntaxException | ParseException ex) {
        Logger.getLogger(ParsedHttpRequest.class.getName()).log(Level.SEVERE, null, ex);
    }
    return parsedRequest;
}

From source file:org.piwik.sdk.QuickTrackTest.java

private static QueryHashMap<String, String> parseEventUrl(String url) throws Exception {
    QueryHashMap<String, String> values = new QueryHashMap<String, String>();

    List<NameValuePair> params = URLEncodedUtils.parse(new URI("http://localhost/" + url), "UTF-8");

    for (NameValuePair param : params) {
        values.put(param.getName(), param.getValue());
    }/*from  w w w.  j a  va 2s.c  o  m*/

    return values;
}

From source file:com.kylinolap.common.util.HadoopUtil.java

public static URI makeURI(String filePath) {
    try {//from  www  . j  a v  a  2s.  co  m
        return new URI(filePath);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Cannot create FileSystem from URI: " + filePath, e);
    }
}

From source file:steamdb.parser.HttpGetRequest.java

public String getPage(String url) throws Exception {

    URI uri = new URI(url);
    HttpGet request = new HttpGet(url);
    HttpResponse response = client.execute(request);
    //   System.out.println("Response Code : " + 
    //                       response.getStatusLine().getStatusCode());

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);//from w w w .j  av a2 s .c om
    }
    return result.toString();
}

From source file:org.ow2.bonita.facade.rest.apachehttpclient.ApacheHttpClientUtil.java

public static HttpClient getHttpClient(String serverAddress, String username, String password)
        throws URISyntaxException {
    URI serverURI = new URI(serverAddress);
    DefaultHttpClient client = new DefaultHttpClient();
    AuthScope authScope = new AuthScope(serverURI.getHost(), serverURI.getPort(), AuthScope.ANY_REALM,
            AuthScope.ANY_SCHEME);//from ww w . j a va 2s.  c o m
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    client.getCredentialsProvider().setCredentials(authScope, credentials);
    return client;
}

From source file:org.commonjava.aprox.bind.jaxrs.util.ResponseUtils.java

public static Response formatCreatedResponse(final String baseUri, final UriFormatter uriFormatter,
        final String... params) throws URISyntaxException {
    final URI location = new URI(uriFormatter.formatAbsolutePathTo(baseUri, params));
    return Response.created(location).build();
}

From source file:com.tweetlanes.android.urlservice.ApiService.java

public static HttpResponse getRequest(String url, String debugName) {
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet();
    HttpResponse response = null;//from  ww  w  . j  a v a  2s .co m
    try {
        request.setURI(new URI(url));
        //Log.d("tweetlanes url fetch", url);
        response = client.execute(request);
        //Log.d(TAG, debugName + " complete");
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return response;
}

From source file:me.footlights.core.crypto.Fingerprint.java

public static Option<Fingerprint> unapply(String s) {
    try {/*from w  ww  .  ja v a  2s  .  c o m*/
        return Option.apply(decode(new URI(s)));
    } catch (FormatException e) {
        log.log(Level.INFO, e.getLocalizedMessage() + ": " + s);
    } catch (NoSuchAlgorithmException e) {
        log.log(Level.WARNING, "No such algorithm", e);
    } catch (URISyntaxException e) {
        log.log(Level.INFO, "Bad fingerprint syntax: " + s);
    }

    return Option.apply(null);
}

From source file:org.jboss.tools.aerogear.hybrid.core.internal.util.HttpUtil.java

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

        @Override
        public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context)
                throws HttpException {
            IProxyService proxy = HybridCore.getDefault().getProxyService();
            HttpHost host = 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) {
                HybridCore.log(IStatus.ERROR, "Incorrect URI", e);
            }
            if (host == null) {
                return new HttpRoute(target);
            }
            return new HttpRoute(target, null, host, false);
        }
    });

}