Example usage for java.net URI create

List of usage examples for java.net URI create

Introduction

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

Prototype

public static URI create(String str) 

Source Link

Document

Creates a URI by parsing the given string.

Usage

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.util.EvaluatorUtils.java

/**
 * Get the gold keyphrases from the file system.
 * By convention gold keyphrase files should have the same name as the document file.
 * Standard extension is .key, but something else can be specified in the corresponding parameter.
 *
 * @param metaData The DocumentMetaData annotation of this document.
 * @param goldSuffix The suffix of the gold standard file.
 * @param toLowerCase If gold keys should be lowercased or not.
 *
 * @return The set of gold keyphrases for this document.
 * @throws AnalysisEngineProcessException an analysis engine process exception
 *///from   w w  w. ja  v a  2 s  . c  o m
public static Set<String> getGoldKeyphrases(DocumentMetaData metaData, String goldSuffix, boolean toLowerCase)
        throws AnalysisEngineProcessException {

    Set<String> goldKeyphrases = new TreeSet<String>();

    String uri = metaData.getDocumentUri();
    URL keyUrl;
    try {
        keyUrl = URI.create(uri.substring(0, indexOfExtension(uri)) + goldSuffix).toURL();

        List<String> lines = IOUtils.readLines(keyUrl.openStream(), "UTF-8");

        for (String line : lines) {
            if (toLowerCase) {
                line = line.toLowerCase().trim();
            } else {
                line = line.trim();
            }
            if (line.length() > 0) {
                if (line.contains(";")) {
                    for (String part : line.split(";")) {
                        goldKeyphrases.add(part.trim());
                    }

                } else {
                    goldKeyphrases.add(line);
                }
            }
        }

        return goldKeyphrases;

    } catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }
}

From source file:com.fujitsu.dc.client.http.HttpAclMethod.java

/**
 * This is the parameterized constructor calling its parent constructor and setting URI after formatting it.
 * @param uri Target URL string/*from   www.j a v a  2 s .c  o m*/
 */
public HttpAclMethod(final String uri) {
    super();
    setURI(URI.create(uri));
}

From source file:org.apache.brooklyn.rest.CsrfTokenFilterLauncherTest.java

@Test
public void testRequestToken() {
    useServerForTest(baseLauncher().withoutJsgui().start());

    HttpClient client = client();/*ww  w . ja  va 2s. co  m*/

    HttpToolResponse response = HttpTool.httpGet(client, URI.create(getBaseUriRest() + "server/status"),
            ImmutableMap.<String, String>of(CsrfTokenFilter.CSRF_TOKEN_REQUIRED_HEADER,
                    CsrfTokenFilter.CsrfTokenRequiredForRequests.WRITE.toString()));

    // comes back okay
    assertOkayResponse(response, "MASTER");

    Map<String, List<String>> cookies = response.getCookieKeyValues();
    String token = Iterables.getOnlyElement(cookies.get(CsrfTokenFilter.CSRF_TOKEN_VALUE_COOKIE));
    Assert.assertNotNull(token);
    String tokenAngular = Iterables
            .getOnlyElement(cookies.get(CsrfTokenFilter.CSRF_TOKEN_VALUE_COOKIE_ANGULAR_NAME));
    Assert.assertEquals(token, tokenAngular);

    // can post subsequently with token
    response = HttpTool.httpPost(client, URI.create(getBaseUriRest() + "script/groovy"),
            ImmutableMap.<String, String>of(HttpHeaders.CONTENT_TYPE, "application/text",
                    CsrfTokenFilter.CSRF_TOKEN_VALUE_HEADER, token),
            "return 0;".getBytes());
    assertOkayResponse(response, "{\"result\":\"0\"}");

    // but fails without token
    response = HttpTool.httpPost(client, URI.create(getBaseUriRest() + "script/groovy"),
            ImmutableMap.<String, String>of(HttpHeaders.CONTENT_TYPE, "application/text"),
            "return 0;".getBytes());
    assertEquals(response.getResponseCode(), HttpStatus.SC_UNAUTHORIZED);

    // can get without token
    response = HttpTool.httpGet(client, URI.create(getBaseUriRest() + "server/status"),
            ImmutableMap.<String, String>of());
    assertOkayResponse(response, "MASTER");

    // but if we set required ALL then need a token to get
    response = HttpTool.httpGet(client, URI.create(getBaseUriRest() + "server/status"),
            ImmutableMap.<String, String>of(CsrfTokenFilter.CSRF_TOKEN_REQUIRED_HEADER,
                    CsrfTokenFilter.CsrfTokenRequiredForRequests.ALL.toString().toLowerCase()));
    assertOkayResponse(response, "MASTER");
    response = HttpTool.httpGet(client, URI.create(getBaseUriRest() + "server/status"),
            ImmutableMap.<String, String>of());
    assertEquals(response.getResponseCode(), HttpStatus.SC_UNAUTHORIZED);

    // however note if we use a new client, with no session, then we can post with no token
    // (ie we don't guard against CSRF if your brooklyn is unsecured)
    client = client();
    response = HttpTool.httpPost(client, URI.create(getBaseUriRest() + "script/groovy"),
            ImmutableMap.<String, String>of(HttpHeaders.CONTENT_TYPE, "application/text"),
            "return 0;".getBytes());
    assertOkayResponse(response, "{\"result\":\"0\"}");
}

From source file:nl.surfnet.coin.janus.JanusRestClientTest.java

@Before
public void before() {
    janusRestClient = new JanusRestClient();
    janusRestClient.setSecret("secret");
    janusRestClient.setUser("user");
    janusRestClient.setJanusUri(URI.create("http://localhost/"));
    MockitoAnnotations.initMocks(this);
}

From source file:com.hp.autonomy.frontend.find.hod.web.HodErrorController.java

@Override
protected URI getErrorUrl(final HttpServletRequest request) {
    return URI.create(configService.getConfig().getHsod().getFindAppUrl().toString());
}

From source file:piecework.content.concrete.RemoteResourceTest.java

@Before
public void setup() {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(100);//from  ww  w.  j av a2s .c  o  m
    this.client = HttpClients.custom().setConnectionManager(cm).build();
    URI uri = URI.create(URI_STRING);
    this.remoteResource = new RemoteResource(client, uri);
}

From source file:jails.http.client.CommonsClientHttpRequest.java

public URI getURI() {
    try {/*from  w w w.  j av  a 2 s. c om*/
        return URI.create(this.httpMethod.getURI().getEscapedURI());
    } catch (URIException ex) {
        throw new IllegalStateException("Could not get HttpMethod URI: " + ex.getMessage(), ex);
    }
}

From source file:com.github.fge.jsonschema.load.URIManagerTest.java

@Test
public void unhandledSchemeShouldBeReportedAsSuch() {
    final URI uri = URI.create("bar://baz");
    final URIManager manager = new URIManager();

    try {/* www. j a  v a2s.  c  om*/
        manager.getContent(uri);
    } catch (ProcessingException e) {
        assertMessage(e.getProcessingMessage()).hasMessage(BUNDLE.getString("unhandledScheme"))
                .hasField("scheme", "bar").hasField("uri", uri).hasLevel(LogLevel.FATAL);
    }
}

From source file:com.xx_dev.apn.proxy.utils.HostNamePortUtil.java

public static int getPort(HttpRequest httpRequest) {
    int originalPort = 80;

    if (httpRequest.getMethod().equals(HttpMethod.CONNECT)) {
        originalPort = 443;/* w w  w .j a va2  s  .c om*/
    }

    String originalHostHeader = httpRequest.headers().get(HttpHeaders.Names.HOST);

    if (StringUtils.isBlank(originalHostHeader) && httpRequest.getMethod().equals(HttpMethod.CONNECT)) {
        originalHostHeader = httpRequest.getUri();
    }

    if (StringUtils.isNotBlank(originalHostHeader)) {
        if (StringUtils.split(originalHostHeader, ": ").length == 2) {
            originalPort = Integer.parseInt(StringUtils.split(originalHostHeader, ": ")[1]);
        }
    } else {
        String uriStr = httpRequest.getUri();
        try {
            URI uri = URI.create(uriStr);

            if (uri.getPort() > 0) {
                originalPort = uri.getPort();
            }
        } catch (IllegalArgumentException e) {
            logger.error(e.getMessage(), e);
            originalPort = -1;
        }
    }

    return originalPort;
}

From source file:org.fabric3.samples.hibernate.MessageService.java

@POST
@Path("/message")
public Response create(Message message) {
    em.persist(message);//w ww  . jav a 2s .  c om
    return Response.created(URI.create(message.getId().toString())).build();
}