Example usage for java.net URI toURL

List of usage examples for java.net URI toURL

Introduction

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

Prototype

public URL toURL() throws MalformedURLException 

Source Link

Document

Constructs a URL from this URI.

Usage

From source file:org.apache.ode.axis2.util.Axis2WSDLLocator.java

public InputStream openResource(URI uri) throws IOException {
    if (uri.isAbsolute() && uri.getScheme().equals("file")) {
        try {//from  w  w  w .  j a  v  a  2s . com
            return uri.toURL().openStream();
        } catch (Exception except) {
            LOG.error("openResource: unable to open file URL " + uri + "; " + except.toString());
            return null;
        }
    }

    // Note that if we get an absolute URI, the relativize operation will simply
    // return the absolute URI.
    URI relative = _baseUri.relativize(uri);
    if (relative.isAbsolute() && !relative.getScheme().equals("urn")) {
        LOG.error("openResource: invalid scheme (should be urn:)  " + uri);
        return null;
    }

    File f = new File(_baseUri.getPath(), relative.getPath());
    if (!f.exists()) {
        LOG.error("openResource: file not found " + f);
        return null;
    }
    return new FileInputStream(f);
}

From source file:org.apache.axis2.jaxws.util.CatalogWSDLLocator.java

/**
 * Returns an InputStream pointed at an imported wsdl pathname relative to
 * the parent document./*from ww  w  .  j av  a 2 s. c  o m*/
 * 
 * @param importPath
 *            identifies the WSDL file within the context
 * @return a stream of the WSDL file
 */
protected InputStream getInputStream(String importPath) throws IOException {
    URL importURL = null;
    InputStream is = null;
    try {
        importURL = new URL(importPath);
        is = importURL.openStream();
    } catch (Throwable t) {
        // No FFDC required
    }
    if (is == null) {
        try {
            is = classLoader.getResourceAsStream(importPath);
        } catch (Throwable t) {
            // No FFDC required
        }
    }
    if (is == null) {
        try {
            File file = new File(importPath);
            is = file.toURL().openStream();
        } catch (Throwable t) {
            // No FFDC required
        }
    }
    if (is == null) {
        try {
            URI uri = new URI(importPath);
            is = uri.toURL().openStream();
        } catch (Throwable t) {
            // No FFDC required
        }
    }
    return is;
}

From source file:org.kalypso.ogc.gml.featureview.control.AbstractImageFeatureControl.java

/** Translates platform url's to file url's */
private URL translateLocation(final URL url) {
    if (url == null)
        return null;

    final IFile file = ResourceUtilities.findFileFromURL(url);
    if (file == null)
        return url;

    final URI locationURI = file.getLocationURI();
    if (locationURI == null)
        return url;

    try {//ww w. j av a 2s.  c  o m
        return locationURI.toURL();
    } catch (final MalformedURLException e) {
        e.printStackTrace();
        return url;
    }
}

From source file:org.gradle.internal.resource.UriResource.java

private Reader getInputStream(URI url) throws IOException {
    final URLConnection urlConnection = url.toURL().openConnection();
    urlConnection.setRequestProperty("User-Agent", getUserAgentString());
    urlConnection.connect();/*from  w ww .  j a  va 2  s .  c  o m*/
    String charset = extractCharacterEncoding(urlConnection.getContentType(), "utf-8");
    return new InputStreamReader(urlConnection.getInputStream(), charset);
}

From source file:org.apache.olingo.odata2.fit.basic.FitLoadTest.java

@Test
public void useJavaHttpClient() throws IOException {
    final URI uri = URI.create(getEndpoint().toString() + "$metadata");
    for (int i = 0; i < LOOP_COUNT; i++) {
        HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty(HttpHeaders.ACCEPT, HttpContentType.WILDCARD);
        connection.connect();//from   w w  w .j a  v  a2  s.c  om
        assertEquals(HttpStatusCodes.OK.getStatusCode(), connection.getResponseCode());
        assertEquals(HttpContentType.APPLICATION_XML_UTF8, connection.getContentType());
    }
}

From source file:com.measurence.sdk.android.api_subscriptions.MeasurenceAPISubscriptions.java

private String invokeApiSubscriptionEndPoint(URI apiSubscriptionURI) throws IOException {
    InputStream apiSubscriptionRequestStream = null;
    try {/*  w ww . j  a  v  a 2s. c  o  m*/
        apiSubscriptionRequestStream = apiSubscriptionURI.toURL().openStream();
        return IOUtils.toString(apiSubscriptionRequestStream);
    } finally {
        IOUtils.closeQuietly(apiSubscriptionRequestStream);
    }
}

From source file:cat.calidos.morfeu.model.injection.DocumentTest.java

private Document parseRelativeLocation(String location)
        throws ParsingException, FetchingException, URISyntaxException, MalformedURLException, IOException {

    String absoluteLocation = this.getClass().getClassLoader().getResource(location).toString();
    URI uri = new URI(absoluteLocation);
    InputStream stream = FileUtils.openInputStream(FileUtils.toFile(uri.toURL()));
    ObjectMapper mapper = JSONMapperModule.produceJSONObjectMapper();
    Document document = DocumentModule.parseDocument(uri, stream, mapper);

    return document;

}

From source file:br.com.autonomiccs.autonomic.plugin.common.utils.NotifySmartAcsStartUpUtils.java

public void sendModuleStartUp(Class<?> clazz) {
    try {/*w  w  w .  j  a  va 2s  . c  o m*/
        URI uri = new URI("http", "smartcloudstack.lrg.ufsc.br:8080", "/boot/log/" + uuid,
                String.format("msg=Module initialized[%s]", ObjectUtils.toString(clazz)), null);
        httpUtils.executeHttpGetRequest(uri.toURL());
    } catch (IOException | URISyntaxException e) {
        logger.info("Problems while notifying home about the modules startup.");
    }
}

From source file:org.gvsig.framework.web.ogc.CSWISO19115LangCatalogServiceDriver.java

/**
 * It try to discover the server capabilities.
 *
 * @param uri Server URI/*from ww  w. jav a2 s  .c  om*/
 * @param language. Can be null. By default english.
 * @return Node with the server answer.
 * @throws NotSupportedVersionException only supports 2.0.2 version.
 */
public DiscoveryServiceCapabilities getCapabilities(URI uri, String language)
        throws NotSupportedVersionException {
    URL url = null;
    try {
        url = uri.toURL();
    } catch (MalformedURLException e) {
        setServerAnswerReady("errorServerNotFound");
        return null;
    }
    @SuppressWarnings("rawtypes")
    Collection nodes = new java.util.ArrayList();

    NameValuePair nvp1 = new NameValuePair("request", CSWConstants.OPERATION_GETCAPABILITIES);
    NameValuePair nvp2 = new NameValuePair("service", ServerData.SERVER_SUBTYPE_CATALOG_CSW);
    NameValuePair nvp3 = new NameValuePair("acceptFormats", "text/xml");
    NameValuePair[] parameters;
    if (language != null) {
        NameValuePair nvp4 = new NameValuePair("language", language);
        parameters = new NameValuePair[] { nvp1, nvp2, nvp3, nvp4 };
    } else {
        parameters = new NameValuePair[] { nvp1, nvp2, nvp3 };
    }

    nodes = new HTTPGetProtocol().doQuery(url, parameters, 0);
    CSWCapabilitiesParser parser = new CSWCapabilitiesParser(url, this);
    capabilities = parser.parse((XMLNode) nodes.toArray()[0]);
    // There are servers that need the getCapabilities operation (instead of
    // GetCapabilities)
    if (!(capabilities.isAvailable()) && (capabilities.getException() != null)) {
        CSWException exception = capabilities.getException();
        if ((exception.getCode().equals(CSWException.CODE_ERROR))
                && (exception.getSubcode().equals(CSWException.SUBCODE_ERROR))) {
            nodes = new HTTPGetProtocol().doQuery(url, CSWAbstractMessages.getHTTPGETCapabilitiesLower(), 0);
            capabilities = parser.parse((XMLNode) nodes.toArray()[0]);
        }
    }
    String version = capabilities.getVersion();
    if (version != null && !version.equalsIgnoreCase("2.0.2")) {
        throw new NotSupportedVersionException();
    }
    // If the version can be retrieved the CSWAbstractMessages object
    // cant be created
    setMessages(uri, url);
    return capabilities;
}

From source file:com.shazam.fork.reporter.gradle.JenkinsDownloader.java

@Nonnull
private URL getArtifactUrl(Build build, Artifact artifact) {
    try {//from   w  ww.  j  av  a 2  s  . c om
        URI uri = new URI(build.getUrl());
        String artifactPath = uri.getPath() + "artifact/" + artifact.getRelativePath();
        URI artifactUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
                artifactPath, "", "");
        return artifactUri.toURL();
    } catch (URISyntaxException | MalformedURLException e) {
        throw new GradleException("Error when trying to construct artifact URL for: " + build.getUrl(), e);
    }
}