Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:org.kitodo.sruimport.SRUImport.java

private SearchResult search(String catalogId, Map<String, String> searchParameters, int numberOfRecords) {
    // TODO: check how the fields of hits from SRU interfaces can be configured via CQL (need only title and id!)
    loadOPACConfiguration(catalogId);/*w w w  . j av  a  2 s. c  o  m*/
    if (searchFieldMapping.keySet().containsAll(searchParameters.keySet())) {

        // Query parameters for HTTP request
        LinkedHashMap<String, String> queryParameters = new LinkedHashMap<>(parameters);

        // Search fields and terms of query
        LinkedHashMap<String, String> searchFieldMap = new LinkedHashMap<>();
        for (Map.Entry<String, String> entry : searchParameters.entrySet()) {
            searchFieldMap.put(searchFieldMapping.get(entry.getKey()), entry.getValue());
        }

        try {
            URI queryURL = createQueryURI(queryParameters);
            return performQuery(queryURL.toString() + "&maximumRecords=" + numberOfRecords + "&query="
                    + createSearchFieldString(searchFieldMap));
        } catch (URISyntaxException | UnsupportedEncodingException e) {
            logger.error(e.getLocalizedMessage());
        }
    }
    return null;
}

From source file:com.github.sardine.AuthenticationTest.java

@Test
public void testBasicAuth() throws Exception {
    Sardine sardine = SardineFactory.begin(properties.getProperty("username"),
            properties.getProperty("password"));
    try {/*from w  w w  .j  a  va  2s.com*/
        URI url = URI.create("http://sudo.ch/dav/basic/");
        final List<DavResource> resources = sardine.list(url.toString());
        assertNotNull(resources);
        assertFalse(resources.isEmpty());
    } catch (SardineException e) {
        fail(e.getMessage());
    }
}

From source file:de.otto.jsonhome.client.HttpJsonHomeClient.java

/**
 * {@inheritDoc}/*from w  w w  .j  av a 2s.c  om*/
 */
@Override
public JsonHome updateAndGet(final URI uri) {
    try {
        LOG.info("Expiring cached json-home document {}", uri);
        cacheStorage.removeEntry(uri.toString());
    } catch (IOException e) {
        throw new JsonHomeClientException("IOException caught while removing cache-entry: " + e.getMessage(),
                e);
    }
    return get(uri);
}

From source file:com.github.jknack.handlebars.TemplateLoader.java

/**
 * Load the template from a template repository.
 *
 * @param uri The resource's uri. Required.
 * @return The requested resource./*  w ww .  j a va2s  .c  om*/
 * @throws IOException If the resource cannot be loaded.
 */
public Reader load(final URI uri) throws IOException {
    notNull(uri, "The uri is required.");
    notEmpty(uri.toString(), "The uri is required.");
    String location = resolve(normalize(uri.toString()));
    Handlebars.debug("Loading resource: %s", location);
    Reader reader = read(location);
    if (reader == null) {
        throw new FileNotFoundException(location.toString());
    }
    Handlebars.debug("Resource found: %s", location);
    return reader;
}

From source file:com.github.sardine.AuthenticationTest.java

@Test
public void testDigestAuth() throws Exception {
    Sardine sardine = SardineFactory.begin(properties.getProperty("username"),
            properties.getProperty("password"));
    try {/*w  w w.  j  a  v  a  2  s. c  o m*/
        URI url = URI.create("http://sudo.ch/dav/digest/");
        final List<DavResource> resources = sardine.list(url.toString());
        assertNotNull(resources);
        assertFalse(resources.isEmpty());
    } catch (SardineException e) {
        fail(e.getMessage());
    }
}

From source file:org.mule.modules.bitly.MuleBitlyModule.java

/**
 * Custom processor/* ww w . j  a v a 2 s .  co m*/
 *
 * {@sample.xml ../../../doc/MuleBitly-connector.xml.sample mulebitly:my-processor}
 *
 * @param content Content to be processed
 * @return Some string
 */
@Processor
public String shorten(URI uri) {
    log.info("Shortening {}", uri);
    Map<String, String> params = new HashMap<String, String>(PARAMS);

    params.put("longUrl", uri.toString());

    Map<String, Object> res = restTemplate.getForObject(
            BITLY_API + "/shorten?login={login}&apiKey={apiKey}&longUrl={longUrl}&format={format}", Map.class,
            params);

    log.debug("Response from bit.ly: {}", res);

    if (!(res.get("status_code").equals(200))) {
        throw new RuntimeException(
                String.format("Error with bit.ly - {} {}", res.get("status_code"), res.get("status_txt")));
    }

    return ((Map<String, String>) (res.get("data"))).get("url");

}

From source file:com.springsource.insight.plugin.springweb.http.SimpleClientHttpRequestFactoryCollectionAspectTest.java

private Operation assertConnectionOperation(URI uri, String method) {
    return assertConnectionOperation(uri.toString(), method);
}

From source file:org.openlmis.fulfillment.service.referencedata.PeriodReferenceDataServiceTest.java

@Test
public void shouldReturnOrderablesById() {
    ProcessingPeriodDto period = mockPageResponseEntityAndGetDto();

    String startDate = "2018-04-05";
    String endDate = "2018-05-05";
    List<ProcessingPeriodDto> response = service.search(LocalDate.parse(startDate), LocalDate.parse(endDate));

    assertThat(response, hasSize(1));/*from www.  j  a  v a  2  s .  c o  m*/
    assertThat(response, hasItems(period));

    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(),
            refEq(new DynamicPageTypeReference<>(ProcessingPeriodDto.class)));

    URI uri = uriCaptor.getValue();
    assertEquals(serviceUrl + service.getUrl() + "?startDate=" + startDate + "&endDate=" + endDate,
            uri.toString());

    assertAuthHeader(entityCaptor.getValue());
    assertNull(entityCaptor.getValue().getBody());
}

From source file:com.github.thesmartenergy.sparql.generate.jena.engine.TestBase.java

void testPlanExecution() throws Exception {
    String query = IOUtils.toString(fileManager.open("query.rqg"), "UTF-8");
    System.out.println("query is: \n" + query);
    SPARQLGenerateQuery q = (SPARQLGenerateQuery) QueryFactory.create(query, SPARQLGenerate.SYNTAX);

    // create generation plan
    PlanFactory factory = new PlanFactory(fileManager);
    RootPlan plan = factory.create(q);//from  w w  w  .j av  a2s.  c  o  m
    Model output = ModelFactory.createDefaultModel();
    QuerySolutionMap initialBinding = null;

    // execute plan
    plan.exec(initialBinding, output);

    // write output

    String fileName = exampleDir.toString() + "/output.ttl";
    FileWriter out = new FileWriter(fileName);
    try {
        output.write(out, "TTL");
    } finally {
        try {
            out.close();
        } catch (IOException closeException) {
            LOG.debug("Error while writing to file");
        }
    }

    fileName = exampleDir.toString() + "/output.ttl";
    out = new FileWriter(fileName);
    try {
        output.write(out, "TTL");
    } finally {
        try {
            out.close();
        } catch (IOException closeException) {
            LOG.debug("Error while writing to file");
        }
    }

    URI expectedOutputUri = exampleDir.toURI().resolve("expected_output.ttl");
    Model expectedOutput = RDFDataMgr.loadModel(expectedOutputUri.toString());
    StringWriter sw = new StringWriter();
    LOG.debug(expectedOutput.write(sw, "TTL"));

    assertTrue(output.isIsomorphicWith(expectedOutput));
}

From source file:com.gistlabs.mechanize.requestor.RequestBuilder.java

private HttpRequestBase composeGetRequest(String uri, final Parameters parameters) {
    try {/*from   w  w w.j  a  v a  2s  .  c  om*/
        URIBuilder builder = new URIBuilder(uri);

        for (Parameter param : parameters)
            if (param.isSingleValue())
                builder.setParameter(param.getName(), param.getValue());
            else
                for (String value : param.getValues())
                    builder.addParameter(param.getName(), value);

        URI requestURI = builder.build();
        uri = requestURI.toString();
        return new HttpGet(requestURI);
    } catch (URISyntaxException e) {
        throw MechanizeExceptionFactory.newException(e);
    }
}