List of usage examples for java.net ConnectException getMessage
public String getMessage()
From source file:org.squidy.nodes.laserpointer.configclient.service.comm.TcpIpCommService.java
@Override protected void startupImpl() throws CommException { Object property = pService.getProperties().getProperty(JavaPropService.DEBUG_COMM); if (property != null) { debug = Boolean.parseBoolean((String) property); }//from w ww . ja va 2s . c om if (debug) initDebugOutput(); // init connection LOG.info("Creating connection: " + address); try { server = new Socket(address.getAddress(), address.getPort()); LOG.info("Connection accepted"); newConnection(server.getInputStream(), server.getOutputStream()); } catch (ConnectException e) { String msg = "Connection to " + address + " refused."; LOG.error(msg); throw new CommException(msg); } catch (UnknownHostException e) { String msg = "Unknown host: " + address; LOG.error(msg); throw new CommException(msg); } catch (IOException e) { String msg = "Cannot read from: " + address; LOG.error(msg); throw new CommException(msg); } // init jaxb try { context = JAXBContext.newInstance("org.squidy.nodes.laserpointer.config.xml"); unmarshaller = context.createUnmarshaller(); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); } catch (JAXBException e) { LOG.error(e.getMessage(), e); throw new CommException(CommService.INTERNAL_ERROR_MSG); } }
From source file:org.squidy.nodes.tracking.configclient.service.comm.TcpIpCommService.java
@Override protected void startupImpl() throws CommException { Object property = pService.getProperties().getProperty(JavaPropService.DEBUG_COMM); if (property != null) { debug = Boolean.parseBoolean((String) property); }// w w w . java 2s. c om if (debug) initDebugOutput(); // init connection LOG.info("Creating connection: " + address); try { server = new Socket(address.getAddress(), address.getPort()); LOG.info("Connection accepted"); newConnection(server.getInputStream(), server.getOutputStream()); } catch (ConnectException e) { String msg = "Connection to " + address + " refused."; LOG.error(msg); throw new CommException(msg); } catch (UnknownHostException e) { String msg = "Unknown host: " + address; LOG.error(msg); throw new CommException(msg); } catch (IOException e) { String msg = "Cannot read from: " + address; LOG.error(msg); throw new CommException(msg); } // init jaxb try { context = JAXBContext.newInstance(Configuration.class.getPackage().getName()); unmarshaller = context.createUnmarshaller(); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); } catch (JAXBException e) { LOG.error(e.getMessage(), e); throw new CommException(CommService.INTERNAL_ERROR_MSG); } }
From source file:org.camera.service.CAMERARESTService.java
/** * //from w w w. ja v a2s .c om * @param pmPairList List of the name and value parameters that user has provided * through paramInputPort. However in method this list is combined with * the user configured ports and the combined list name value pair parameters are * added to the service URL separated by ampersand. * @param nvPairList List of the name and value parameters that user has provided * @return the results after executing the Get service. */ public String executeGetMethod(List<NameValuePair> nvPairList, String serSiteURL) throws IllegalActionException { if (_debugging) { _debug("I AM IN GET METHOD"); } HttpClient client = new HttpClient(); StringBuilder results = new StringBuilder(); results.append(serSiteURL); //Files cannot be attached with GET List<NameValuePair> fullPairList = nvPairList;// getCombinedPairList(nvPairList); if (fullPairList.size() > 0) { results.append("?"); int pairListSize = fullPairList.size(); for (int j = 0; j < pairListSize; j++) { NameValuePair nvPair = fullPairList.get(j); results.append(nvPair.getName()).append(ServiceUtils.EQUALDELIMITER).append(nvPair.getValue()); if (j < pairListSize - 1) { results.append("&"); } } } if (_debugging) { _debug("RESULTS :" + results.toString()); } // Create a method instance. GetMethod method = new GetMethod(results.toString()); InputStream rstream = null; StringBuilder resultsForDisplay = new StringBuilder(); try { messageBldr = new StringBuilder(); messageBldr.append("In excutePostMethod, communicating with service: ").append(serSiteURL) .append(" STATUS Code: "); int statusCode = client.executeMethod(method); messageBldr.append(statusCode); log.debug("DEBUG: " + messageBldr.toString()); System.out.println(messageBldr.toString()); rstream = method.getResponseBodyAsStream(); BufferedReader br = new BufferedReader(new InputStreamReader(rstream)); String s; while ((s = br.readLine()) != null) { resultsForDisplay.append(s).append(ServiceUtils.LINESEP); } } catch (HttpException httpe) { if (_debugging) { _debug("Fatal protocol violation: " + httpe.getMessage()); } httpe.printStackTrace(); // return "Protocol Violation"; throw new IllegalActionException("Fatal protocol violation: " + httpe.getMessage()); } catch (ConnectException conExp) { if (_debugging) { _debug("Perhaps service not reachable: " + conExp.getMessage()); } conExp.printStackTrace(); throw new IllegalActionException("Perhaps service not reachable: " + conExp.getMessage()); } catch (IOException ioe) { if (_debugging) { _debug("Fatal transport error: " + ioe.getMessage()); } ioe.printStackTrace(); // return "IOException: fatal transport error"; throw new IllegalActionException("Fatal transport error: " + ioe.getMessage()); } catch (Exception e) { if (_debugging) { _debug("Unknown error: " + e.getMessage()); } e.printStackTrace(); // return "Exception: Unknown type error"; throw new IllegalActionException("Error: " + e.getMessage()); } finally { // Release the connection. method.releaseConnection(); } return resultsForDisplay.toString(); }
From source file:edu.isi.misd.tagfiler.client.JakartaClient.java
/** * Execute a HttpUriRequest//from www.jav a 2 s . c o m * * @param request * the request to be executed * @param cookie * the cookie to be set in the request * @return the HTTP Response */ private ClientURLResponse execute(HttpUriRequest request, String cookie) { setCookie(cookie, request); request.setHeader("X-Machine-Generated", "true"); ClientURLResponse response = null; int count = 0; while (true) { try { response = new JakartaClientResponse(httpclient.execute(request)); break; } catch (ConnectException e) { // Can not connect and send the request // Retry maximum 10 times synchronized (this) { if (connectException == null || !connectException.equals(e.getMessage())) { System.err.println("ConnectException"); e.printStackTrace(); connectException = e.getMessage(); } } } catch (ClientProtocolException e) { // TODO Auto-generated catch block synchronized (this) { if (clientProtocolException == null || !clientProtocolException.equals(e.getMessage())) { System.err.println("ClientProtocolException"); e.printStackTrace(); clientProtocolException = e.getMessage(); } } } catch (IOException e) { // The request was sent, but no response; connection might have been broken synchronized (this) { if (ioException == null || !ioException.equals(e.getMessage())) { System.err.println("IOException"); e.printStackTrace(); ioException = e.getMessage(); } } } if (++count > retries) { break; } else { // just in case if (response != null) { response.release(); } // sleep before retrying int delay = (int) Math.ceil((0.75 + Math.random() * 0.5) * Math.pow(10, count) * 0.00001); System.out.println("Retry delay: " + delay + " ms."); try { Thread.sleep(delay); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } return response; }
From source file:org.camera.service.CAMERARESTService.java
/** * File & regular parameters are passed as two separate lists and they are treated * little differently. If flPairList is not null or empty then this method uses Part * Object else no.//from w ww .j a v a 2 s. c o m * @param pmPairList List of the name and value parameters that user has provided * @param flPairList List of the name and value (full file path)of file parameters. * It is essentially a list of files that user wishes to attach. * @return the results after executing the Post service. */ public String executePostMethod(List<NameValuePair> pmPairList, List<NameValuePair> flPairList, String serSiteURL) throws IllegalActionException { if (_debugging) { _debug("I AM IN POST METHOD"); } log.debug("I AM IN POST METHOD"); String postAddress = serSiteURL; HttpClient client = new HttpClient(); MultipartPostMethod method = new MultipartPostMethod(postAddress); List<NameValuePair> fullNameValueList = pmPairList; if (flPairList != null && flPairList.size() > 0) { fullNameValueList.addAll(flPairList); int totalSize = fullNameValueList.size(); Part[] parts = new Part[totalSize]; try { for (int i = 0; i < parts.length; i++) { String nm = fullNameValueList.get(i).getName(); String vl = fullNameValueList.get(i).getValue(); if (i > totalSize - flPairList.size() - 1) { System.out.println("FILE NAME: " + nm); File file = getFileObject(vl); System.out.println("FILE NAME: " + file.getName()); parts[i] = new FilePart(nm, file); method.addPart(parts[i]); System.out.println("PARTS: " + i + " " + parts[i].getName()); System.out.println("file Name: " + vl); } else { System.out.println("PARAMETER NAME: " + nm); System.out.println("PARAMETER Value: " + vl); parts[i] = new StringPart(nm, vl); method.addPart(parts[i]); } if (_debugging) { _debug("Value of i: " + i); } } } catch (FileNotFoundException fnfe) { if (_debugging) { _debug("File Not Found Exception: " + fnfe.getMessage()); } fnfe.printStackTrace(); throw new IllegalActionException("File Not Found: " + fnfe.getMessage()); } } else { for (NameValuePair nmPair : fullNameValueList) { method.addParameter(nmPair.getName(), nmPair.getValue()); System.out.println("Name: " + nmPair.getName() + " Value:" + nmPair.getValue()); } } InputStream rstream = null; StringBuilder results = new StringBuilder(); try { messageBldr = new StringBuilder(); messageBldr.append("In excutePostMethod, communicating with service: ").append(serSiteURL) .append(" STATUS Code: "); int statusCode = client.executeMethod(method); messageBldr.append(statusCode); log.debug("DEBUG: " + messageBldr.toString()); System.out.println(messageBldr.toString()); rstream = method.getResponseBodyAsStream(); BufferedReader br = new BufferedReader(new InputStreamReader(rstream)); log.debug("BEFORE WHILE LOOP"); String s; while ((s = br.readLine()) != null) { results.append(s).append(ServiceUtils.LINESEP); } } catch (HttpException httpe) { if (_debugging) { _debug("Fatal protocol violation: " + httpe.getMessage()); } httpe.printStackTrace(); // return "Protocol Violation"; throw new IllegalActionException("Fatal protocol violation: " + httpe.getMessage()); } catch (ConnectException conExp) { if (_debugging) { _debug("Perhaps service not reachable: " + conExp.getMessage()); } conExp.printStackTrace(); throw new IllegalActionException("Perhaps service not reachable: " + conExp.getMessage()); // return "Perhaps service not reachable"; } catch (IOException ioe) { if (_debugging) { _debug("Fatal transport error: " + ioe.getMessage()); } ioe.printStackTrace(); // return "IOException: Perhaps could not connect to the service."; throw new IllegalActionException("Fatal transport error: " + ioe.getMessage()); } catch (Exception e) { if (_debugging) { _debug("Unknown error: " + e.getMessage()); } e.printStackTrace(); // return "Exception: Unknown type error"; throw new IllegalActionException("Error: " + e.getMessage()); } finally { // Release the connection. method.releaseConnection(); } return results.toString(); }
From source file:com.mobilyzer.util.PhoneUtils.java
/** * Using MLab service to detect ipv4 or ipv6 compatibility * @param ip_detect_type -- "ipv4" or "ipv6" * @return IP_TYPE_CANNOT_DECIDE, IP_TYPE_UNCONNECTIVITY, IP_TYPE_CONNECTIVITY *///from w w w . j av a2s . com private int checkIPCompatibility(String ip_detect_type) { if (!ip_detect_type.equals("ipv4") && !ip_detect_type.equals("ipv6")) { return IP_TYPE_CANNOT_DECIDE; } Socket tcpSocket = new Socket(); try { ArrayList<String> hostnameList = MLabNS.Lookup(context, "mobiperf", ip_detect_type, "ip"); // MLabNS returns at least one ip address if (hostnameList.isEmpty()) return IP_TYPE_CANNOT_DECIDE; // Use the first result in the element String hostname = hostnameList.get(0); SocketAddress remoteAddr = new InetSocketAddress(hostname, portNum); tcpSocket.setTcpNoDelay(true); tcpSocket.connect(remoteAddr, tcpTimeout); } catch (ConnectException e) { // Server is not reachable due to client not support ipv6 Logger.e("Connection exception is " + e.getMessage()); return IP_TYPE_UNCONNECTIVITY; } catch (IOException e) { // Client timer expired Logger.e("Fail to setup TCP in checkIPCompatibility(). " + e.getMessage()); return IP_TYPE_CANNOT_DECIDE; } catch (InvalidParameterException e) { // MLabNS service lookup fail Logger.e("InvalidParameterException in checkIPCompatibility(). " + e.getMessage()); return IP_TYPE_CANNOT_DECIDE; } catch (IllegalArgumentException e) { Logger.e("IllegalArgumentException in checkIPCompatibility(). " + e.getMessage()); return IP_TYPE_CANNOT_DECIDE; } finally { try { tcpSocket.close(); } catch (IOException e) { Logger.e("Fail to close TCP in checkIPCompatibility()."); return IP_TYPE_CANNOT_DECIDE; } } return IP_TYPE_CONNECTIVITY; }
From source file:org.zaproxy.zap.spider.SpiderTask.java
@Override public void run() { // Log the task start if (log.isDebugEnabled()) { try {//from www . ja v a 2s. co m log.debug("Spider Task Started. Processing uri at depth " + depth + " using already constructed message: " + reference.getURI()); } catch (Exception e1) { // Ignore it } } // Check if the should stop if (parent.isStopped()) { log.debug("Spider process is stopped. Skipping crawling task..."); parent.postTaskExecution(); return; } if (reference == null) { log.warn("Null URI. Skipping crawling task: " + this); parent.postTaskExecution(); return; } // Check if the crawling process is paused and do any "before execution" processing parent.preTaskExecution(); // Fetch the resource HttpMessage msg = null; try { msg = fetchResource(); } catch (ConnectException e) { // This will have been logged at debug level with the URL (which we dont have here) parent.postTaskExecution(); return; } catch (SocketTimeoutException e) { // This will have been logged at debug level with the URL (which we dont have here) parent.postTaskExecution(); return; } catch (SocketException e) { // This will have been logged at debug level with the URL (which we dont have here) parent.postTaskExecution(); return; } catch (UnknownHostException e) { // This will have been logged at debug level with the URL (which we dont have here) parent.postTaskExecution(); return; } catch (Exception e) { log.error("An error occured while fetching the resource: " + e.getMessage(), e); parent.postTaskExecution(); return; } // Check if the should stop if (parent.isStopped()) { log.debug("Spider process is stopped. Skipping crawling task..."); parent.postTaskExecution(); return; } // Check if the crawling process is paused parent.checkPauseAndWait(); // Check the parse filters to see if the resource should be skipped from parsing boolean isFiltered = false; for (ParseFilter filter : parent.getController().getParseFilters()) { if (filter.isFiltered(msg)) { if (log.isDebugEnabled()) { log.debug("Resource fetched, but will not be parsed due to a ParseFilter rule: " + msg.getRequestHeader().getURI()); } isFiltered = true; break; } } if (!isFiltered) { // Notify the SpiderListeners that a resource was read parent.notifyListenersReadURI(msg); } // Check if the should stop if (parent.isStopped()) { log.debug("Spider process is stopped. Skipping crawling task..."); parent.postTaskExecution(); return; } // Check if the crawling process is paused parent.checkPauseAndWait(); // Process resource, if this is not the maximum depth if (!isFiltered && depth < parent.getSpiderParam().getMaxDepth()) { processResource(msg); } // Update the progress and check if the spidering process should stop parent.postTaskExecution(); log.debug("Spider Task finished."); }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.LDAPUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#removeUserAccount(java.lang.String) *//*ww w . jav a 2 s .com*/ public synchronized boolean removeUserAccount(final String userId) throws UserManagementException { final String methodName = LDAPUserManager.CNAME + "#removeUserAccount(final String userId) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug(userId); } boolean isComplete = false; LDAPConnection ldapConn = null; LDAPConnectionPool ldapPool = null; try { ldapPool = (LDAPConnectionPool) svcBean.getAuthDataSource(); if (DEBUG) { DEBUGGER.debug("LDAPConnectionPool: {}", ldapPool); } if (ldapPool.isClosed()) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } ldapConn = ldapPool.getConnection(); if (DEBUG) { DEBUGGER.debug("LDAPConnection: {}", ldapConn); } if (!(ldapConn.isConnected())) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } DeleteRequest deleteRequest = new DeleteRequest( new StringBuilder().append(userAttributes.getUserId() + "=" + userId + ",") .append(repoConfig.getRepositoryUserBase() + "," + repoConfig.getRepositoryBaseDN()) .toString()); if (DEBUG) { DEBUGGER.debug("DeleteRequest: {}", deleteRequest); } LDAPResult ldapResult = ldapConn.delete(deleteRequest); if (DEBUG) { DEBUGGER.debug("LDAPResult: {}", ldapResult); } if (ldapResult.getResultCode() == ResultCode.SUCCESS) { isComplete = true; } } catch (LDAPException lx) { throw new UserManagementException(lx.getMessage(), lx); } catch (ConnectException cx) { throw new UserManagementException(cx.getMessage(), cx); } finally { if ((ldapPool != null) && ((ldapConn != null) && (ldapConn.isConnected()))) { ldapConn.close(); ldapPool.releaseConnection(ldapConn); } } return isComplete; }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.LDAPUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserEmail(java.lang.String, java.lang.String) *//* w w w . j av a 2 s.com*/ public synchronized boolean modifyUserEmail(final String userId, final String value) throws UserManagementException { final String methodName = LDAPUserManager.CNAME + "#modifyUserEmail(final String userId, final String value) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("userId: {}", userId); DEBUGGER.debug("userGuid: {}", value); } boolean isComplete = false; LDAPConnection ldapConn = null; LDAPConnectionPool ldapPool = null; try { ldapPool = (LDAPConnectionPool) svcBean.getAuthDataSource(); if (DEBUG) { DEBUGGER.debug("LDAPConnectionPool: {}", ldapPool); } if (ldapPool.isClosed()) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } ldapConn = ldapPool.getConnection(); if (DEBUG) { DEBUGGER.debug("LDAPConnection: {}", ldapConn); } if (!(ldapConn.isConnected())) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } List<Modification> modifyList = new ArrayList<Modification>(Arrays .asList(new Modification(ModificationType.REPLACE, userAttributes.getEmailAddr(), value))); LDAPResult ldapResult = ldapConn.modify( new ModifyRequest(new StringBuilder().append(userAttributes.getUserId() + "=" + userId + ",") .append(repoConfig.getRepositoryUserBase() + "," + repoConfig.getRepositoryBaseDN()) .toString(), modifyList)); if (DEBUG) { DEBUGGER.debug("LDAPResult: {}", ldapResult); } isComplete = (ldapResult.getResultCode() == ResultCode.SUCCESS); if (DEBUG) { DEBUGGER.debug("isComplete: {}", isComplete); } } catch (LDAPException lx) { throw new UserManagementException(lx.getMessage(), lx); } catch (ConnectException cx) { throw new UserManagementException(cx.getMessage(), cx); } finally { if ((ldapPool != null) && ((ldapConn != null) && (ldapConn.isConnected()))) { ldapConn.close(); ldapPool.releaseConnection(ldapConn); } } return isComplete; }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.LDAPUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserContact(java.lang.String, java.util.List) *//*from w w w. j av a2 s .co m*/ public synchronized boolean modifyUserContact(final String userId, final List<String> values) throws UserManagementException { final String methodName = LDAPUserManager.CNAME + "#modifyUserContact(final String userId, final String value, final String attribute) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", userId); DEBUGGER.debug("Value: {}", values); } boolean isComplete = false; LDAPConnection ldapConn = null; LDAPConnectionPool ldapPool = null; try { ldapPool = (LDAPConnectionPool) svcBean.getAuthDataSource(); if (DEBUG) { DEBUGGER.debug("LDAPConnectionPool: {}", ldapPool); } if (ldapPool.isClosed()) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } ldapConn = ldapPool.getConnection(); if (DEBUG) { DEBUGGER.debug("LDAPConnection: {}", ldapConn); } if (!(ldapConn.isConnected())) { throw new ConnectException("Failed to create LDAP connection using the specified information"); } List<Modification> modifyList = new ArrayList<Modification>(Arrays.asList(new Modification( ModificationType.REPLACE, userAttributes.getTelephoneNumber(), values.get(0)))); LDAPResult ldapResult = ldapConn.modify( new ModifyRequest(new StringBuilder().append(userAttributes.getUserId() + "=" + userId + ",") .append(repoConfig.getRepositoryUserBase() + "," + repoConfig.getRepositoryBaseDN()) .toString(), modifyList)); if (DEBUG) { DEBUGGER.debug("LDAPResult: {}", ldapResult); } isComplete = (ldapResult.getResultCode() == ResultCode.SUCCESS); if (DEBUG) { DEBUGGER.debug("isComplete: {}", isComplete); } } catch (LDAPException lx) { throw new UserManagementException(lx.getMessage(), lx); } catch (ConnectException cx) { throw new UserManagementException(cx.getMessage(), cx); } finally { if ((ldapPool != null) && ((ldapConn != null) && (ldapConn.isConnected()))) { ldapConn.close(); ldapPool.releaseConnection(ldapConn); } } return isComplete; }