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.nebel_tv.content.api.ContentWrapper.java

@Override
public WrapperResponse getMediaData(String url) {

    try {//from   w w  w. j  a  v  a 2s.c om
        String name = getUrlLastSegment(url);
        IWrapperMethod method = WrapperMethodFactory.getMethodByName(name);

        if (method != null) {
            List<NameValuePair> pairs = URLEncodedUtils.parse(new URI(url), "UTF-8");

            Map<String, String> params = new HashMap<String, String>();
            for (NameValuePair param : pairs) {
                params.put(param.getName(), param.getValue());
            }
            return method.execute(params);
        }
    } catch (URISyntaxException ex) {
        Logger.getLogger(ContentWrapper.class.getName()).log(Level.WARNING, null, ex);
    } catch (InvalidParameterException ex) {
        Logger.getLogger(ContentWrapper.class.getName()).log(Level.SEVERE, null, ex);

        return new WrapperResponse(ResponseResult.InvalidParams, ResponseType.Content, "");
    }
    return new WrapperResponse(ResponseResult.InvalidUrl, ResponseType.Content, "");
}

From source file:lv.vizzual.numuri.service.http.HttpProvider.java

private void processGet(Request req) {
    HttpGet get = null;/*w  ww .jav a  2s. com*/
    String result = null;
    HttpResponse response = null;

    try {
        get = new HttpGet(new URI(req.getUrl()));
        response = client.execute(get);

        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            result = convertStreamToString(is);

            req.setResult(result);
            req.setSuccess(true);
        }
    } catch (IOException ex) {
        Log.d(TAG, "request failed", ex);
        req.setSuccess(false);
    } catch (URISyntaxException ex) {
        Log.d(TAG, "uri invalid", ex);
        req.setSuccess(false);
    }
}

From source file:com.google.android.vending.licensing.ResponseData.java

private static Map<String, String> decodeExtras(String extras) {
    Map<String, String> results = new HashMap<>();
    URI rawExtras;//w  w  w .jav a  2  s  .  c  o  m
    try {
        rawExtras = new URI("?" + extras);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Invalid syntax error while decoding extras data from " + "server.");
    }

    List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8");
    for (NameValuePair item : extraList) {
        String name = item.getName();
        int i = 0;
        while (results.containsKey(name)) {
            name = item.getName() + ++i;
        }
        results.put(name, item.getValue());
    }
    return results;
}

From source file:de.betterform.connector.http.HTTPURIResolver.java

/**
 * Performs link traversal of the <code>http</code> URI and returns the result
 * as a DOM document./* w w w  .ja v a 2 s. co  m*/
 *
 * @return a DOM node parsed from the <code>http</code> URI.
 * @throws XFormsException if any error occurred during link traversal.
 */
public Object resolve() throws XFormsException {
    URI uri = null;
    try {
        uri = new URI(getURI());
    } catch (URISyntaxException e) {
        throw new XFormsException(e);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("getting '" + uri + "'");
    }

    get(getURIWithoutFragment());

    InputStream responseStream = getResponseBody();
    Map header = getResponseHeader();
    String contentType = (String) header.get("Content-Type");
    contentType = parseContentType(contentType);

    if ("text/plain".equalsIgnoreCase(contentType) || "text/html".equalsIgnoreCase(contentType)) {
        try {
            return inputStreamToString(responseStream);
        } catch (IOException e) {
            throw new XFormsException(e);
        }
    } else if ("application/xml".equalsIgnoreCase(contentType) || "text/xml".equalsIgnoreCase(contentType)
            || "application/xhtml+xml".equalsIgnoreCase(contentType)
            || "application/xml+xslt".equalsIgnoreCase(contentType)) {
        try {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("converting response stream to XML");
            }
            return buildDocument(uri, responseStream);
        } catch (Exception e) {
            throw new XFormsException(e);
        }
    } else {
        LOGGER.warn(
                "WARN WARN WARN WARN WARN WARN WARN: Contenttype of response can not be handled. contentype:"
                        + contentType);
        return null;
    }
}

From source file:org.springframework.cloud.dataflow.rest.util.HttpClientConfigurerTests.java

/**
 * Basic test ensuring that the {@link HttpClient} is built successfully with
 * null username and password.//from   w ww  . j  a  v a 2  s. com
 */
@Test
public void testThatHttpClientWithProxyIsCreatedWithNullUsernameAndPassword() throws Exception {
    final URI targetHost = new URI("http://test.com");
    final HttpClientConfigurer builder = HttpClientConfigurer.create(targetHost);
    builder.withProxyCredentials(URI.create("https://spring.io"), null, null);
    builder.buildHttpClient();
}

From source file:eu.eubrazilcc.lvl.core.servlet.ServletUtils.java

/**
 * Gets the portal endpoint by inspecting the application configuration. In case that the endpoint
 * cannot be discovered from the configuration, 
 * @param baseUri - the base URI where the service is running
 * @return/*from   w  ww. j a  v  a  2s.c  om*/
 */
public static final URI getPortalEndpoint(final URI baseUri) {
    URI portalUri = null;
    try {
        final String portalEndpoint = CONFIG_MANAGER.getPortalEndpoint();
        portalUri = isNotBlank(portalEndpoint) ? new URI(portalEndpoint.replaceAll("/$", ""))
                : new URI(baseUri.getScheme(), baseUri.getAuthority(), null, null, null);
    } catch (URISyntaxException e) {
        LOGGER.error("Failed to create LVL portal endpoint", e);
    }
    return portalUri;
}

From source file:cn.isif.util_plus.http.client.util.URIBuilder.java

public URIBuilder(final String uri) {
    try {/*from   w  w w  .j  ava 2s  . c  o  m*/
        digestURI(new URI(uri));
    } catch (URISyntaxException e) {
        LogUtils.e(e.getMessage(), e);
    }
}

From source file:com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacadeTest.java

@Before
public void setUp() throws Exception {
    profile = OAuth2TestUtils.getOAuthProfileWithDefaultValues();
    profileWithOnlyAccessToken = OAuth2TestUtils.getOAuth2ProfileWithOnlyAccessToken();
    httpRequest = new ExtendedPostMethod();
    httpRequest.setURI(new URI("endpoint/path"));
    oltuClientFacade = OAuth2TestUtils.getOltuOAuth2ClientFacadeWithMockedTokenExtractor(profile);
}

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

@Test
public void toResponse() throws Exception {
    UriInfo mockUriInfo = Mockito.mock(UriInfo.class);
    Mockito.when(mockUriInfo.getAbsolutePath()).thenReturn(new URI("http://www.test.com/go"));
    ReflectionTestUtils.setField(mapper, "uriInfo", mockUriInfo);

    RSSException e = new RSSException("RssException");
    Response response = mapper.toResponse(e);
    Assert.assertTrue(true);//  w  w  w.  j av a  2  s  .  c o m

    GenericJDBCException ex = new GenericJDBCException("sql", new SQLException("reason"));
    response = mapper.toResponse(ex);
    Assert.assertTrue(true);

    JDBCConnectionException ex1 = new JDBCConnectionException("sql", new SQLException("reason"));
    response = mapper.toResponse(ex1);
    Assert.assertTrue(true);

    NotFoundException ex2 = new NotFoundException();
    response = mapper.toResponse(ex2);
    Assert.assertTrue(true);

    Exception ex3 = new Exception("RssException");
    response = mapper.toResponse(ex3);
    Assert.assertTrue(true);

    Exception ex4 = new Exception("RssException", ex);
    response = mapper.toResponse(ex4);
    Assert.assertTrue(true);

    Exception ex5 = new Exception("RssException", ex1);
    response = mapper.toResponse(ex5);
    Assert.assertTrue(true);

}

From source file:com.redhat.jenkins.plugins.bayesian.Bayesian.java

public Bayesian(String url) throws URISyntaxException {
    URI uri = new URI(url);
    String host = uri.getHost();//ww w. j a v  a2s.  c  o  m
    if (host.indexOf('.') == -1) {
        // looks like it's a short domain name
        // TODO: there can be dots in short domain names as well
        List<String> cnames = DnsFiddler.getActualCNAME(host);
        if (!cnames.isEmpty()) {
            String hostname = cnames.get(0);
            if (hostname.endsWith(".")) {
                hostname = hostname.substring(0, hostname.length() - 1);
            }
            uri = new URIBuilder(uri).setHost(hostname).build();
        }
        cnames = null;
    }
    this.url = uri.toString();
}