Example usage for java.net URI getPath

List of usage examples for java.net URI getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Returns the decoded path component of this URI.

Usage

From source file:org.herrlado.engeo.Utils.java

/**
 * Update cookies from response.//from   w  w  w  .j a v  a 2s.  co  m
 * 
 * @param cookies
 *            old {@link Cookie} list
 * @param headers
 *            {@link Header}s from {@link HttpResponse}
 * @param url
 *            requested URL
 * @throws URISyntaxException
 *             malformed URI
 * @throws MalformedCookieException
 *             malformed {@link Cookie}
 */
@Deprecated
public static void updateCookies(final ArrayList<Cookie> cookies, final Header[] headers, final String url)
        throws URISyntaxException, MalformedCookieException {
    final URI uri = new URI(url);
    int port = uri.getPort();
    if (port < 0) {
        if (url.startsWith("https")) {
            port = PORT_HTTPS;
        } else {
            port = PORT_HTTP;
        }
    }
    final CookieOrigin origin = new CookieOrigin(uri.getHost(), port, uri.getPath(), false);
    final CookieSpecBase cookieSpecBase = new BrowserCompatSpec();
    String name;
    String value;
    for (final Header header : headers) {
        for (final Cookie cookie : cookieSpecBase.parse(header, origin)) {
            // THE cookie
            name = cookie.getName();
            value = cookie.getValue();
            if (value == null || value.equals("")) {
                continue;
            }
            for (final Cookie c : cookies) {
                if (name.equals(c.getName())) {
                    cookies.remove(c);
                    cookies.add(cookie);
                    name = null;
                    break;
                }
            }
            if (name != null) {
                cookies.add(cookie);
            }
        }
    }
}

From source file:com.smartitengineering.util.simple.reflection.DefaultClassScannerImpl.java

private void scanForVisit(URI u, String filePackageName, ClassVisitor classVisitor) {
    String scheme = u.getScheme();
    if (scheme.equals("file")) {
        File f = new File(u.getPath());
        if (f.isDirectory()) {
            scanDir(f, false, classVisitor);
        } else {//from  w ww  .  ja v  a2s.  co  m
        }
    } else if (scheme.equals("jar") || scheme.equals("zip")) {
        URI jarUri = URI.create(u.getRawSchemeSpecificPart());
        String jarFile = jarUri.getPath();
        jarFile = jarFile.substring(0, jarFile.indexOf('!'));
        scanJar(new File(jarFile), filePackageName, classVisitor);
    } else {
    }
}

From source file:com.adito.vfs.webdav.methods.COPY.java

/**
 * <p>//from  w w w . ja v a  2 s  .c  o m
 * Process the <code>COPY</code> method.
 * </p>
 * 
 * @throws IOException
 */
public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException {

    String handle = VFSLockManager.getNewHandle();
    VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), false, true, handle);

    String action = (String) transaction.getRequest().getMethod();

    VFSResource dest = null;

    try {

        URI target = transaction.getDestination();

        if (target == null)
            throw new DAVException(412, "No destination");
        if (log.isDebugEnabled())
            log.debug("Target " + target.getPath());

        try {
            DAVProcessor processor = DAVServlet.getDAVProcessor(transaction.getRequest());
            dest = processor.getRepository().getResource(resource.getLaunchSession(), target.getPath(),
                    transaction.getCredentials()/*, transaction*/);
            VFSLockManager.getInstance().lock(dest, transaction.getSessionInfo(), true, false, handle);

        } catch (Exception ex) {
            log.error("Failed to get resource. ", ex);
            transaction.setStatus(500);
            return;
        }

        int depth = transaction.getDepth();
        boolean recursive = false;
        if (depth == 0) {
            recursive = false;
        } else if (depth == DAVTransaction.INFINITY) {
            recursive = true;
        } else {
            throw new DAVException(412, "Invalid Depth specified");
        }
        try {
            resource.copy(dest, transaction.getOverwrite(), recursive);
            transaction.setStatus(204);
        } catch (DAVMultiStatus multistatus) {
            multistatus.write(transaction);
        }
        if (action.equals("COPY")) {
            resource.getMount().resourceCopy(resource, dest, transaction, null);
        }
    } catch (Exception e) {
        if (action.equals("COPY")) {
            resource.getMount().resourceCopy(resource, dest, transaction, e);
        }
        IOException ioe = new IOException(e.getMessage());
        ioe.initCause(e);
        throw ioe;
    } finally {
        VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle);
    }

}

From source file:io.seldon.external.ExternalPluginServer.java

@Override
public JsonNode execute(JsonNode payload, OptionsHolder options) {
    long timeNow = System.currentTimeMillis();
    URI uri = URI.create(options.getStringOption(URL_PROPERTY_NAME));
    try {/* ww  w  . java 2  s.co  m*/
        URIBuilder builder = new URIBuilder().setScheme("http").setHost(uri.getHost()).setPort(uri.getPort())
                .setPath(uri.getPath()).setParameter("json", payload.toString());

        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new APIException(APIException.GENERIC_ERROR);
    }
    HttpContext context = HttpClientContext.create();
    HttpGet httpGet = new HttpGet(uri);
    try {
        if (logger.isDebugEnabled())
            logger.debug("Requesting " + httpGet.getURI().toString());
        CloseableHttpResponse resp = httpClient.execute(httpGet, context);
        if (resp.getStatusLine().getStatusCode() == 200) {

            JsonFactory factory = mapper.getJsonFactory();
            JsonParser parser = factory.createJsonParser(resp.getEntity().getContent());
            JsonNode actualObj = mapper.readTree(parser);
            if (logger.isDebugEnabled())
                logger.debug(
                        "External prediction server took " + (System.currentTimeMillis() - timeNow) + "ms");
            return actualObj;
        } else {
            logger.error(
                    "Couldn't retrieve prediction from external prediction server -- bad http return code: "
                            + resp.getStatusLine().getStatusCode());
            throw new APIException(APIException.GENERIC_ERROR);
        }
    } catch (IOException e) {
        logger.error("Couldn't retrieve prediction from external prediction server - ", e);
        throw new APIException(APIException.GENERIC_ERROR);
    }

}

From source file:com.ge.predix.controller.test.PolicyManagementControllerIT.java

private String upsertPolicySet(final PolicySet myPolicySet) throws JsonProcessingException, Exception {

    String policySetContent = this.objectWriter.writeValueAsString(myPolicySet);
    String policySetName = myPolicySet.getName();
    MockMvcContext ctxt = this.testUtils.createWACWithCustomPUTRequestBuilder(this.wac,
            this.testZone.getSubdomain(), VERSION + "policy-set/" + myPolicySet.getName());
    URI policySetUri = UriTemplateUtils.expand(POLICY_SET_URL, "policySetId:" + policySetName);
    String policySetPath = policySetUri.getPath();

    ctxt.getMockMvc()/*from   w  ww .ja v  a2s  . c o m*/
            .perform(ctxt.getBuilder().content(policySetContent).contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isCreated()).andExpect(header().string("Location", policySetPath));

    return policySetName;
}

From source file:org.apache.heron.uploader.http.HttpUploaderTest.java

@Test(expected = IllegalArgumentException.class)
public void testInitializeWhenTopologyPackageFileIsNull() throws URISyntaxException {
    final URI uri = new URIBuilder().setScheme("http").setHost(httpHost.getHostName())
            .setPort(httpHost.getPort()).setPath(EXPECTED_URI).build();

    testInitialize(null, uri.getPath());
}

From source file:io.cloudslang.lang.cli.utils.CompilerHelperTest.java

@Test
public void testLoadInputsFromEmptyFile() throws Exception {
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("Inputs file");

    URI inputsFromFile = getClass().getResource("/inputs/empty_inputs.yaml").toURI();
    compilerHelper.loadInputsFromFile(Collections.singletonList(inputsFromFile.getPath()));

}

From source file:org.apache.heron.uploader.http.HttpUploaderTest.java

@Test(expected = IllegalArgumentException.class)
public void testInitializeWhenTopologyPackageFileIsBlank() throws URISyntaxException {
    final URI uri = new URIBuilder().setScheme("http").setHost(httpHost.getHostName())
            .setPort(httpHost.getPort()).setPath(EXPECTED_URI).build();

    testInitialize("   ", uri.getPath());
}

From source file:net.hillsdon.reviki.wiki.renderer.creole.CreoleLinkContentsSplitter.java

/**
 * Splits links of the form target or text|target where target is
 * /*w ww. ja v a 2 s.c o  m*/
 * PageName wiki:PageName PageName#fragment wiki:PageName#fragment
 * A String representing an absolute URI scheme://valid/absolute/uri
 * Any character not in the `unreserved`, `punct`, `escaped`, or `other` categories (RFC 2396),
 * and not equal '/' or '@', is %-encoded. 
 * 
 * @param in The String to split
 * @return The split LinkParts
 */
LinkParts split(final String in) {
    String target = StringUtils.trimToEmpty(StringUtils.substringBefore(in, "|"));
    String text = StringUtils.trimToNull(StringUtils.substringAfter(in, "|"));
    if (target == null) {
        target = "";
    }
    if (text == null) {
        text = target;
    }
    // Link target can be PageName, wiki:PageName or a URL.
    URI uri = null;
    try {
        URL url = new URL(target);

        uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        if (uri.getPath() == null || !uri.isAbsolute()) {
            uri = null;
        }
    } catch (URISyntaxException e) {
        // uri remains null
    } catch (MalformedURLException e) {
        // uri remains null
    }

    if (uri != null) {
        return new LinkParts(text, uri);
    } else {
        // Split into wiki:pageName
        String[] parts = target.split(":", 2);
        String wiki = null;
        String pageName = target;
        if (parts.length == 2) {
            wiki = parts[0];
            pageName = parts[1];
        }

        // Split into pageName#fragment
        parts = pageName.split("#", 2);
        String fragment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            fragment = parts[1];
        }

        // Split into pageName/attachment
        parts = pageName.split("/", 2);
        String attachment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            attachment = parts[1];
        }

        return new LinkParts(text, wiki, pageName, fragment, attachment);
    }
}

From source file:com.vmware.identity.openidconnect.server.AuthenticationRequestProcessor.java

private void authenticateClient() throws ServerException {
    if (this.clientInfo.getCertSubjectDN() == null) {
        return; // no client authentication since no cert was specified at client registration time
    }/*from  ww w . ja v  a  2  s . co  m*/

    if (this.authnRequest.getClientAssertion() == null) {
        throw new ServerException(ErrorObject
                .invalidClient("client_assertion parameter is required since client has registered a cert"));
    }

    URI requestUri = this.httpRequest.getURI();
    if (requestUri.getPath().contains("/oidc/cac")) {
        // the client_assertion audience is expected to be the authorization endpoint (/oidc/authorize), but
        // login using TLS client cert (smart card / CAC) will arrive at the cac endpoint instead (/oidc/cac), so
        // we do this uri transformation to allow the client_assertion to pass validation
        requestUri = URIUtils.changePathComponent(requestUri,
                requestUri.getPath().replace("/oidc/cac", "/oidc/authorize"));
    }

    long clientAssertionLifetimeMs = (this.clientInfo.getAuthnRequestClientAssertionLifetimeMS() > 0)
            ? this.clientInfo.getAuthnRequestClientAssertionLifetimeMS()
            : CLIENT_ASSERTION_LIFETIME_MS;

    this.solutionUserAuthenticator.authenticateByClientAssertion(this.authnRequest.getClientAssertion(),
            clientAssertionLifetimeMs, requestUri, this.tenantInfo, this.clientInfo);
}