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:org.iipg.hurricane.jmx.client.JMXRequestHandler.java

/**
 * Constructor//from  www.ja  va  2s .  c om
 *
 * @param pServerUrl URL to remote agent
 * @param pTargetConfig optional default target configuration for proxy requests
 */
public JMXRequestHandler(String pServerUrl, JMXTargetConfig pTargetConfig) {
    try {
        serverUrl = new URI(pServerUrl);
        defaultTargetConfig = pTargetConfig;
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Invalid URL " + pServerUrl, e);
    }
}

From source file:org.jolokia.client.request.J4pRequestHandler.java

/**
 * Constructor//  w  ww  .  ja  va2  s  . com
 *
 * @param pJ4pServerUrl URL to remote agent
 * @param pTargetConfig optional default target configuration for proxy requests
 */
public J4pRequestHandler(String pJ4pServerUrl, J4pTargetConfig pTargetConfig) {
    try {
        j4pServerUrl = new URI(pJ4pServerUrl);
        defaultTargetConfig = pTargetConfig;
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Invalid URL " + pJ4pServerUrl, e);
    }
}

From source file:org.neo4j.server.rest.DisableWADLDocIT.java

@Test
public void should404OnAnyUriEndinginWADL() throws Exception {
    URI nodeUri = new URI("http://localhost:7474/db/data/application.wadl");

    HttpClient httpclient = new DefaultHttpClient();
    try {//  w  w  w .  j  a  v a2 s  .c  om
        HttpGet httpget = new HttpGet(nodeUri);

        httpget.setHeader("Accept", "*/*");
        HttpResponse response = httpclient.execute(httpget);

        assertEquals(404, response.getStatusLine().getStatusCode());

    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.gameminers.mav.firstrun.GoogleScreen.java

@Override
public void onKeyDown(int k, char c, long nanos) {
    if (k == Keyboard.KEY_RETURN) {
        String str = tf.getText();
        if (Strings.similarity(str.toLowerCase(), "yes") > 0.6) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URI("https://mav.gameminers.com/using-google.html"));
                    try {
                        Mav.ttsInterface.say(
                                "Okay, then I'll need you to get a Google API key. I've opened a page on my website explaining how to do this.");
                    } catch (SynthesisException e) {
                        // TODO
                        e.printStackTrace();
                    }/*from   w w w .  jav a2 s  . com*/
                    return;
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
            }
            try {
                Mav.ttsInterface.say(
                        "Okay, then I'll need you to get a Google API key. I can't open your browser, so you'll need to go to my site yourself. Near the bottom is a link titled 'Using Google'. That page explains how to get an API key.");
            } catch (SynthesisException e) {
                // TODO
                e.printStackTrace();
            }
        } else if (Strings.similarity(str.toLowerCase(), "no") > 0.6) {
            try {
                Mav.ttsInterface.say(
                        "Okay. Next, I need to learn the sound of your voice. Read the sentences I show out loud.");
            } catch (SynthesisException e) {
                // TODO
                e.printStackTrace();
            }
            Mav.currentScreen = new TeachSphinxScreen();
        } else if (StringUtils.isBlank(str)) {
            try {
                Mav.ttsInterface.say("Please enter Yes or No.");
            } catch (SynthesisException e) {
                // TODO
                e.printStackTrace();
            }
        } else {
            try {
                Mav.ttsInterface.say("Sorry, I don't understand.");
            } catch (SynthesisException e) {
                // TODO
                e.printStackTrace();
            }
        }
        tf.setText("");
    }
}

From source file:client.ClientBase.java

/**
 * Creates a URIBuilder with the base path and a relative path resolved.
 *
 * @param relativePath the relative path
 * @return a new {@link URIBuilder}/*from   w w w  .  j ava 2 s.c  o  m*/
 */
protected URIBuilder uriBuilder(final String relativePath) {
    final URI tokenUri;
    try {
        tokenUri = new URI(_baseUrl).resolve(relativePath);
    } catch (final URISyntaxException e) {
        LOGGER.error(String.format("Unable to parse baseURL; baseURL=%s", _baseUrl), e);
        throw Throwables.propagate(e);
    }
    return new URIBuilder(tokenUri);
}

From source file:com.amazonaws.eclipse.core.HttpClientFactory.java

private static void configureProxy(DefaultHttpClient client, String url) {
    AwsToolkitCore plugin = AwsToolkitCore.getDefault();
    if (plugin != null) {
        IProxyService proxyService = AwsToolkitCore.getDefault().getProxyService();

        if (proxyService.isProxiesEnabled()) {
            try {
                IProxyData[] proxyData;//from w  w  w.  j  av  a  2 s .  co  m
                proxyData = proxyService.select(new URI(url));
                if (proxyData.length > 0) {

                    IProxyData data = proxyData[0];
                    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
                            new HttpHost(data.getHost(), data.getPort()));

                    if (data.isRequiresAuthentication()) {
                        client.getCredentialsProvider().setCredentials(
                                new AuthScope(data.getHost(), data.getPort()),
                                new NTCredentials(data.getUserId(), data.getPassword(), null, null));
                    }
                }
            } catch (URISyntaxException e) {
                plugin.getLog().log(new Status(Status.ERROR, AwsToolkitCore.PLUGIN_ID, e.getMessage(), e));
            }
        }
    }
}

From source file:net.seedboxer.camel.component.file.remote.ftp2.Ftp2Component.java

@Override
protected GenericFileEndpoint<FTPFile> buildFileEndpoint(String uri, String remaining,
        Map<String, Object> parameters) throws Exception {
    String baseUri = getBaseUri(uri);

    // lets make sure we create a new configuration as each endpoint can customize its own version
    // must pass on baseUri to the configuration (see above)
    Ftp2Configuration config = new Ftp2Configuration(new URI(baseUri));
    setProperties(config, parameters);/*from   w  w  w . ja  v a 2s. c  o m*/

    Ftp2Endpoint<FTPFile> answer = new Ftp2Endpoint<FTPFile>(uri, this, config);
    extractAndSetFtpClientConfigParameters(parameters, answer);
    extractAndSetFtpClientParameters(parameters, answer);

    return answer;
}

From source file:net.haltcondition.anode.HttpWorker.java

public void run() {
    Log.d(TAG, "Running");

    HttpClient client = new WebtoolsHttpClient(context);
    try {//  w  ww  .  j  av a  2  s  .c  o  m
        Log.d(TAG, "performing get " + url);
        sendUpdate("Fetching page ...");

        URI u = new URI(url);
        HttpGet method = new HttpGet(u);

        if (account != null) {
            Log.d(TAG, "Using account " + account.getUsername());
            /*
             * This sucks, but I've wasted half a day trying to get HttpClient basic auth to work.
             * Android appears to ship with alpha version of 4.0 that doesn't match the docs.
             */
            String auth = Base64.encodeBytes((account.getUsername() + ":" + account.getPassword()).getBytes())
                    .toString();
            method.addHeader("Authorization", "Basic " + auth);
        }

        HttpResponse response = client.execute(method);
        if (response == null) {
            Log.e(TAG, "got a null response");
            sendError("Error Retrieving Service Data");

        } else if (response.getStatusLine().getStatusCode() == 200) {
            Log.d(TAG, "Status: " + response.getStatusLine());

            sendUpdate("Parsing XML ...");
            sendResult(resultHandler.parse(response.getEntity().getContent()));

        } else {
            String err = "Failed to get data: " + response.getStatusLine().getStatusCode() + " / "
                    + response.getStatusLine().getReasonPhrase();
            Log.e(TAG, err);
            sendError(err);
        }

    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        sendError("IO Error Retrieving Data");
    } catch (URISyntaxException e) {
        Log.e(TAG, "Error parsing URL" + e.getMessage());
        sendError("URI Error Retrieving Data");

    } finally {
        client.getConnectionManager().shutdown();
    }

}

From source file:com.thoughtworks.go.server.security.DenyGoCDAccessForArtifactsFilter.java

private boolean requestingAnArtifact(HttpServletRequest request) {
    String requestURI;/*from   w  w w  .  ja  va  2s. c om*/
    try {
        requestURI = new URI(request.getRequestURI()).normalize().toString();
    } catch (URISyntaxException e) {
        requestURI = request.getRequestURI();
    }
    return requestURI.startsWith("/go/files");
}

From source file:io.crate.rest.AdminUIIntegrationTest.java

private URI adminURI() throws URISyntaxException {
    return new URI(String.format(Locale.ENGLISH, "http://%s:%d/", address.getHostName(), address.getPort()));
}