Example usage for java.net URI getHost

List of usage examples for java.net URI getHost

Introduction

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

Prototype

public String getHost() 

Source Link

Document

Returns the host component of this URI.

Usage

From source file:se.vgregion.urlservice.services.DefaultUrlServiceService.java

@Override
public UrlWithHash expandPath(URI url) {
    String domain = url.getHost();
    if (url.getPort() > 0) {
        domain += ":" + url.getPort();
    }//from w  w w. j a  v  a 2  s .c o  m

    return expandPath(url.getPath());
}

From source file:org.n52.sos.web.JdbcUrl.java

protected final void parse(String string) throws URISyntaxException {
    URI uri = new URI(string);
    scheme = uri.getScheme();// www.ja v  a 2 s  .  co m
    uri = new URI(uri.getSchemeSpecificPart());
    type = uri.getScheme();
    host = uri.getHost();
    port = uri.getPort();
    String[] path = uri.getPath().split(SLASH_STRING);
    if (path.length == 1 && !path[0].isEmpty()) {
        database = path[0];
    } else if (path.length == 2 && path[0].isEmpty() && !path[1].isEmpty()) {
        database = path[1];
    }
    for (NameValuePair nvp : URLEncodedUtils.parse(uri, "UTF-8")) {
        if (nvp.getName().equals(QUERY_PARAMETER_USER)) {
            user = nvp.getValue();
        } else if (nvp.getName().equals(QUERY_PARAMETER_PASSWORD)) {
            password = nvp.getValue();
        }
    }
}

From source file:org.obm.satellite.client.ConnectionImpl.java

private void post(String hostName, String host, String path) {
    try {// ww w .  ja va 2 s .  c  o m
        URI uri = new URIBuilder().setScheme(configuration.getSatelliteProtocol().getScheme()).setHost(host)
                .setPort(configuration.getSatellitePort()).setPath(String.format(path, hostName)).build();
        StatusLine statusLine = Executor.newInstance(client)
                .authPreemptive(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()))
                .auth(configuration.getUsername(), configuration.getPassword().getStringValue())
                .execute(Request.Post(uri)).returnResponse().getStatusLine();

        if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
            throw new SatteliteClientException(String.format("The MTA at %s returned %s", host, statusLine));
        }
    } catch (IOException e) {
        throw new ConnectionException(e);
    } catch (URISyntaxException e) {
        throw new SatteliteClientException(e);
    }
}

From source file:com.seajas.search.contender.service.modifier.AbstractModifierService.java

/**
 * Retrieve the FTP client belonging to the given URI.
 * /*from   w  w w . j ava2  s .c om*/
 * @param uri
 * @return FTPClient
 */
protected FTPClient retrieveFtpClient(final URI uri) {
    // Create the FTP client

    FTPClient ftpClient = uri.getScheme().equalsIgnoreCase("ftps") ? new FTPSClient() : new FTPClient();

    try {
        ftpClient.connect(uri.getHost(), uri.getPort() != -1 ? uri.getPort() : 21);

        if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
            ftpClient.disconnect();

            logger.error("Could not connect to the given FTP server " + uri.getHost()
                    + (uri.getPort() != -1 ? ":" + uri.getPort() : "") + " - " + ftpClient.getReplyString());

            return null;
        }

        if (StringUtils.hasText(uri.getUserInfo())) {
            if (uri.getUserInfo().contains(":"))
                ftpClient.login(uri.getUserInfo().substring(0, uri.getUserInfo().indexOf(":")),
                        uri.getUserInfo().substring(uri.getUserInfo().indexOf(":") + 1));
            else
                ftpClient.login(uri.getUserInfo(), "");
        }

        if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
            ftpClient.disconnect();

            logger.error("Could not login to the given FTP server " + uri.getHost()
                    + (uri.getPort() != -1 ? ":" + uri.getPort() : "") + " - " + ftpClient.getReplyString());

            return null;
        }

        // Switch to PASV and BINARY mode

        ftpClient.enterLocalPassiveMode();
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

        return ftpClient;
    } catch (IOException e) {
        logger.error("Could not close input stream during archive processing", e);
    }

    return null;
}

From source file:com.chigix.bio.proxy.buffer.FixedBufferTest.java

License:asdf

@Test
public void testURI() {
    try {//w  w  w .j  a  v  a  2s  .com
        URI uri = new URI(
                "http://www.baidu.com/awefawgwage/awefwfa/wefafwef/awdfa?safwefawf=awefaf&afwef=fafwef");
        System.out.println(uri.getScheme());
        System.out.println(uri.getHost());
        System.out.println(uri.getPort());
        System.out.println(uri.getQuery());
        System.out.println(uri.getPath());
    } catch (URISyntaxException ex) {
        Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    String illegalQuery = "http://sclick.baidu.com/w.gif?q=a&fm=se&T=1423492890&y=55DFFF7F&rsv_cache=0&rsv_pre=0&rsv_reh=109_130_149_109_85_195_85_85_85_85|540&rsv_scr=1899_1720_0_0_1080_1920&rsv_sid=10383_1469_12498_10902_11101_11399_11277_11241_11401_12550_11243_11403_12470&cid=0&qid=fd67eec000006821&t=1423492880700&rsv_iorr=1&rsv_tn=baidu&path=http%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26f%3D8%26rsv_bp%3D1%26rsv_idx%3D1%26ch%3D%26tn%3Dbaidu%26bar%3D%26wd%3Da%26rn%3D%26rsv_pq%3Dda7dc5fb00004904%26rsv_t%3D55188AMIFp8JX4Jb3hJkfCZHYxQdZOBK%252FhV0kLFfAPijGGrceXBoFpnHzmI%26rsv_enter%3D1%26inputT%3D111";
    URI uri;
    while (true) {
        try {
            uri = new URI(illegalQuery);
        } catch (URISyntaxException ex) {
            System.out.println(illegalQuery);
            System.out.println(illegalQuery.charAt(ex.getIndex()));
            System.out.println(illegalQuery.substring(0, ex.getIndex()));
            System.out.println(illegalQuery.substring(ex.getIndex() + 1));
            try {
                illegalQuery = illegalQuery.substring(0, ex.getIndex())
                        + URLEncoder.encode(String.valueOf(illegalQuery.charAt(ex.getIndex())), "utf-8")
                        + illegalQuery.substring(ex.getIndex() + 1);
            } catch (UnsupportedEncodingException ex1) {
            }
            System.out.println(illegalQuery);
            continue;
        }
        break;
    }
    System.out.println("SCHEME: " + uri.getScheme());
    System.out.println("HOST: " + uri.getHost());
    System.out.println("path: " + uri.getRawPath());
    System.out.println("query: " + uri.getRawQuery());
    System.out.println("PORT: " + uri.getPort());
}

From source file:org.cleverbus.core.common.ws.transport.http.CloseableHttpComponentsMessageSender.java

/**
 * Sets the maximum number of connections per host for the underlying HttpClient. The maximum number of connections
 * per host can be set in a form accepted by the {@code java.util.Properties} class, like as follows:
 * <p/>/*from w  w  w  . java 2 s . c  o m*/
 * <pre>
 * https://esb.cleverbus.org/esb/=1
 * http://esb.cleverbus.org:8080/esb/=7
 * http://esb.cleverbus.org/esb/=10
 * </pre>
 * <p/>
 * The host can be specified as a URI (with scheme and port).
 *
 * @param maxConnectionsPerHost a properties object specifying the maximum number of connection
 * @see PoolingHttpClientConnectionManager#setMaxPerRoute(org.apache.http.conn.routing.HttpRoute, int)
 */
@Override
public void setMaxConnectionsPerHost(Map<String, String> maxConnectionsPerHost) throws URISyntaxException {
    for (Map.Entry<String, String> entry : maxConnectionsPerHost.entrySet()) {
        URI uri = new URI(entry.getKey());
        HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
        HttpRoute route = new HttpRoute(host);

        PoolingHttpClientConnectionManager connectionManager = (PoolingHttpClientConnectionManager) getConnPoolControl();

        int max = Integer.parseInt(entry.getValue());
        connectionManager.setMaxPerRoute(route, max);
        BasicScheme basicAuth = new BasicScheme();
        authCache.get().put(host, basicAuth);
    }
}

From source file:com.mirth.connect.connectors.tcp.TcpMessageReceiver.java

protected ServerSocket createSocket(URI uri) throws IOException {
    String host = uri.getHost();
    int backlog = connector.getBacklog();
    if (host == null || host.length() == 0) {
        host = "localhost";
    }/* w  w w . ja  va  2s .  c om*/
    InetAddress inetAddress = InetAddress.getByName(host);
    if (inetAddress.equals(InetAddress.getLocalHost()) || inetAddress.isLoopbackAddress()
            || host.trim().equals("localhost")) {
        return new ServerSocket(uri.getPort(), backlog);
    } else {
        return new ServerSocket(uri.getPort(), backlog, inetAddress);
    }
}

From source file:com.mellanox.jxio.ServerPortal.java

/**
 * This method forwards the serverSession on the ServerPortal. This means that all ServerSession
 * events will arrive on this portal's EventQueueHandler.
 * /*from w  w  w . java  2s.  co m*/
 * @param portal
 *            - the portal to which the serverSession will be forwarded
 * @param serverSession
 *            - sesrverSession that will be forwarded
 */
public void forward(ServerPortal portal, ServerSession serverSession) {
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.toLogString() + "portal " + portal + " ses id is " + serverSession.getId());
    }
    if (portal == this) {// in case forward was called but the user really means accept
        accept(serverSession);
        return;
    }
    URI uriForForward = portal.getUri();
    if (uriForForward.getHost().equals("0.0.0.0")) {
        uriForForward = this.replaceIPinURI(uriForForward, serverSession.getUri());
    }

    serverSession.setEventQueueHandlers(this.eqh, portal.eqh);
    if (!Bridge.forwardSession(uriForForward.toString(), serverSession.getId(), portal.getId()))
        LOG.error("forward failed");
    portal.setSession(serverSession);
}

From source file:de.ii.xtraplatform.ogc.csw.client.CSWAdapter.java

private boolean isDefaultUrl(URI uri, CSW.METHOD method) {
    URI defaultURI = this.urls.get("default").get(method);
    URI inputURI = uri;//from   www. j  av a  2s  .co  m

    if (defaultURI.getHost().startsWith(inputURI.getHost())) {
        return true;
    }
    return false;
}

From source file:com.mirth.connect.connectors.dimse.DICOMMessageReceiver.java

@Override
public void doConnect() throws ConnectException {
    disposing.set(false);//w w w. j  a  v a 2  s. c o  m
    URI uri = endpoint.getEndpointURI().getUri();

    try {
        dcmrcv.setPort(uri.getPort());
        dcmrcv.setHostname(uri.getHost());
        dcmrcv.setAEtitle("DCMRCV");

        String[] only_def_ts = { UID.ImplicitVRLittleEndian };
        String[] native_le_ts = { UID.ImplicitVRLittleEndian };
        String[] native_ts = { UID.ImplicitVRLittleEndian };
        String[] non_retired_ts = { UID.ImplicitVRLittleEndian };

        if (StringUtils.isNotBlank(connector.getDest())) {
            dcmrcv.setDestination(connector.getDest());
        }

        if (connector.isDefts()) {
            dcmrcv.setTransferSyntax(only_def_ts);
        } else if (connector.isNativeData()) {
            if (connector.isBigendian()) {
                dcmrcv.setTransferSyntax(native_ts);
            } else {
                dcmrcv.setTransferSyntax(native_le_ts);
            }
        } else if (connector.isBigendian()) {
            dcmrcv.setTransferSyntax(non_retired_ts);
        }

        if (StringUtils.isNotBlank(connector.getApplicationEntity())) {
            dcmrcv.setAEtitle(connector.getApplicationEntity());
        }

        if (connector.getReaper() != 10) {
            dcmrcv.setAssociationReaperPeriod(connector.getReaper());
        }

        if (connector.getIdleto() != 60) {
            dcmrcv.setIdleTimeout(connector.getIdleto());
        }

        if (connector.getRequestto() != 5) {
            dcmrcv.setRequestTimeout(connector.getRequestto());
        }

        if (connector.getReleaseto() != 5) {
            dcmrcv.setReleaseTimeout(connector.getReleaseto());
        }

        if (connector.getSoclosedelay() != 50) {
            dcmrcv.setSocketCloseDelay(connector.getSoclosedelay());
        }

        if (connector.getRspdelay() > 0) {
            dcmrcv.setDimseRspDelay(connector.getRspdelay());
        }

        if (connector.getRcvpdulen() != 16) {
            dcmrcv.setMaxPDULengthReceive(connector.getRcvpdulen());
        }

        if (connector.getSndpdulen() != 16) {
            dcmrcv.setMaxPDULengthSend(connector.getSndpdulen());
        }

        if (connector.getSosndbuf() > 0) {
            dcmrcv.setSendBufferSize(connector.getSosndbuf());
        }

        if (connector.getSorcvbuf() > 0) {
            dcmrcv.setReceiveBufferSize(connector.getSorcvbuf());
        }

        if (connector.getBufsize() != 1) {
            dcmrcv.setFileBufferSize(connector.getBufsize());
        }

        dcmrcv.setPackPDV(connector.isPdv1());
        dcmrcv.setTcpNoDelay(!connector.isTcpdelay());

        if (connector.getAsync() > 0) {
            dcmrcv.setMaxOpsPerformed(connector.getAsync());
        }

        dcmrcv.initTransferCapability();

        // connection tls settings

        if (!StringUtils.equals(connector.getTls(), "notls")) {
            if (connector.getTls().equals("without")) {
                dcmrcv.setTlsWithoutEncyrption();
            } else if (connector.getTls().equals("3des")) {
                dcmrcv.setTls3DES_EDE_CBC();
            } else if (connector.getTls().equals("aes")) {
                dcmrcv.setTlsAES_128_CBC();
            }

            if (StringUtils.isNotBlank(connector.getTruststore())) {
                dcmrcv.setTrustStoreURL(connector.getTruststore());
            }

            if (StringUtils.isNotBlank(connector.getTruststorepw())) {
                dcmrcv.setTrustStorePassword(connector.getTruststorepw());
            }

            if (StringUtils.isNotBlank(connector.getKeypw())) {
                dcmrcv.setKeyPassword(connector.getKeypw());
            }

            if (StringUtils.isNotBlank(connector.getKeystore())) {
                dcmrcv.setKeyStoreURL(connector.getKeystore());
            }

            if (StringUtils.isNotBlank(connector.getKeystorepw())) {
                dcmrcv.setKeyStorePassword(connector.getKeystorepw());
            }

            dcmrcv.setTlsNeedClientAuth(connector.isNoclientauth());

            if (!connector.isNossl2()) {
                dcmrcv.setTlsProtocol(new String[] { "TLSv1", "SSLv3" });
            }

            dcmrcv.initTLS();
        }

        // start the DICOM port
        dcmrcv.start();

        monitoringController.updateStatus(this.connector, connectorType, Event.INITIALIZED);
    } catch (Exception e) {
        throw new ConnectException(new Message("DICOM", 1, uri), e, this);
    }
}