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:com.microsoft.tfs.client.common.util.TeamContextCache.java

private String getCacheKey(final TFSTeamProjectCollection connection) {
    /*//  w ww  .j av  a 2 s .  c  o m
     * So TeamContextCache is useful offline, we must use only attributes
     * from the connection that can be read offline. The connection's
     * instance ID plus the authorized user name would combine to make an
     * ideal key here, but those require a round-trip to the server. The URI
     * will do instead.
     */

    final URI uri = connection.getBaseURI();

    // Convert the URI parts to something more pref-key-like
    return String.format("%s/%s/%d/%s", uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath()) //$NON-NLS-1$
            .toLowerCase();
}

From source file:com.netty.file.HttpUploadServerHandler.java

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    if (msg instanceof HttpRequest) {
        HttpRequest request = this.request = (HttpRequest) msg;
        URI uri = new URI(request.uri());

        if (!uri.getPath().startsWith("/form")) {
            // Write Menu
            writeMenu(ctx);//from   ww w.  j  ava2s.co  m
            return;
        }
        responseContent.setLength(0);
        responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n");
        responseContent.append("===================================\r\n");

        responseContent.append("VERSION: " + request.protocolVersion().text() + "\r\n");

        responseContent.append("REQUEST_URI: " + request.uri() + "\r\n\r\n");
        responseContent.append("\r\n\r\n");

        // new getMethod
        for (Entry<String, String> entry : request.headers()) {
            responseContent.append("HEADER: " + entry.getKey() + '=' + entry.getValue() + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        System.out.println("Helllllllllllllllllloooooooooooooo");

        // new getMethod
        Set<Cookie> cookies;
        String value = request.headers().get(HttpHeaderNames.COOKIE);
        if (value == null) {
            cookies = Collections.emptySet();
        } else {
            cookies = ServerCookieDecoder.STRICT.decode(value);
        }
        for (Cookie cookie : cookies) {
            responseContent.append("COOKIE: " + cookie + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        QueryStringDecoder decoderQuery = new QueryStringDecoder(request.uri());
        Map<String, List<String>> uriAttributes = decoderQuery.parameters();
        for (Entry<String, List<String>> attr : uriAttributes.entrySet()) {
            for (String attrVal : attr.getValue()) {
                responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\r\n");
            }
        }
        responseContent.append("\r\n\r\n");

        // if GET Method: should not try to create a HttpPostRequestDecoder
        if (request.method().equals(HttpMethod.GET)) {
            // GET Method: should not try to create a HttpPostRequestDecoder
            // So stop here
            responseContent.append("\r\n\r\nEND OF GET CONTENT\r\n");
            // Not now: LastHttpContent will be sent writeResponse(ctx.channel());
            return;
        }
        try {
            decoder = new HttpPostRequestDecoder(factory, request);
        } catch (ErrorDataDecoderException e1) {
            e1.printStackTrace();
            responseContent.append(e1.getMessage());
            writeResponse(ctx.channel());
            ctx.channel().close();
            return;
        }

        readingChunks = HttpUtil.isTransferEncodingChunked(request);
        responseContent.append("Is Chunked: " + readingChunks + "\r\n");
        responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
        if (readingChunks) {
            // Chunk version
            responseContent.append("Chunks: ");
            readingChunks = true;
        }
    }

    // check if the decoder was constructed before
    // if not it handles the form get
    if (decoder != null) {
        if (msg instanceof HttpContent) {
            // New chunk is received
            HttpContent chunk = (HttpContent) msg;
            try {
                decoder.offer(chunk);
            } catch (ErrorDataDecoderException e1) {
                e1.printStackTrace();
                responseContent.append(e1.getMessage());
                writeResponse(ctx.channel());
                ctx.channel().close();
                return;
            }
            responseContent.append('o');
            // example of reading chunk by chunk (minimize memory usage due to
            // Factory)
            readHttpDataChunkByChunk();
            // example of reading only if at the end
            if (chunk instanceof LastHttpContent) {
                writeResponse(ctx.channel());
                readingChunks = false;

                reset();
            }
        }
    } else {
        writeResponse(ctx.channel());
    }
}

From source file:com.sra.biotech.submittool.persistence.service.SubmissionServiceImpl.java

public Link assignRun(URI submissionUri, Run run) {
    ObjectMapper objectMapper = restTemplateService.getObjectMapperWithHalModule();
    String runsUri = RestClientConfiguration.BASE_URL + "/" + "runs";
    ObjectNode jsonNodeRun = (ObjectNode) objectMapper.valueToTree(run);
    jsonNodeRun.put("experiment", submissionUri.getPath());

    URI runUri = restTemplate.postForLocation(runsUri, jsonNodeRun);
    ResponseEntity<Resource<Run>> runResponseEntity = restTemplate.exchange(runUri, HttpMethod.GET, null,
            new ParameterizedTypeReference<Resource<Run>>() {
            });//from w ww.  java2 s.  co m

    Resource<Run> runResource = runResponseEntity.getBody();
    Link experimentLinkThroughRun = runResource.getLink("experiment");
    System.out.println("Experiment Link through Run = " + experimentLinkThroughRun);
    return experimentLinkThroughRun;
}

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

@Test
public void testLoadSystemProperties() throws Exception {
    Set<SystemProperty> systemProperties = Sets.newHashSet(
            new SystemProperty("user.sys", "props.host", "localhost"),
            new SystemProperty("user.sys", "props.port", "22"),
            new SystemProperty("user.sys", "props.alla", "balla"));
    URI systemPropertyURI = getClass().getResource("/properties/system_properties.prop.sl").toURI();
    SlangSource source = SlangSource.fromFile(systemPropertyURI);
    when(slang.loadSystemProperties(eq(source))).thenReturn(systemProperties);

    compilerHelper.loadSystemProperties(Collections.singletonList(systemPropertyURI.getPath()));

    verify(slang).loadSystemProperties(eq(source));
}

From source file:com.adaptris.core.http.jetty.BasicJettyConsumer.java

protected String ensureIsPath(String s) throws CoreException {
    String result = s;/*from w w w  .j  a  v  a  2 s . c  o  m*/
    try {
        URI uri = new URI(s);
        result = uri.getPath();
    } catch (URISyntaxException e) {
        throw new CoreException(e);
    }
    return result;
}

From source file:se.vgregion.urlservice.services.DefaultUrlServiceService.java

@Override
public UrlWithHash expandPath(URI url) {
    String domain = url.getHost();
    if (url.getPort() > 0) {
        domain += ":" + url.getPort();
    }/*from   w w  w  . ja va2s. co m*/

    return expandPath(url.getPath());
}

From source file:com.mirth.connect.connectors.ws.WebServiceConnectorService.java

private WsdlInterface getWsdlInterface(URI wsdlUrl, String username, String password) throws Exception {
    /* add the username:password to the URL if using authentication */
    if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
        String hostWithCredentials = username + ":" + password + "@" + wsdlUrl.getHost();
        wsdlUrl = new URI(wsdlUrl.getScheme(), hostWithCredentials, wsdlUrl.getPath(), wsdlUrl.getQuery(),
                wsdlUrl.getFragment());/*from   w  w w.  j a v a2  s. c  o  m*/
    }

    // 
    SoapUI.setSoapUICore(new EmbeddedSoapUICore());
    WsdlProject wsdlProject = new WsdlProjectFactory().createNew();
    WsdlLoader wsdlLoader = new UrlWsdlLoader(wsdlUrl.toURL().toString());

    try {
        Future<WsdlInterface> future = importWsdlInterface(wsdlProject, wsdlUrl, wsdlLoader);
        return future.get(30, TimeUnit.SECONDS);
    } catch (Exception e) {
        wsdlLoader.abort();
        throw e;
    }
}

From source file:com.sap.core.odata.fit.basic.issues.TestIssue105.java

@Test
public void checkContextForDifferentHostNamesRequests()
        throws ClientProtocolException, IOException, ODataException, URISyntaxException {
    URI uri1 = URI.create(getEndpoint().toString() + "$metadata");

    HttpGet get1 = new HttpGet(uri1);
    HttpResponse response1 = getHttpClient().execute(get1);
    assertNotNull(response1);//from  ww  w .  ja v  a  2  s .co m

    URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
    assertEquals(uri1.getHost(), serviceRoot1.getHost());

    get1.reset();

    URI uri2 = new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(),
            uri1.getQuery(), uri1.getFragment());

    HttpGet get2 = new HttpGet(uri2);
    HttpResponse response2 = getHttpClient().execute(get2);
    assertNotNull(response2);

    URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
    assertEquals(uri2.getHost(), serviceRoot2.getHost());
}

From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java

@Override
public Path getPath(URI uri) {
    checkURI(uri);
    return getFileSystem(uri).getPath(uri.getPath());
}

From source file:edu.ur.file.db.service.DefaultFileServerServiceTest.java

/**
 * Test creating a folder.//from w w w.  j ava  2  s .  c  om
 * 
 * - Make sure a folder location can be created.
 * @throws LocationAlreadyExistsException 
 * 
 */
@Test
public void createFolderTest() throws LocationAlreadyExistsException {
    // Start the transaction this is for lazy loading
    TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus ts = tm.getTransaction(td);

    DefaultFileServer fs = dfss.createFileServer("service_file_server");

    DefaultFileDatabase fileDatabase = fs.createFileDatabase("nates file server", "file_server_1",
            properties.getProperty("defaultFileServerService.server_path"), "description");

    TreeFolderInfo treeFolderInfo = fileDatabase.createRootFolder("Nates Folder", "folder_1");
    assert fileDatabase
            .setCurrentFileStore(treeFolderInfo.getName()) : "Should be able to set current file store";

    dfss.saveFileServer(fs);
    //commit the transaction this will assigning an id to the 
    //file database and folder information
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    FolderInfo info = dfss.createFolder(fileDatabase, "a_folder_name");
    Long id = info.getId();

    URI uri = info.getUri();

    File f = new File(uri.getPath());

    assert f.exists() : "File " + f.getAbsolutePath() + " does not exist!";
    tm.commit(ts);

    //make sure the folder exists.
    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    info = dfss.getFolder(id, false);

    assert info != null : "folder info fo id " + id + " could not be found";

    dfss.deleteFolder(info);
    tm.commit(ts);

    //make sure the folder has been deleted.
    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);
    info = dfss.getFolder(id, false);
    assert info == null : "folder info fo id " + id + " was found and SHOULD NOT be";
    tm.commit(ts);

    dfss.deleteFileServer(fs.getName());

}