Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

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

Prototype

public URI(String str) throws URISyntaxException 

Source Link

Document

Constructs a URI by parsing the given string.

Usage

From source file:com.cazcade.billabong.image.impl.ImageMain.java

private static void sendImageRequest(ImageService service, String uriString) throws URISyntaxException {
    CacheResponse response = service.getCacheURIForImage(
            new ImageServiceRequest(new URI(uriString), ImageSize.CLIPPED_MEDIUM, true, uriString));
    System.out.println(response.getURI());
    System.out.println(response.getRefreshIndicator());
}

From source file:com.vmware.identity.interop.ldap.DirectoryStoreProtocol.java

public URI getUri(String hostName, int port) {
    try {//from  w  w w.  jav a 2 s  .co m
        return new URI(String.format("%s://%s:%d", this.name,
                InetAddressUtils.isIPv6Address(hostName) ? ("[" + hostName + "]") : hostName, port));
    } catch (Exception e) {
        return null;
    }
}

From source file:com.macrossx.wechat.impl.WechatUserHelper.java

public Optional<WechatUserGet> userGet(String nextOpenid) {
    try {// w  w w .  j a va2 s . c o m
        Optional<WechatAccessToken> token = helper.getAccessToken();
        if (token.isPresent()) {
            WechatAccessToken accessToken = token.get();
            HttpGet httpGet = new HttpGet();

            httpGet.setURI(new URI(MessageFormat.format(WechatConstants.USER_GET_URL,
                    accessToken.getAccess_token(), nextOpenid == null ? "" : nextOpenid)));
            return new WechatHttpClient().send(httpGet, WechatUserGet.class);
        }
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        log.info(e.getMessage());
    }
    return Optional.empty();
}

From source file:com.oakley.fon.util.RemoveHttpsRedirectHandler.java

@Override
public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException {
    String uri = super.getLocationURI(response, context).toString();
    if (uri.startsWith("https")) {
        uri = uri.replaceFirst("https", "http");
        Log.d(TAG, "Removing https from redirect:" + uri);
    }//from   ww  w  . j a va 2 s  . c  o  m
    URI notSafeUri = null;
    try {
        notSafeUri = new URI(uri);
    } catch (URISyntaxException e) {
        Log.e(TAG, "error change URI", e);
    }
    return notSafeUri;
}

From source file:com.rusticisoftware.tincan.Attachment.java

public Attachment(JsonNode jsonNode) throws URISyntaxException, MalformedURLException {
    JsonNode usageTypeNode = jsonNode.path("usageType");
    if (!usageTypeNode.isMissingNode()) {
        this.setUsageType(new URI(usageTypeNode.textValue()));
    }/*  www.  j  a va  2s .c  o  m*/

    JsonNode displayNode = jsonNode.path("display");
    if (!displayNode.isMissingNode()) {
        this.setDisplay(new LanguageMap(displayNode));
    }

    JsonNode descriptionNode = jsonNode.path("description");
    if (!descriptionNode.isMissingNode()) {
        this.setDescription(new LanguageMap(descriptionNode));
    }

    JsonNode contentTypeNode = jsonNode.path("contentType");
    if (!contentTypeNode.isMissingNode()) {
        this.setContentType(contentTypeNode.textValue());
    }

    JsonNode lengthNode = jsonNode.path("length");
    if (!lengthNode.isMissingNode()) {
        this.setLength(lengthNode.intValue());
    }

    JsonNode sha2Node = jsonNode.path("sha2");
    if (!sha2Node.isMissingNode()) {
        this.setSha2(sha2Node.textValue());
    }

    JsonNode fileUrlNode = jsonNode.path("fileUrl");
    if (!fileUrlNode.isMissingNode()) {
        this.setFileUrl(new URL(fileUrlNode.textValue()));
    }
}

From source file:es.upm.oeg.examples.watson.service.PersonalityInsightsService.java

public String analyse(String text) throws IOException, URISyntaxException {

    logger.info("Analyzing the text: \n" + text);

    URI profileURI = new URI(baseURL + "/v2/profile").normalize();
    logger.info("Profile URI: " + profileURI.toString());

    Request profileRequest = Request.Post(profileURI).addHeader("Accept", "application/json").bodyString(text,
            ContentType.TEXT_PLAIN);//from   w w w  . j  ava 2  s. c o  m

    Executor executor = Executor.newInstance().auth(username, password);
    Response response = executor.execute(profileRequest);
    HttpResponse httpResponse = response.returnResponse();
    StatusLine statusLine = httpResponse.getStatusLine();

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    httpResponse.getEntity().writeTo(os);
    String responseBody = new String(os.toByteArray());

    if (statusLine.getStatusCode() == HttpStatus.SC_OK) {

        return responseBody;

    } else {

        String msg = String.format("Personality Insights Service failed - %d %s \n %s",
                statusLine.getStatusCode(), statusLine.getReasonPhrase(), response);
        logger.severe(msg);
        throw new RuntimeException(msg);
    }
}

From source file:pamela.client2.PamelaWebservice.java

protected List<String> getMacs() {
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
    HttpConnectionParams.setSoTimeout(httpParams, 10000);
    DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);

    String json = "";

    try {//from ww w.j a  v  a  2  s  . co  m
        URI uri = new URI(url);
        HttpGet httpGet = new HttpGet(uri);
        HttpResponse response = httpClient.execute(httpGet);
        json = EntityUtils.toString(response.getEntity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    ArrayList<String> macs = new ArrayList<String>();

    int i = 0;

    for (String part : json.split("\"")) {
        i++;

        // These will be the macs.
        // Assuming no lamefag put's an " in his name :)
        if (i % 2 == 0) {
            macs.add(part);
        }
    }

    return (List<String>) macs;
}

From source file:com.bigdata.rockstor.console.RockStorSender.java

private static HttpRequestBase buildHttpRequest(HttpReq req)
        throws UnsupportedEncodingException, URISyntaxException {

    HttpRequestBase request = null;/*from  www.j a va 2 s  .c  o  m*/
    if ("GET".equals(req.getMethod())) {
        request = new HttpGet();
    } else if ("PUT".equals(req.getMethod())) {
        request = new HttpPut();
        if (req.getBody() != null && req.getBody().length() > 0)
            ((HttpPut) request).setEntity(new StringEntity(req.getBody()));
    } else if ("DELETE".equals(req.getMethod())) {
        request = new HttpDelete();
    } else if ("HEAD".equals(req.getMethod())) {
        request = new HttpHead();
    } else {
        throw new NullPointerException("Unknown HTTP Method : " + req.getMethod());
    }

    request.setURI(new URI(req.getUrl()));

    if (req.getHead() != null) {
        for (Map.Entry<String, String> e : req.getHead().entrySet()) {
            if ("PUT".equals(req.getMethod()) && e.getKey().equals("Content-Length"))
                continue;
            request.setHeader(e.getKey(), e.getValue());
        }
    }

    return request;
}

From source file:es.tid.fiware.rss.exceptionhandles.RssExceptionMapperTest.java

/**
 * //from   w ww. ja  v  a2 s  .co m
 */
@Test
public void toResponse() throws Exception {
    RssExceptionMapper mapper = new RssExceptionMapper();
    UriInfo mockUriInfo = Mockito.mock(UriInfo.class);
    Mockito.when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com/go"));
    ReflectionTestUtils.setField(mapper, "uriInfo", mockUriInfo);

    HttpHeaders headers = Mockito.mock(HttpHeaders.class);
    Mockito.when(headers.getAcceptableMediaTypes()).thenReturn(null);
    ReflectionTestUtils.setField(mapper, "headers", headers);

    RSSException e = new RSSException("RssException");
    Response response = mapper.toResponse(e);
    // other type
    NotFoundException ex = new NotFoundException();
    response = mapper.toResponse(ex);
    // other
    Exception ex1 = new Exception("Exception");
    response = mapper.toResponse(ex1);
    Assert.assertTrue(true);
}

From source file:ca.ualberta.physics.cssdp.util.JSONURIDeserializer.java

@Override
public URI deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    try {// ww  w  .  j  a v  a  2  s  .  co m
        return new URI(jp.getText());
    } catch (URISyntaxException e) {
        logger.error("Could not deserialize json representation of URI " + jp.getText()
                + " into URI object because " + e.getMessage(), e);
    }
    return null;
}