Example usage for java.net UnknownHostException getMessage

List of usage examples for java.net UnknownHostException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.eclipse.californium.proxy.HttpTranslator.java

public static Request createCoapRequestOptions(String proxyUri) throws TranslationException {
    // create the request -- since HTTP is reliable use CON
    Request coapRequest = new Request(Code.valueOf(1), Type.CON);

    if (proxyUri.contains("?")) {
        int index = proxyUri.indexOf("?");
        String uri = proxyUri.substring(0, index);
        coapRequest.getOptions().setProxyUri(uri + "?ldp=options");
    } else {/* w  w w.j av  a  2  s  .  com*/
        coapRequest.getOptions().setProxyUri(proxyUri + "?ldp=options");
    }

    // set the proxy as the sender to receive the response correctly
    try {
        // TODO check with multihomed hosts
        InetAddress localHostAddress = InetAddress.getLocalHost();
        coapRequest.setDestination(localHostAddress);
        // TODO: setDestinationPort???
    } catch (UnknownHostException e) {
        LOGGER.warning("Cannot get the localhost address: " + e.getMessage());
        throw new TranslationException("Cannot get the localhost address: " + e.getMessage());
    }

    return coapRequest;
}

From source file:org.parosproxy.paros.extension.manualrequest.http.impl.HttpPanelSender.java

@Override
public void handleSendMessage(Message aMessage) throws IllegalArgumentException, IOException {
    final HttpMessage httpMessage = (HttpMessage) aMessage;
    try {/*from ww  w .ja  v a2 s.c  o m*/
        final ModeRedirectionValidator redirectionValidator = new ModeRedirectionValidator();
        boolean followRedirects = getButtonFollowRedirects().isSelected();
        if (followRedirects) {
            getDelegate().sendAndReceive(httpMessage,
                    HttpRequestConfig.builder().setRedirectionValidator(redirectionValidator).build());
        } else {
            getDelegate().sendAndReceive(httpMessage, false);
        }

        EventQueue.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                if (!httpMessage.getResponseHeader().isEmpty()) {
                    // Indicate UI new response arrived
                    responsePanel.updateContent();

                    if (!followRedirects) {
                        persistAndShowMessage(httpMessage);
                    } else if (!redirectionValidator.isRequestValid()) {
                        View.getSingleton().showWarningDialog(
                                Constant.messages.getString("manReq.outofscope.redirection.warning",
                                        redirectionValidator.getInvalidRedirection()));
                    }
                }
            }
        });

        ZapGetMethod method = (ZapGetMethod) httpMessage.getUserObject();
        notifyPersistentConnectionListener(httpMessage, null, method);

    } catch (final HttpMalformedHeaderException mhe) {
        throw new IllegalArgumentException("Malformed header error.", mhe);

    } catch (final UnknownHostException uhe) {
        throw new IOException("Error forwarding to an Unknown host: " + uhe.getMessage(), uhe);

    } catch (final SSLException sslEx) {
        throw sslEx;
    } catch (final IOException ioe) {
        throw new IOException("IO error in sending request: " + ioe.getClass() + ": " + ioe.getMessage(), ioe);

    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:ch.cyberduck.core.SystemConfigurationProxy.java

/**
 * @param hostname Hostname or CIDR notation
 * @return True if host is excluded in native proxy configuration
 *//*from   w  w  w .  ja va 2  s. co  m*/
private boolean isHostExcluded(String hostname) {
    if (!hostname.contains(".")) {
        // Non fully qualified hostname
        if (this.isSimpleHostnameExcludedNative()) {
            return true;
        }
    }
    for (String exception : this.getProxyExceptionsNative()) {
        if (StringUtils.isBlank(exception)) {
            continue;
        }
        if (this.matches(exception, hostname)) {
            return true;
        }
        try {
            SubnetUtils subnet = new SubnetUtils(exception);
            try {
                String ip = Inet4Address.getByName(hostname).getHostAddress();
                if (subnet.getInfo().isInRange(ip)) {
                    return true;
                }
            } catch (UnknownHostException e) {
                // Should not happen as we resolve addresses before attempting to connect
                // in ch.cyberduck.core.Resolver
                log.warn(e.getMessage());
            }
        } catch (IllegalArgumentException e) {
            // A hostname pattern but not CIDR. Does not
            // match n.n.n.n/m where n=1-3 decimal digits, m = 1-3 decimal digits in range 1-32
            log.debug("Invalid CIDR notation:" + e.getMessage());
        }
    }
    return false;
}

From source file:org.eclipse.californium.proxy.HttpTranslator.java

public static Request createCoapRequestDiscovery(String proxyUri) throws TranslationException {
    // create the request -- since HTTP is reliable use CON
    Request coapRequest = new Request(Code.valueOf(1), Type.CON);

    String uri = "";
    if (proxyUri.contains("?")) {
        int index = proxyUri.indexOf("?");
        uri = proxyUri.substring(0, index);
    } else {//w  ww .j  a v a2  s. c  om
        uri = proxyUri;
    }

    String uriNoSchema = uri.substring(7);
    int index = uriNoSchema.indexOf('/', 0);
    String host = uriNoSchema.substring(0, index);
    String resource = uriNoSchema.substring(index + 1);

    StringTokenizer tokenizer = new StringTokenizer(resource, "/");
    String resources = "";

    while (tokenizer.hasMoreElements()) {
        resources = (String) tokenizer.nextElement();
    }

    coapRequest.getOptions().setProxyUri("coap://" + host + "/.well-known/core?title=" + resources);

    // set the proxy as the sender to receive the response correctly
    try {
        // TODO check with multihomed hosts
        InetAddress localHostAddress = InetAddress.getLocalHost();
        coapRequest.setDestination(localHostAddress);
        // TODO: setDestinationPort???
    } catch (UnknownHostException e) {
        LOGGER.warning("Cannot get the localhost address: " + e.getMessage());
        throw new TranslationException("Cannot get the localhost address: " + e.getMessage());
    }

    return coapRequest;
}

From source file:org.pouzinsociety.actions.ping.PingCommand.java

public void execute() throws SocketException, InterruptedException {
    int i = 0;/*from w  w w  .j  av  a2s  .  c  o m*/
    while (stackConfiguration.Complete() == false && i < 100) {
        Thread.sleep(1000);
        i++;
        log.info("Waiting for completion");
    }
    StringBuffer cmdOutput = new StringBuffer();
    StringBuffer tmp = new StringBuffer();
    String hostname = "10.0.0.1";
    try {
        this.dst = new IPv4Address(InetAddress.getByName(hostname));
    } catch (UnknownHostException ex) {
        cmdOutput.append("Error: Unknown host: " + ex.getMessage() + "\n");
        log.error(cmdOutput.toString());
        return;
    }

    cmdOutput.append("\nping " + hostname + "\nOutput:\n");

    final IPv4Header netHeader = new IPv4Header(0, this.ttl, IPv4Constants.IPPROTO_ICMP, this.dst, 8);
    netHeader.setDontFragment(this.dontFragment);

    rt = ipv4Service.getRoutingTable();
    log.info("Routing Table:\n" + rt.toString());

    final ICMPProtocol icmpProtocol = (ICMPProtocol) ipv4NetworkLayer
            .getTransportLayer(ICMPProtocol.IPPROTO_ICMP);

    icmpProtocol.addListener(this);
    try {
        int id_count = 0;
        int seq_count = 0;
        while (this.count != 0) {
            tmp.append("Ping " + dst + " attempt " + seq_count + "\n");
            cmdOutput.append(tmp);
            log.info(tmp.toString());
            tmp.setLength(0);

            if (!this.flood) {
                this.wait = true;
            }

            SocketBuffer packet = new SocketBuffer();
            packet.insert(this.size);
            ICMPEchoHeader transportHeader = new ICMPEchoHeader(8, id_count, seq_count);
            transportHeader.prefixTo(packet);

            Request r = new Request(this.stat, this.timeout, System.currentTimeMillis(), id_count, seq_count);
            registerRequest(r);
            ipv4Service.transmit(netHeader, packet);

            while (this.wait) {
                long time = System.currentTimeMillis() - r.getTimestamp();
                if (time > this.interval) {
                    this.wait = false;
                }
                Thread.sleep(500);
                synchronized (this) {
                    if (response) {
                        tmp.append("Reply from " + dst.toString() + ": " + (hdr1.getDataLength() - 8)
                                + "bytes of data " + "ttl=" + hdr1.getTtl() + " " + "seq=" + hdr2.getSeqNumber()
                                + " " + "time=" + (roundt) + "ms\n");
                        log.info(tmp.toString());
                        cmdOutput.append(tmp.toString());
                        tmp.setLength(0);
                        response = false;
                    }
                }
            }
            this.count--;
            seq_count++;
        }

        while (!isEmpty()) {
            Thread.sleep(100);
        }
    } finally {
        icmpProtocol.removeListener(this);
    }

    tmp.append("-> Packet statistics\n" + this.stat.getStatistics() + "\n");
    log.info(tmp.toString());
    cmdOutput.append(tmp);
    tmp.setLength(0);
    log.info(cmdOutput.toString());

}

From source file:org.zaproxy.zap.extension.websocket.client.ServerConnectionEstablisher.java

/**
 * Sends and receives the handshake and sets up a new WebSocket channel with method {@link
 * ServerConnectionEstablisher#setUpChannel}
 *
 * @param handshakeConfig Wrap the Http Handshake and the other available options
 * @return Either a new WebSocketProxy which is acts as a client or null if something went wrong
 *//*from www . ja v  a2 s .  c  o m*/
private WebSocketProxy handleSendMessage(HandshakeConfig handshakeConfig)
        throws RequestOutOfScopeException, IOException {

    // Reset the user before sending (e.g. Forced User mode sets the user, if needed).
    handshakeConfig.getHttpMessage().setRequestingUser(null);
    WebSocketProxy webSocketProxy;

    try {
        final ModeRedirectionValidator redirectionValidator = new ModeRedirectionValidator();
        if (handshakeConfig.isFollowRedirects()) {
            getDelegate(handshakeConfig).sendAndReceive(handshakeConfig.getHttpMessage(),
                    HttpRequestConfig.builder().setRedirectionValidator(redirectionValidator).build());
        } else {
            getDelegate(handshakeConfig).sendAndReceive(handshakeConfig.getHttpMessage(), false);
        }
        if (!handshakeConfig.getHttpMessage().getResponseHeader().isEmpty()) {
            if (!redirectionValidator.isRequestValid()) {
                throw new RequestOutOfScopeException(
                        Constant.messages.getString("manReq.outofscope.redirection.warning"),
                        redirectionValidator.getInvalidRedirection());
            }
        }
    } catch (final HttpMalformedHeaderException mhe) {
        throw new IllegalArgumentException("Malformed header error.", mhe);
    } catch (final UnknownHostException uhe) {
        throw new IOException("Error forwarding to an Unknown host: " + uhe.getMessage(), uhe);
    } catch (final SSLException sslEx) {
        throw sslEx;
    } catch (final IOException ioe) {
        throw new IOException("IO error in sending request: " + ioe.getClass() + ": " + ioe.getMessage(), ioe);
    }

    ZapGetMethod method = (ZapGetMethod) handshakeConfig.getHttpMessage().getUserObject();
    webSocketProxy = setUpChannel(handshakeConfig, method);

    return webSocketProxy;
}

From source file:org.docx4j.services.client.ConverterHttp.java

/**
 * @param httpclient//w  w w  .j a  v a 2  s .c o  m
 * @param httppost
 * @param os
 * @throws IOException
 * @throws ClientProtocolException
 * @throws ConversionException 
 */
protected void execute(CloseableHttpClient httpclient, HttpPost httppost, OutputStream os)
        throws ClientProtocolException, ConversionException {

    CloseableHttpResponse response = null;
    try {

        response = httpclient.execute(httppost);

        //System.out.println(""+response.getStatusLine());
        HttpEntity resEntity = response.getEntity();
        resEntity.writeTo(os);
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new ConversionException(response);
        }
    } catch (java.net.UnknownHostException uhe) {
        System.err.println("\nLooks like you have the wrong host in your endpoint URL '" + URL + "'\n");
        throw new ConversionException(uhe.getMessage(), uhe);

    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new ConversionException(ioe.getMessage(), ioe);
    } finally {
        try {
            if (response == null) {
                System.err.println("\nLooks like your endpoint URL '" + URL + "' is wrong\n");
            } else {
                response.close();
            }
        } catch (IOException e) {
        }
    }
}

From source file:org.manalith.ircbot.plugin.ping.PingPlugin.java

@BotCommand("")
public String ping(@Option(name = "?", help = "?  ?? ? IP ") String uri) {
    InetAddress addr;//from   ww w .  j  a  v  a  2  s  .  co  m

    try {
        addr = InetAddress.getByName(uri);
    } catch (UnknownHostException e) {
        return "[Ping]   .";
    }

    try {
        return String.format("[Ping] %s(%s) is %s: ", addr.getHostName(), addr.getHostAddress(),
                addr.isReachable(3000) ? "reachable" : "not reachable");
    } catch (IOException e) {
        return String.format("[Ping] ?  ?.(%s)", e.getMessage());
    }
}

From source file:leap.webunit.client.THttpClientImpl.java

@Override
public THttpClient addHostName(String hostName) {
    try {//from  w w w  .j  a  va 2s .  c  om
        dnsResolver.add(hostName, InetAddress.getLocalHost());
    } catch (UnknownHostException e) {
        throw new IllegalStateException("Cannot add host name '" + hostName + "', " + e.getMessage(), e);
    }
    return this;
}