Example usage for java.net URISyntaxException printStackTrace

List of usage examples for java.net URISyntaxException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:jp.go.nict.langrid.servicesupervisor.invocationprocessor.executor.intragrid.HttpClientUtil.java

/**
 * /*from  ww  w .j a  v a2 s . co m*/
 * 
 */
public static HttpClient createHttpClientWithHostConfig(URL url) {
    HttpClient client = new HttpClient();
    int port = url.getPort();
    if (port == -1) {
        port = url.getDefaultPort();
        if (port == -1) {
            port = 80;
        }
    }
    if ((url.getProtocol().equalsIgnoreCase("https")) && (sslSocketFactory != null)) {
        Protocol https = new Protocol("https",
                (ProtocolSocketFactory) new SSLSocketFactorySSLProtocolSocketFactory(sslSocketFactory), port);
        client.getHostConfiguration().setHost(url.getHost(), url.getPort(), https);
    } else {
        Protocol http = new Protocol("http", new SocketFactoryProtocolSocketFactory(SocketFactory.getDefault()),
                port);
        client.getHostConfiguration().setHost(url.getHost(), url.getPort(), http);
    }
    try {
        List<Proxy> proxies = ProxySelector.getDefault().select(url.toURI());
        for (Proxy p : proxies) {
            if (p.equals(Proxy.NO_PROXY))
                continue;
            if (!p.type().equals(Proxy.Type.HTTP))
                continue;
            InetSocketAddress addr = (InetSocketAddress) p.address();
            client.getHostConfiguration().setProxy(addr.getHostName(), addr.getPort());
            client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials("", ""));
            break;
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return client;
}

From source file:org.omnaest.utils.download.URIHelper.java

/**
 * Creates a new uri instance with the given parameters.
 * /*from w ww  . j a  va 2  s.  co m*/
 * @see URI#URI(String, String, String, String, String))
 * @param scheme
 *          : e.g. "http"
 * @param host
 *          : e.g. "www.google.de"
 * @param path
 *          : e.g. "search/subsearch"
 * @param queryParameters
 *          : e.g. "key1=value1", "key2=value2"
 * @return {@link URI}
 */
public static URI createURI(String scheme, String host, String path, String... queryParameters) {
    //
    URI uri = null;

    //
    try {
        //
        uri = new URI(scheme, host, path.startsWith("/") ? path : "/" + path,
                StringUtils.join(queryParameters, "&"), null);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    //
    return uri;
}

From source file:net.modelbased.proasense.storage.registry.RegisterSensorSSN.java

public static String postSensor(Sensor sensor) throws RequestErrorException {
    String content = JsonPrinter.sensorToJson(sensor);
    URI target;/*from  w  w w  .j  a v  a  2  s. c om*/
    try {
        target = new URI(sensor.getUri().toString() + SENSOR_PATH);
    } catch (URISyntaxException e1) {
        e1.printStackTrace();
        throw new RequestErrorException(e1.getMessage());
    }
    HttpClient client = new DefaultHttpClient();
    HttpPost request = new HttpPost(target);
    request.setHeader("Content-type", "application/json");
    String response = null;
    try {
        StringEntity seContent = new StringEntity(content);
        seContent.setContentType("text/json");
        request.setEntity(seContent);
        response = resolveResponse(client.execute(request));
    } catch (Exception e) {
        throw new RequestErrorException(e.getMessage());
    }
    return response;
}

From source file:eu.planets_project.tb.utils.XCDLParser.java

public static URI makePropertyUri(String id, String name) {
    try {//from ww w.  j a va 2s. co  m
        return new URI(TecRegMockup.URI_XCDL_PROP_ROOT + id + "/" + name);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:es.bsc.demiurge.core.utils.HttpUtils.java

/**
 * Builds a URI with format: scheme:://host:port/path .
 *
 * @param scheme Scheme of the URI (HTTP, HTTPS, etc.).
 * @param host Host of the URI.//  ww w. j a va 2  s .com
 * @param path Path of the URI.
 * @return The URI built.
 */
public static URI buildURI(String scheme, String host, int port, String path) {
    URI uri = null;
    try {
        uri = new URIBuilder().setScheme(scheme).setHost(host).setPort(port).setPath(path).build();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return uri;
}

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   w ww .j  a v  a2s . c om
    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:com.tweetlanes.android.urlservice.ApiService.java

public static HttpResponse postRequest(String url, String debugName) {
    HttpClient client = new DefaultHttpClient();
    HttpPost request = new HttpPost();
    HttpResponse response = null;//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:Main.java

private static Intent intentFromString(StringBuilder s) {
    CharSequence prefix = extract(s);
    Intent intent = null;//ww  w .ja v  a  2  s .  c om
    if (prefix != null) {
        try {
            String action = toString(extract(s));
            String uri = toString(extract(s));
            intent = Intent.parseUri(uri, Intent.URI_INTENT_SCHEME);
            intent.setAction(action);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    return intent;
}

From source file:org.linagora.linshare.webservice.utils.DocumentStreamReponseBuilder.java

private static String getContentDispositionHeader(String fileName) {
    String encodeFileName = null;
    try {//  www .j  a va 2  s  .  c  o  m
        URI uri = new URI(null, null, fileName, null);
        encodeFileName = uri.toASCIIString();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    StringBuilder sb = new StringBuilder();
    sb.append("attachment; ");

    // Adding filename using the old way for old browser compatibility
    sb.append("filename=\"" + fileName + "\"; ");

    // Adding UTF-8 encoded filename. If the browser do not support this
    // parameter, it will use the old way.
    if (encodeFileName != null) {
        sb.append("filename*= UTF-8''" + encodeFileName);
    }
    return sb.toString();
}

From source file:org.mule.module.pubsubhubbub.Utils.java

public static URI getMandatoryUrlParameter(final String name, final Map<String, List<String>> parameters) {
    final String value = getMandatoryStringParameter(name, parameters);

    try {/*from w w w  .j  a  v  a 2 s.  c o m*/
        final URI uri = new URI(value);

        if (StringUtils.isNotEmpty(uri.getFragment())) {
            throw new IllegalArgumentException("Fragment found in URL parameter: " + name);
        }

        return uri;
    } catch (final URISyntaxException use) {
        use.printStackTrace();
        throw new IllegalArgumentException("Invalid URL parameter: " + name, use);
    }
}