Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

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

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:org.robertburrelldonkin.template4couchdb.rest.HttpClientRestClientTest.java

@Test
public void testGetUrl() throws Exception {
    subject.get(URL, mapper);/*  w w w.jav  a2s  . com*/
    ArgumentCaptor<HttpGet> argument = ArgumentCaptor.forClass(HttpGet.class);
    verify(client).execute(argument.capture(), eq(handler));
    URI uri = argument.getValue().getURI();
    assertThat(PORT, is(uri.getPort()));
    assertThat(HOST, is(uri.getHost()));
    assertThat(PROTOCOL, is(uri.getScheme()));
    assertThat(PATH, is(uri.getPath()));
}

From source file:org.robertburrelldonkin.template4couchdb.rest.HttpClientRestClientTest.java

@Test
public void testPostUrl() throws Exception {
    ArgumentCaptor<HttpPost> argument = ArgumentCaptor.forClass(HttpPost.class);
    this.subject.post(URL, documentMarshaller, document, responseUnmarshaller);
    verify(client).execute(argument.capture(), eq(handler));
    URI uri = argument.getValue().getURI();
    assertThat(PORT, is(uri.getPort()));
    assertThat(HOST, is(uri.getHost()));
    assertThat(PROTOCOL, is(uri.getScheme()));
    assertThat(PATH, is(uri.getPath()));
}

From source file:org.coffeebreaks.validators.w3c.W3cMarkupValidator.java

private ValidationResult validateW3cMarkup(String type, String value, boolean get) throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpRequestBase method;//www .  j a  v a  2 s. co m
    if (get) {
        List<NameValuePair> qParams = new ArrayList<NameValuePair>();
        qParams.add(new BasicNameValuePair("output", "soap12"));
        qParams.add(new BasicNameValuePair(type, value));

        try {
            URI uri = new URI(baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "check");
            URI uri2 = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(),
                    URLEncodedUtils.format(qParams, "UTF-8"), null);
            method = new HttpGet(uri2);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("invalid uri. Check your baseUrl " + baseUrl, e);
        }
    } else {
        HttpPost httpPost = new HttpPost(baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "check");
        List<NameValuePair> formParams = new ArrayList<NameValuePair>();
        formParams.add(new BasicNameValuePair("output", "soap12"));
        formParams.add(new BasicNameValuePair(type, value));
        UrlEncodedFormEntity requestEntity = new UrlEncodedFormEntity(formParams, "UTF-8");
        httpPost.setEntity(requestEntity);
        method = httpPost;
    }
    HttpResponse response = httpclient.execute(method);
    HttpEntity responseEntity = response.getEntity();
    int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode >= HttpStatus.SC_BAD_REQUEST) {
        throw new IllegalStateException(
                "Unexpected HTTP status code: " + statusCode + ". Implementation error ?");
    }
    if (responseEntity == null) {
        throw new IllegalStateException(
                "No entity but HTTP status code: " + statusCode + ". Server side error ?");
    }

    InputStream entityContentInputStream = responseEntity.getContent();
    StringWriter output = new StringWriter();
    IOUtils.copy(entityContentInputStream, output, "UTF-8");
    final String soap = output.toString();

    // we can use the response headers instead of the soap
    // final W3cSoapValidatorSoapOutput soapObject = parseSoapObject(soap);

    String headerValue = getHeaderValue(response, "X-W3C-Validator-Status");
    final boolean indeterminate = headerValue.equals("Abort");
    final int errorCount = Integer.parseInt(getHeaderValue(response, "X-W3C-Validator-Errors"));
    final int warningCount = Integer.parseInt(getHeaderValue(response, "X-W3C-Validator-Warnings"));

    return new ValidationResult() {
        public boolean isResultIndeterminate() {
            return indeterminate;
        }

        public int getErrorCount() {
            return errorCount;
        }

        public int getWarningCount() {
            return warningCount;
        }

        public String getResponseContent() {
            return soap;
        }
    };
}

From source file:tools.devnull.boteco.client.rest.impl.DefaultRestConfiguration.java

@Override
public RestConfiguration withAuthentication(String user, String password) {
    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    CredentialsProvider provider = new BasicCredentialsProvider();

    URI uri = request.getURI();
    authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth);
    provider.setCredentials(new AuthScope(uri.getHost(), AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(user, password));

    this.context.setCredentialsProvider(provider);
    this.context.setAuthCache(authCache);

    return this;
}

From source file:com.subgraph.vega.internal.http.requests.HttpRequestBuilder.java

@Override
public synchronized void setFromRequestLine(RequestLine requestLine) throws URISyntaxException {
    method = requestLine.getMethod();//  ww w.jav  a  2 s .co  m

    final URI requestUri = new URI(requestLine.getUri());
    scheme = requestUri.getScheme();
    if (scheme == null) {
        scheme = "http";
    }

    host = requestUri.getHost();
    hostPort = requestUri.getPort();
    if (hostPort == -1) {
        if (scheme.equals("https")) {
            hostPort = 443;
        } else {
            hostPort = 80;
        }
    }

    setPathFromUri(requestUri);
    setProtocolVersion(requestLine.getProtocolVersion());
}

From source file:io.kahu.hawaii.util.call.sql.DbRequestBuilderRepository.java

private void walkDirectory(final String directory) {
    try {/*w  w w. ja  v a  2s .c  o m*/
        URI uri = this.getClass().getResource(directory).toURI();
        Path myPath;
        if (uri.getScheme().equals("jar")) {
            FileSystem fileSystem = null;
            try {
                fileSystem = FileSystems.getFileSystem(uri);
            } catch (Exception e) {
                // ignore
            }
            if (fileSystem == null) {
                fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
            }
            myPath = fileSystem.getPath(directory);
        } else {
            myPath = Paths.get(uri);
        }
        Stream<Path> walk = Files.walk(myPath, 1);
        walk.forEach((path) -> {
            String name = path.getFileName().toString();
            if (name.endsWith(".sql")) {
                DbRequestPrototype p = createPrototype(directory, name);
                if (p != null) {
                    try {
                        add(new DbRequestBuilder(p));
                    } catch (ServerException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.gistlabs.mechanize.util.apache.URIBuilder.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}

From source file:org.sonatype.nexus.client.rest.jersey.NexusClientFactoryImpl.java

/**
 * NXCM-4547 JERSEY-1293 Enforce proxy setting on httpclient
 * <p/>/*w w w.  jav  a  2s.c  o  m*/
 * Revisit for jersey 1.13.
 */
private void enforceProxyUri(final ApacheHttpClient4Config config, final ApacheHttpClient4 client) {
    final Object proxyProperty = config.getProperties().get(PROPERTY_PROXY_URI);
    if (proxyProperty != null) {
        final URI uri = getProxyUri(proxyProperty);
        final HttpHost proxy = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
        client.getClientHandler().getHttpClient().getParams().setParameter(DEFAULT_PROXY, proxy);
    }
}

From source file:eu.stratosphere.test.util.AbstractTestBase.java

public File asFile(String path) {
    try {// ww w . j a va  2  s  . c  o  m
        URI uri = new URI(path);
        if (uri.getScheme().equals("file")) {
            return new File(uri.getPath());
        } else {
            throw new IllegalArgumentException("This path does not denote a local file.");
        }
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("This path does not describe a valid local file URI.");
    }
}

From source file:eu.bittrade.libs.steemj.communication.HttpClient.java

@Override
public JsonRPCResponse invokeAndReadResponse(JsonRPCRequest requestObject, URI endpointUri,
        boolean sslVerificationDisabled) throws SteemCommunicationException {
    try {//w ww.  j  a  v  a 2s  .c  o m
        NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
        // Disable SSL verification if needed
        if (sslVerificationDisabled && endpointUri.getScheme().equals("https")) {
            builder.doNotValidateCertificate();
        }

        String requestPayload = requestObject.toJson();
        HttpRequest httpRequest = builder.build().createRequestFactory(new HttpClientRequestInitializer())
                .buildPostRequest(new GenericUrl(endpointUri),
                        ByteArrayContent.fromString("application/json", requestPayload));

        LOGGER.debug("Sending {}.", requestPayload);

        HttpResponse httpResponse = httpRequest.execute();

        int status = httpResponse.getStatusCode();
        String responsePayload = httpResponse.parseAsString();

        if (status >= 200 && status < 300 && responsePayload != null) {
            return new JsonRPCResponse(CommunicationHandler.getObjectMapper().readTree(responsePayload));
        } else {
            throw new ClientProtocolException("Unexpected response status: " + status);
        }

    } catch (GeneralSecurityException | IOException e) {
        throw new SteemCommunicationException("A problem occured while processing the request.", e);
    }
}