Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

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

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:com.adaptris.core.jms.VendorImplementationImp.java

public JmsDestination createDestination(String destination, JmsActorConfig c) throws JMSException {
    JmsDestinationImpl jmsDest = new JmsDestinationImpl();
    try {//from   www.ja  va2s .c  om
        URI uri = new URI(destination);
        if (!uri.getScheme().equals("jms")) {
            throw new JMSException("failed to parse [" + destination + "]; doesn't start with 'jms'");
        }
        String[] parts = uri.getRawSchemeSpecificPart().split("\\?");
        String[] typeAndName = parts[0].split(":");
        String type = URLDecoder.decode(typeAndName[0], URI_CHARSET);
        String name = URLDecoder.decode(typeAndName[1], URI_CHARSET);
        jmsDest.destType = JmsDestination.DestinationType.valueOf(type.toUpperCase());

        jmsDest.setDestination(jmsDest.destType.create(this, c, name));

        if (parts.length > 1) {
            Map<String, String> params = URLHelper.queryStringToMap(parts[1], URI_CHARSET);
            jmsDest.setDeliveryMode(params.get(RFC6167_DELIVERY_MODE));
            jmsDest.setPriority(params.get(RFC6167_PRIORITY));
            jmsDest.setTimeToLive(params.get(RFC6167_TIME_TO_LIVE));
            jmsDest.setSubscriptionId(params.get(RFC6167_SUBSCRIPTION_ID));
            jmsDest.setSharedConsumerId(params.get(JMS20_SHARED_CONSUMER_ID));
            jmsDest.setNoLocal(params.get(RFC6167_NO_LOCAL));
            String replyToName = params.get(RFC6167_REPLY_TO_NAME);
            if (!isEmpty(replyToName)) {
                jmsDest.setReplyTo(jmsDest.destType.create(this, c, replyToName));
            }
        }
    } catch (NullPointerException e) {
        throw new JMSException("failed to parse [" + destination + "]; NullPointerException");
    } catch (Exception e) {
        JmsUtils.rethrowJMSException(e);
    }
    return jmsDest;
}

From source file:org.apache.juddi.v3.client.mapping.wsdl.WSDLLocatorImpl.java

/**
 * Internal method to normalize the importUrl. The importLocation can be
 * relative to the parentLocation.//from w  w  w.j  a v a  2 s .  c  o m
 *
 * @param parentLocation
 * @param importLocation
 * @return a url
 */
protected URL constructImportUrl(String parentLocation, String importLocation) {
    URL importUrl = null;
    try {
        URI importLocationURI = new URI(importLocation);
        if (importLocationURI.getScheme() != null || parentLocation == null) {
            importUrl = importLocationURI.toURL();
        } else {
            String parentDir = parentLocation.substring(0, parentLocation.lastIndexOf("/"));
            URI uri = new URI(parentDir + "/" + importLocation);
            importUrl = uri.normalize().toURL();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    if (importUrl != null) {
        log.debug("importUrl: " + importUrl.toExternalForm());
    } else {
        log.error("importUrl is null!");
    }
    return importUrl;
}

From source file:feign.httpclient.ApacheHttpClient.java

HttpUriRequest toHttpUriRequest(Request request, Request.Options options)
        throws UnsupportedEncodingException, MalformedURLException, URISyntaxException {
    RequestBuilder requestBuilder = RequestBuilder.create(request.method());

    //per request timeouts
    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(options.connectTimeoutMillis())
            .setSocketTimeout(options.readTimeoutMillis()).build();
    requestBuilder.setConfig(requestConfig);

    URI uri = new URIBuilder(request.url()).build();

    requestBuilder.setUri(uri.getScheme() + "://" + uri.getAuthority() + uri.getRawPath());

    //request query params
    List<NameValuePair> queryParams = URLEncodedUtils.parse(uri, requestBuilder.getCharset().name());
    for (NameValuePair queryParam : queryParams) {
        requestBuilder.addParameter(queryParam);
    }//from  ww  w .  j a  va 2  s.  co  m

    //request headers
    boolean hasAcceptHeader = false;
    for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) {
        String headerName = headerEntry.getKey();
        if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) {
            hasAcceptHeader = true;
        }

        if (headerName.equalsIgnoreCase(Util.CONTENT_LENGTH)) {
            // The 'Content-Length' header is always set by the Apache client and it
            // doesn't like us to set it as well.
            continue;
        }

        for (String headerValue : headerEntry.getValue()) {
            requestBuilder.addHeader(headerName, headerValue);
        }
    }
    //some servers choke on the default accept string, so we'll set it to anything
    if (!hasAcceptHeader) {
        requestBuilder.addHeader(ACCEPT_HEADER_NAME, "*/*");
    }

    //request body
    if (request.body() != null) {
        HttpEntity entity = null;
        if (request.charset() != null) {
            ContentType contentType = getContentType(request);
            String content = new String(request.body(), request.charset());
            entity = new StringEntity(content, contentType);
        } else {
            entity = new ByteArrayEntity(request.body());
        }

        requestBuilder.setEntity(entity);
    }

    return requestBuilder.build();
}

From source file:com.subgraph.vega.impl.scanner.urls.ResponseAnalyzer.java

private URI stripQuery(URI uri) {
    try {/*w w  w. j  a v  a 2s  .com*/
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null,
                null);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.fao.geonet.MockRequestFactoryGeonet.java

@Override
public ClientHttpResponse execute(HttpUriRequest request, Function<HttpClientBuilder, Void> configurator)
        throws IOException {
    final URI uri = request.getURI();
    final Request key = new Request(uri.getHost(), uri.getPort(), uri.getScheme(), null);
    final XmlRequest xmlRequest = (XmlRequest) getRequest(key);
    return new MockClientHttpResponse(Xml.getString(xmlRequest.execute()).getBytes(Constants.CHARSET),
            HttpStatus.OK);//from  w  w  w .  j a v  a 2 s  .  c o  m
}

From source file:com.smartitengineering.cms.ws.resources.workspace.WorkspaceFriendliesResource.java

protected WorkspaceResource getWorkspaceResource(final String uri)
        throws IllegalArgumentException, ContainerException, ClassCastException, UriBuilderException {
    final URI checkUri;
    if (uri.startsWith("http:")) {
        checkUri = URI.create(uri);
    } else {/*from  www. j a  v  a  2  s  .  c o m*/
        URI absUri = getAbsoluteURIBuilder().build();
        checkUri = UriBuilder.fromPath(uri).host(absUri.getHost()).port(absUri.getPort())
                .scheme(absUri.getScheme()).build();
    }
    WorkspaceResource resource = getResourceContext().matchResource(checkUri, WorkspaceResource.class);
    return resource;
}

From source file:com.almende.eve.transport.Router.java

@Override
public void send(final URI receiverUri, final String message, final String tag) throws IOException {
    final Transport transport = transports.get(receiverUri.getScheme().toLowerCase());
    if (transport != null) {
        transport.send(receiverUri, message, tag);
    } else {//  w  w  w.  j ava  2s  .  c om
        throw new IOException("No transport known for scheme:" + receiverUri.getScheme());
    }
}

From source file:com.almende.eve.transport.Router.java

@Override
public void send(final URI receiverUri, final byte[] message, final String tag) throws IOException {
    final Transport transport = transports.get(receiverUri.getScheme().toLowerCase());
    if (transport != null) {
        transport.send(receiverUri, message, tag);
    } else {//  w ww  . ja va 2 s  .  c  o m
        throw new IOException("No transport known for scheme:" + receiverUri.getScheme());
    }
}

From source file:com.almende.eve.transport.Router.java

@Override
public void send(final URI receiverUri, final Object message, final String tag) throws IOException {
    final Transport transport = transports.get(receiverUri.getScheme().toLowerCase());
    if (transport != null) {
        transport.send(receiverUri, message, tag);
    } else {/*w  w  w .j  a v a  2 s. c  o m*/
        throw new IOException("No transport known for scheme:" + receiverUri.getScheme());
    }
}

From source file:fi.mystes.synapse.mediator.ReadFileMediator.java

/**
 * Helper method to initialize file to read content from. Will try to get file name
 * first from fileName attribute. If it fails, it will try to read file name from property.
 * /*from  ww w .  j  a va 2  s .  c om*/
 * @param context Contains property which may hold XML file name.
 * 
 * @return Reference to file object
 * @throws URISyntaxException 
 * @throws SftpException 
 * @throws JSchException 
 * @throws FileNotFoundException 
 * @throws IOException 
 */
private InputStream initProcessableFile(MessageContext context)
        throws URISyntaxException, JSchException, SftpException, FileNotFoundException {
    InputStream fileToProcess = null;
    if (fileName != null) {
        URI aURI = new URI(fileName);

        if (aURI.getScheme().equals("file"))
            fileToProcess = new FileInputStream(new File(aURI));

        else if (aURI.getScheme().equals("ftp") || aURI.getScheme().equals("sftp"))
            fileToProcess = processFtpSftpInput(aURI);

        else
            throw new URISyntaxException(fileName, "Unknown protocol");

    } else if (property != null) {
        fileToProcess = new FileInputStream(new File((String) context.getProperty(property)));
    }
    return fileToProcess;
}