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.zaproxy.zap.extension.quickstart.AttackThread.java

private SiteNode accessNode(URL url) {
    SiteNode startNode = null;// w w  w. ja  v a 2 s. com
    // Request the URL
    try {
        final HttpMessage msg = new HttpMessage(new URI(url.toString(), true),
                extension.getModel().getOptionsParam().getConnectionParam());
        getHttpSender().sendAndReceive(msg, true);

        if (msg.getResponseHeader().getStatusCode() != HttpStatusCode.OK) {
            extension.notifyProgress(Progress.failed, Constant.messages
                    .getString("quickstart.progress.failed.code", msg.getResponseHeader().getStatusCode()));

            return null;
        }

        if (msg.getResponseHeader().isEmpty()) {
            extension.notifyProgress(Progress.failed);
            return null;
        }

        ExtensionHistory extHistory = ((ExtensionHistory) Control.getSingleton().getExtensionLoader()
                .getExtension(ExtensionHistory.NAME));
        extHistory.addHistory(msg, HistoryReference.TYPE_PROXIED);

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                // Needs to be done on the EDT
                Model.getSingleton().getSession().getSiteTree().addPath(msg.getHistoryRef());
            }
        });

        for (int i = 0; i < 10; i++) {
            startNode = Model.getSingleton().getSession().getSiteTree()
                    .findNode(new URI(url.toString(), false));
            if (startNode != null) {
                break;
            }
            try {
                sleep(200);
            } catch (InterruptedException e) {
                // Ignore
            }
        }
    } catch (UnknownHostException e1) {
        ConnectionParam connectionParam = Model.getSingleton().getOptionsParam().getConnectionParam();
        if (connectionParam.isUseProxyChain()
                && connectionParam.getProxyChainName().equalsIgnoreCase(e1.getMessage())) {
            extension.notifyProgress(Progress.failed, Constant.messages
                    .getString("quickstart.progress.failed.badhost.proxychain", e1.getMessage()));
        } else {
            extension.notifyProgress(Progress.failed,
                    Constant.messages.getString("quickstart.progress.failed.badhost", e1.getMessage()));
        }
    } catch (URIException e) {
        extension.notifyProgress(Progress.failed,
                Constant.messages.getString("quickstart.progress.failed.reason", e.getMessage()));
    } catch (Exception e1) {
        logger.error(e1.getMessage(), e1);
        extension.notifyProgress(Progress.failed,
                Constant.messages.getString("quickstart.progress.failed.reason", e1.getMessage()));
        return null;
    }
    return startNode;
}

From source file:org.spout.engine.SpoutServer.java

private PortMapping createPortMapping(int port, PortMapping.Protocol protocol, String description) {
    try {/*  w  ww.  j  ava 2  s  .c  o m*/
        return new PortMapping(port, InetAddress.getLocalHost().getHostAddress(), protocol, description);
    } catch (UnknownHostException e) {
        Error error = new Error(
                "Error while trying to retrieve the localhost while creating a PortMapping object.", e);
        getLogger().severe(e.getMessage());
        throw error;
    }
}

From source file:org.openadaptor.auxil.connector.socket.SocketWriteConnector.java

/**
 * If the {@link #setRemoteHostname remoteHostname} property is set then connects to remote host
 * and returns the OutputStream from that socket. Otherwise it creates a ServerSocket
 * and waits for a connection from a client, when this happens it returns the OutputStream
 * from that socket;/*from  w  w  w . j  a v a  2s. co m*/
        
 * @throws IOException if there was a comms error
 */
protected OutputStream getOutputStream() throws IOException {
    /* This effectively acts as the 'real' connect as the connection attempt occurs when the Socket or ServerSocket class gets instantiated
     * 
     */
    if (remoteHostname != null) {
        log.info(getId() + " connecting to " + remoteHostname + ":" + port);
        setInitiatedConnection(true);
        try {
            if (retryPeriod > 0) {
                repeatedAttempts();
            } else {
                socket = new Socket(remoteHostname, port);
            }
            configureSocket(socket);
            socketWriter = socket.getOutputStream();
            return socketWriter;
        } catch (UnknownHostException e) {
            throw new ConnectionException("UnknownHostExceptiont, " + remoteHostname + ", " + e.getMessage(), e,
                    this);
        }
    } else {
        log.info(getId() + " waiting for connection...");
        setInitiatedConnection(false);
        ServerSocket serverSocket = new ServerSocket(port);
        socket = serverSocket.accept();
        // check hostname if we only allow connections from specific hosts
        String client_host = socket.getInetAddress().getHostName();
        if (restrictedHost != null && !restrictedHost.equals(client_host)) {
            throw new ConnectionException(
                    "This component is not configured to accept connections from [" + client_host + "]", this);
        }
        log.info(getId() + " accepted connection from " + socket.getInetAddress().getHostAddress() + ":"
                + socket.getPort());
        configureSocket(socket);
        socketWriter = socket.getOutputStream();
        return socketWriter;
    }
}

From source file:cn.edu.zzu.wemall.http.AsyncHttpRequest.java

private void makeRequestWithRetries() throws IOException {
    boolean retry = true;
    IOException cause = null;/*  w w w.j  a va2 s  .co  m*/
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    try {
        while (retry) {
            try {
                makeRequest();
                return;
            } catch (UnknownHostException e) {
                // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
                // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
                // (to assist in genuine cases of unknown host) which seems better than outright failure
                cause = new IOException("UnknownHostException exception: " + e.getMessage());
                retry = (executionCount > 0) && retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (NullPointerException e) {
                // there's a bug in HttpClient 4.0.x that on some occasions causes
                // DefaultRequestExecutor to throw an NPE, see
                // http://code.google.com/p/android/issues/detail?id=5255
                cause = new IOException("NPE in HttpClient: " + e.getMessage());
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (IOException e) {
                cause = e;
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            }
            if (retry && (responseHandler != null)) {
                responseHandler.sendRetryMessage();
            }
        }
    } catch (Exception e) {
        // catch anything else to ensure failure message is propagated
        cause = new IOException("Unhandled exception: " + e.getMessage());
    }

    // cleaned up to throw IOException
    throw (cause);
}

From source file:org.squidy.nodes.tracking.CameraConfigComm.java

public void sendMultipleParameters(String name, String type, String[] values, int numParams) {
    if (!initDone) {
        try {/*from  www  .ja  va2s  .c om*/
            initConnection();
        } catch (UnknownHostException e1) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e1.getMessage(), e1);
            }
            System.out.println("Could not connect to Camera on " + addressOutgoing + " : " + portOutgoing);
            return;
        }
    }
    OSCBundle bundle = new OSCBundle();
    OSCMessage param = new OSCMessage("/config/param");
    param.addArgument(id);
    param.addArgument(numParams);
    param.addArgument("set");
    for (int i = 0; i < numParams; i++) {
        param.addArgument(name);
        param.addArgument(type);
        param.addArgument(values[i]);
    }
    bundle.addPacket(param);
    //   int len = bundle.getByteArray().length;

    try {
        oscPortOut.send(bundle);
    } catch (IOException e) {
        throw new ProcessException(e.getMessage(), e);
    }

}

From source file:net.java.sip.communicator.impl.protocol.sip.xcap.BaseHttpXCapClient.java

/**
 * Gets resource from the server./*from  w  w w  .  j  a  v a 2 s .c om*/
 *
 * @param uri the resource uri.
 * @return the server response.
 * @throws XCapException if there is error during reading the resource's
 *                       content.
 */
protected XCapHttpResponse get(URI uri) throws XCapException {
    DefaultHttpClient httpClient = null;
    try {
        httpClient = createHttpClient();

        HttpGet getMethod = new HttpGet(uri);
        getMethod.setHeader("Connection", "close");

        HttpResponse response = httpClient.execute(getMethod);
        XCapHttpResponse result = createResponse(response);
        if (logger.isDebugEnabled()) {
            byte[] contentBytes = result.getContent();
            String contenString;
            // for debug purposes print only xmls
            // skip the icon queries
            if (contentBytes != null && result.getContentType() != null
                    && !result.getContentType().startsWith(PresContentClient.CONTENT_TYPE))
                contenString = new String(contentBytes);
            else
                contenString = "";

            String logMessage = String.format("Getting resource %1s from the server content:%2s",
                    uri.toString(), contenString);
            logger.debug(logMessage);
        }
        return result;
    } catch (UnknownHostException uhe) {
        showError(uhe, null, null);
        disconnect();
        throw new XCapException(uhe.getMessage(), uhe);
    } catch (IOException e) {
        String errorMessage = SipActivator.getResources().getI18NString(
                "impl.protocol.sip.XCAP_ERROR_RESOURCE_ERR",
                new String[] { uri.toString(), userAddress.getDisplayName() });
        showError(e, null, errorMessage);
        throw new XCapException(errorMessage, e);
    } finally {
        if (httpClient != null)
            httpClient.getConnectionManager().shutdown();
    }
}

From source file:cn.com.dfc.pl.afinal.http.SyncRequestHandler.java

private Object makeRequestWithRetries(HttpUriRequest request) throws IOException {

    boolean retry = true;
    IOException cause = null;//from   w  w w. j a v  a2  s  .  c om
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            HttpResponse response = client.execute(request, context);
            return entityHandler.handleEntity(response.getEntity(), null, charset);
        } catch (UnknownHostException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // HttpClient 4.0.x ?bug
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (Exception e) {
            cause = new IOException("Exception" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }
    if (cause != null)
        throw cause;
    else
        throw new IOException("");

}

From source file:com.aoeng.degu.utils.net.asyncthhpclient.AsyncHttpRequest.java

private void makeRequestWithRetries() throws IOException {
    boolean retry = true;
    IOException cause = null;//from w  w w.  j  av  a2s .  c o m
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    try {
        while (retry) {
            try {
                makeRequest();
                return;
            } catch (UnknownHostException e) {
                // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
                // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
                // (to assist in genuine cases of unknown host) which seems better than outright failure
                cause = new IOException("UnknownHostException exception: " + e.getMessage());
                retry = (executionCount > 0) && retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (NullPointerException e) {
                // there's a bug in HttpClient 4.0.x that on some occasions causes
                // DefaultRequestExecutor to throw an NPE, see
                // http://code.google.com/p/android/issues/detail?id=5255
                cause = new IOException("NPE in HttpClient: " + e.getMessage());
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (IOException e) {
                cause = e;
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            }
            if (retry && (responseHandler != null)) {
                responseHandler.sendRetryMessage(executionCount);
            }
        }
    } catch (Exception e) {
        // catch anything else to ensure failure message is propagated
        Log.e("AsyncHttpRequest", "Unhandled exception origin cause", e);
        cause = new IOException("Unhandled exception: " + e.getMessage());
    }

    // cleaned up to throw IOException
    throw (cause);
}

From source file:com.sf.httpclient.newcore.BaseHttpClientManager.java

private T makeRequestWithRetries(HttpUriRequest request) throws IOException {

    boolean retry = true;
    IOException cause = null;//  w w w . j a  v a  2 s  .c  o m
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            HttpResponse response = client.execute(request, context);
            return handleEntity(response.getEntity(), mEntityCallBack);
        } catch (UnknownHostException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // HttpClient 4.0.x ?bug
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (Exception e) {
            cause = new IOException("Exception" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }
    if (cause != null)
        throw cause;
    else
        throw new IOException("");
}

From source file:org.fcrepo.utilities.install.FedoraHome.java

private String getHost() throws InstallationFailedException {
    if (_host == null) {
        String host = _opts.getValue(InstallOptions.FEDORA_SERVERHOST);
        try {/*w  w  w. j  a v a2  s  .  co  m*/
            _host = InetAddress.getByName(host);
        } catch (UnknownHostException e) {
            throw new InstallationFailedException(e.getMessage(), e);
        }
    }
    return _host.getHostAddress();
}