List of usage examples for java.net SocketException toString
public String toString()
From source file:me.schiz.jmeter.protocol.smtp.sampler.SMTPSampler.java
private SampleResult sampleConnect(SampleResult sr) { SMTPClient client;//from ww w . ja v a 2 s. c o m if (getUseSSL()) { client = new SMTPSClient(true); } else if (getUseSTARTTLS()) { client = new SMTPSClient(false); } else { client = new SMTPClient(); } try { String request = "CONNECT \n"; request += "Host : " + getHostname() + ":" + getPort() + "\n"; request += "Default Timeout : " + getDefaultTimeout() + "\n"; request += "Connect Timeout : " + getConnectionTimeout() + "\n"; request += "So Timeout : " + getSoTimeout() + "\n"; request += "Client : " + getClient() + "\n"; if (getUseSSL()) request += "SSL : true\n"; else request += "SSL : false\n"; if (getUseSTARTTLS()) request += "STARTTLS : true\n"; else request += "STARTTLS : false\n"; sr.setRequestHeaders(request); sr.sampleStart(); client.setDefaultTimeout(getDefaultTimeout()); client.setConnectTimeout(getConnectionTimeout()); client.connect(getHostname(), getPort()); if (client.isConnected()) { SessionStorage.proto_type protoType = SessionStorage.proto_type.PLAIN; if (getUseSSL() && !getUseSTARTTLS()) protoType = SessionStorage.proto_type.SSL; if (!getUseSSL() && getUseSTARTTLS()) protoType = SessionStorage.proto_type.STARTTLS; SessionStorage.getInstance().putClient(getSOClient(), client, protoType); client.setSoTimeout(getSoTimeout()); client.setTcpNoDelay(getTcpNoDelay()); sr.setResponseCode(String.valueOf(client.getReplyCode())); sr.setResponseData(client.getReplyString().getBytes()); setSuccessfulByResponseCode(sr, client.getReplyCode()); } } catch (SocketException se) { sr.setResponseMessage(se.toString()); sr.setSuccessful(false); sr.setResponseCode(se.getClass().getName()); log.error("client `" + client + "` ", se); } catch (IOException ioe) { sr.setResponseMessage(ioe.toString()); sr.setSuccessful(false); sr.setResponseCode(ioe.getClass().getName()); log.error("client `" + client + "` ", ioe); } sr.sampleEnd(); return sr; }
From source file:com.terminal.ide.TermService.java
public String getLocalIpAddress() { String addr = null;//from w ww.j a v a 2s.co m try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); String ip = inetAddress.getHostAddress().toString(); if (!inetAddress.isLoopbackAddress()) { if (addr == null || ip.length() < addr.length()) { addr = ip; } } } } } catch (SocketException ex) { Log.e("SpartacusRex GET LOCAL IP : ", ex.toString()); } if (addr != null) { return addr; } return "127.0.0.1"; }
From source file:com.shreymalhotra.crazyflieserver.MainActivity.java
public String getLocalIpAddress() { try {/* w w w.j a va2 s . c om*/ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); // if (!inetAddress.isLoopbackAddress() && // !inetAddress.isLinkLocalAddress() && // inetAddress.isSiteLocalAddress() ) { if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) { String ipAddr = inetAddress.getHostAddress(); return ipAddr; } } } } catch (SocketException ex) { Log.d("CrazyFlieServer", ex.toString()); } return null; }
From source file:autobahn.WebSocketWriter.java
/** * Process message received from foreground thread. This is called from * the message looper set up for the background thread running this writer. * * @param msg Message from thread message queue. */// ww w .j a va 2 s.c om @Override public void handleMessage(Message msg) { try { // clear send buffer mBuffer.clear(); // process message from master processMessage(msg.obj); // send out buffered data mBuffer.flip(); while (mBuffer.remaining() > 0) { // this can block on socket write @SuppressWarnings("unused") int written = mSocket.write(mBuffer.getBuffer()); } } catch (SocketException e) { if (DEBUG) Log.d(TAG, "run() : SocketException (" + e.toString() + ")"); // wrap the exception and notify master notify(new WebSocketMessage.ConnectionLost()); } catch (Exception e) { if (DEBUG) e.printStackTrace(); // wrap the exception and notify master notify(new WebSocketMessage.Error(e)); } }
From source file:de.tavendo.autobahn.WebSocketWriter.java
/** * Process message received from foreground thread. This is called from * the message looper set up for the background thread running this writer. * * @param msg Message from thread message queue. */// w w w . ja v a 2 s .c om @Override public void handleMessage(Message msg) { try { // clear send buffer mBuffer.clear(); // process message from master processMessage(msg.obj); // send out buffered data if (null != mSSLEngine) { write(mSocket, mSSLEngine, mBuffer.getBuffer()); } else { mBuffer.flip(); while (mBuffer.remaining() > 0) { // this can block on socket write @SuppressWarnings("unused") int written = mSocket.write(mBuffer.getBuffer()); } } } catch (SocketException e) { if (DEBUG) Log.d(TAG, "run() : SocketException (" + e.toString() + ")"); // wrap the exception and notify master notify(new WebSocketMessage.ConnectionLost()); } catch (Exception e) { if (DEBUG) e.printStackTrace(); // wrap the exception and notify master notify(new WebSocketMessage.Error(e)); } }
From source file:me.schiz.jmeter.protocol.imap.sampler.IMAPSampler.java
private SampleResult sampleConnect(SampleResult sr) { IMAPClient client;//from w w w .j av a 2s. co m if (getUseSSL()) { client = new IMAPSClient(true); } else { client = new IMAPClient(); } try { String request = "CONNECT \n"; request += "Host : " + getHostname() + ":" + getPort() + "\n"; request += "Default Timeout : " + getDefaultTimeout() + "\n"; request += "Connect Timeout : " + getConnectionTimeout() + "\n"; request += "So Timeout : " + getSoTimeout() + "\n"; request += "Client : " + getClient() + "\n"; sr.setRequestHeaders(request); sr.sampleStart(); client.setDefaultTimeout(getDefaultTimeout()); client.setConnectTimeout(getConnectionTimeout()); if (getLocalAddr().isEmpty()) client.connect(getHostname(), getPort()); else client.connect(getHostname(), getPort(), InetAddress.getByName(getLocalAddr()), 0); if (client.isConnected()) { log.info("imap client " + getClient() + " connected from " + client.getLocalAddress() + ":" + client.getLocalPort()); SessionStorage.proto_type protoType = SessionStorage.proto_type.PLAIN; if (getUseSSL()) protoType = SessionStorage.proto_type.SSL; SessionStorage.getInstance().putClient(getSOClient(), client, protoType); client.setSoTimeout(getSoTimeout()); sr.setSuccessful(true); sr.setResponseCodeOK(); sr.setResponseData(client.getReplyString().getBytes()); } else { client.close(); sr.setSuccessful(false); sr.setResponseCode("java.net.ConnectException"); sr.setResponseMessage("Not connected"); } } catch (SocketException se) { sr.setResponseMessage(se.toString()); sr.setSuccessful(false); sr.setResponseCode(se.getClass().getName()); log.error("client `" + getClient() + "` ", se); removeClient(); } catch (IOException ioe) { sr.setResponseMessage(ioe.toString()); sr.setSuccessful(false); sr.setResponseCode(ioe.getClass().getName()); log.error("client `" + getClient() + "` ", ioe); removeClient(); } finally { sr.sampleEnd(); } return sr; }
From source file:com.intuit.tank.httpclient5.TankHttpClient5.java
private void sendRequest(BaseRequest request, @Nonnull ClassicHttpRequest method, String requestBody) { String uri = null;/*from w w w. j av a2 s . c o m*/ long waitTime = 0L; CloseableHttpResponse response = null; try { uri = method.getRequestUri(); LOG.debug(request.getLogUtil().getLogMessage( "About to " + method.getMethod() + " request to " + uri + " with requestBody " + requestBody, LogEventType.Informational)); List<String> cookies = new ArrayList<String>(); if (context.getCookieStore().getCookies() != null) { for (Cookie cookie : context.getCookieStore().getCookies()) { cookies.add("REQUEST COOKIE: " + cookie.toString()); } } request.logRequest(uri, requestBody, method.getMethod(), request.getHeaderInformation(), cookies, false); setHeaders(request, method, request.getHeaderInformation()); long startTime = System.currentTimeMillis(); request.setTimestamp(new Date(startTime)); response = httpclient.execute(method, context); // read response body byte[] responseBody = new byte[0]; // check for no content headers if (response.getCode() != 203 && response.getCode() != 202 && response.getCode() != 204) { try { responseBody = IOUtils.toByteArray(response.getEntity().getContent()); } catch (Exception e) { LOG.warn("could not get response body: " + e); } } waitTime = System.currentTimeMillis() - startTime; processResponse(responseBody, waitTime, request, response.getReasonPhrase(), response.getCode(), response.getAllHeaders()); } catch (UnknownHostException uhex) { LOG.error(request.getLogUtil().getLogMessage( "UnknownHostException to url: " + uri + " | error: " + uhex.toString(), LogEventType.IO), uhex); } catch (SocketException sex) { LOG.error( request.getLogUtil().getLogMessage( "SocketException to url: " + uri + " | error: " + sex.toString(), LogEventType.IO), sex); } catch (Exception ex) { LOG.error(request.getLogUtil().getLogMessage( "Could not do " + method.getMethod() + " to url " + uri + " | error: " + ex.toString(), LogEventType.IO), ex); throw new RuntimeException(ex); } finally { try { if (response != null) { response.close(); } } catch (Exception e) { LOG.warn("Could not release connection: " + e, e); } if (method.getMethod().equalsIgnoreCase("post") && request.getLogUtil().getAgentConfig().getLogPostResponse()) { LOG.info(request.getLogUtil() .getLogMessage("Response from POST to " + request.getRequestUrl() + " got status code " + request.getResponse().getHttpCode() + " BODY { " + request.getResponse().getBody() + " }", LogEventType.Informational)); } } if (waitTime != 0) { doWaitDueToLongResponse(request, waitTime, uri); } }
From source file:org.apache.jmeter.protocol.tcp.sampler.TCPSampler.java
private Socket getSocket(String socketKey) { Map<String, Object> cp = tp.get(); Socket con = null;//w w w .j a v a2 s . c o m if (isReUseConnection()) { con = (Socket) cp.get(socketKey); if (con != null) { log.debug(this + " Reusing connection " + con); //$NON-NLS-1$ } } if (con == null) { // Not in cache, so create new one and cache it try { closeSocket(socketKey); // Bug 44910 - close previous socket (if any) SocketAddress sockaddr = new InetSocketAddress(getServer(), getPort()); con = new Socket(); if (getPropertyAsString(SO_LINGER, "").length() > 0) { con.setSoLinger(true, getSoLinger()); } con.connect(sockaddr, getConnectTimeout()); if (log.isDebugEnabled()) { log.debug("Created new connection " + con); //$NON-NLS-1$ } cp.put(socketKey, con); } catch (UnknownHostException e) { log.warn("Unknown host for " + getLabel(), e);//$NON-NLS-1$ cp.put(ERRKEY, e.toString()); return null; } catch (IOException e) { log.warn("Could not create socket for " + getLabel(), e); //$NON-NLS-1$ cp.put(ERRKEY, e.toString()); return null; } } // (re-)Define connection params - Bug 50977 try { con.setSoTimeout(getTimeout()); con.setTcpNoDelay(getNoDelay()); if (log.isDebugEnabled()) { log.debug(this + " Timeout " + getTimeout() + " NoDelay " + getNoDelay()); //$NON-NLS-1$ } } catch (SocketException se) { log.warn("Could not set timeout or nodelay for " + getLabel(), se); //$NON-NLS-1$ cp.put(ERRKEY, se.toString()); } return con; }
From source file:tor.Consensus.java
private InputStream connectToDirectory(String address, String port, String path) throws IOException { URL url = new URL("http://" + address + ":" + port + path); // try the compressed version first, and transparently inflate it if (!path.endsWith(".z")) { try {/*from ww w. j ava2s . co m*/ URL zurl = new URL("http://" + address + ":" + port + path + ".z"); log.debug("Downloading (from directory server): " + zurl.toString()); return new InflaterInputStream(zurl.openStream()); } catch (SocketException e) { log.warn("Failed to connect: " + e); throw e; } catch (IOException e) { log.warn("Transparent download of compressed stream failed, falling back to uncompressed." + " Exception: " + e.toString()); } } log.debug("Downloading: " + url.toString()); InputStream in = url.openStream(); if (path.endsWith(".z")) return new InflaterInputStream(in); return in; }
From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java
public String getLocalIpAddress() { try {/*from w ww .java2 s . c o m*/ InetAddress inetAddress = getLocalInetAddress(); if (inetAddress != null) return inetAddress.getHostAddress().toString(); } catch (SocketException ex) { Toast.makeText(getApplication().getApplicationContext(), ex.toString(), Toast.LENGTH_LONG).show(); } return null; }