List of usage examples for java.io IOException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:me.schiz.jmeter.protocol.pop3.sampler.POP3Sampler.java
private SampleResult sampleNoop(SampleResult sr) { SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient()); POP3Client client = null;// w w w. ja va 2s . co m if (soclient instanceof POP3Client) client = (POP3Client) soclient; String request = "NOOP\n"; request += "Client : " + getClient() + "\n"; sr.setRequestHeaders(request); if (client == null) { clientNotFound(sr); } else { synchronized (client) { sr.sampleStart(); try { boolean noop = client.noop(); sr.setSuccessful(noop); sr.setResponseCode(noop ? RC_200 : RC_500); } catch (IOException e) { sr.setSuccessful(false); sr.setResponseData(e.toString().getBytes()); sr.setResponseCode(e.getClass().getName()); log.error("client `" + client + "` io exception", e); removeClient(); } sr.sampleEnd(); } } return sr; }
From source file:me.schiz.jmeter.protocol.pop3.sampler.POP3Sampler.java
private SampleResult sampleReset(SampleResult sr) { SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient()); POP3Client client = null;//w w w .j ava 2 s .co m if (soclient instanceof POP3Client) client = (POP3Client) soclient; String request = "COMMAND\n"; request += "Client : " + getClient() + "\n"; sr.setRequestHeaders(request); if (client == null) { clientNotFound(sr); return sr; } else { synchronized (client) { sr.sampleStart(); try { boolean reset = client.reset(); sr.setSuccessful(reset); sr.setResponseCode(reset ? RC_200 : RC_500); } catch (IOException e) { sr.setSuccessful(false); sr.setResponseData(e.toString().getBytes()); sr.setResponseCode(e.getClass().getName()); log.error("client `" + client + "` ", e); removeClient(); } sr.sampleEnd(); } } return sr; }
From source file:me.schiz.jmeter.protocol.pop3.sampler.POP3Sampler.java
private SampleResult sampleConnect(SampleResult sr) { POP3Client client;// www. j a v a 2 s .c o m if (getUseSSL()) { client = new POP3SClient(true); // } else if(getUseSTARTTLS()) { // client = new POP3SClient(false); } else { client = new POP3Client(); } StringBuilder requestBuilder = new StringBuilder(); try { //String request = "CONNECT \n"; requestBuilder.append("CONNECT\n"); requestBuilder.append("Host : " + getHostname() + ":" + getPort() + "\n"); requestBuilder.append("Connect Timeout: " + getConnectionTimeout() + "\n"); requestBuilder.append("Socket Timeout: " + getSoTimeout() + "\n"); requestBuilder.append("Client : " + getClient() + "\n"); if (getUseSSL()) requestBuilder.append("SSL : true\n"); else requestBuilder.append("SSL : false\n"); // if(getUseSTARTTLS()) request += "STARTTLS : true\n"; // else request += "STARTTLS : false\n"; sr.setRequestHeaders(requestBuilder.toString()); sr.sampleStart(); client.setConnectTimeout(getConnectionTimeout()); client.connect(getHostname(), getPort()); if (client.isConnected()) { SessionStorage.proto_type protoType = SessionStorage.proto_type.PLAIN; if (getUseSSL()) protoType = SessionStorage.proto_type.SSL; // 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(RC_200); sr.setResponseData(client.getReplyString().getBytes()); sr.setSuccessful(true); } else { sr.setResponseCode(RC_500); sr.setSuccessful(false); } } 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:org.dasein.cloud.google.network.FirewallSupport.java
@Override public @Nonnull Collection<Firewall> list() throws InternalException, CloudException { //GCE has a defacto Firewall for every network so will simply map a fake firewall to networks. ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new InternalException("No context was established"); }// w w w . j ava2 s . c o m ArrayList<Firewall> firewalls = new ArrayList<Firewall>(); try { Compute gce = provider.getGoogleCompute(); List<Network> networks = gce.networks().list(ctx.getAccountNumber()).execute().getItems(); if (networks != null && networks.size() > 0) { for (Network network : networks) { if (network != null) { List<com.google.api.services.compute.model.Firewall> rules = gce.firewalls() .list(ctx.getAccountNumber()).setFilter("network eq " + network.getName()).execute() .getItems(); Firewall firewall = toFirewall(network, rules); if (firewall != null) firewalls.add(firewall); } } } } catch (IOException ex) { logger.error(ex.getMessage()); if (ex.getClass() == GoogleJsonResponseException.class) { GoogleJsonResponseException gjre = (GoogleJsonResponseException) ex; throw new GoogleException(CloudErrorType.GENERAL, gjre.getStatusCode(), gjre.getContent(), gjre.getDetails().getMessage()); } else throw new CloudException("An error occurred while listing Firewalls: " + ex.getMessage()); } return firewalls; }
From source file:org.dasein.cloud.google.network.FirewallSupport.java
@Override public void revoke(@Nonnull String providerFirewallRuleId) throws InternalException, CloudException { APITrace.begin(provider, "Firewall.revoke"); try {/*from www .j a v a 2s. c o m*/ try { Compute gce = provider.getGoogleCompute(); Operation job = gce.firewalls() .delete(provider.getContext().getAccountNumber(), providerFirewallRuleId).execute(); GoogleMethod method = new GoogleMethod(provider); if (!method.getOperationComplete(provider.getContext(), job, GoogleOperationType.GLOBAL_OPERATION, "", "")) { throw new CloudException("An error occurred deleting the rule: Operation Timed Out"); } } catch (IOException ex) { logger.error(ex.getMessage()); if (ex.getClass() == GoogleJsonResponseException.class) { GoogleJsonResponseException gjre = (GoogleJsonResponseException) ex; throw new GoogleException(CloudErrorType.GENERAL, gjre.getStatusCode(), gjre.getContent(), gjre.getDetails().getMessage()); } else throw new CloudException( "An error occurred while deleting the firewall rule: " + ex.getMessage()); } } finally { APITrace.end(); } }
From source file:org.paxle.se.provider.rsssearch.impl.RssSearchProvider.java
public void search(ISearchRequest searchRequest, List<IIndexerDocument> results) throws IOException, InterruptedException { String url = null;/* www .j a va2 s . c om*/ try { final ISearchProviderContext context = SearchProviderContext.getCurrentContext(); final String request = new RssSearchQueryFactor().transformToken(searchRequest.getSearchQuery()); final int maxCount = searchRequest.getMaxResultCount(); //creating a channel-builder ChannelBuilder builder = new ChannelBuilder(); // parsing the rss/atom feed HttpMethod hm = null; try { // opening an http connection url = new URL(String.format(feedURL, URLEncoder.encode(request, DEFAULT_CHARSET))).toExternalForm(); hm = new GetMethod(url); HttpClient hc = new HttpClient(); int status = hc.executeMethod(hm); if (status != 200) { this.logger.warn(String.format("Error while connecting to '%s'.\r\n\tServer-Status: %s", url, hm.getStatusLine())); return; } // parsing the rss/atom feed ChannelIF channel = FeedParser.parse(builder, hm.getResponseBodyAsStream()); // loop through all items Collection<ItemIF> items = channel.getItems(); Iterator<ItemIF> it = items.iterator(); int count = 0; while (it.hasNext() && count++ < maxCount) { ItemIF item = it.next(); IIndexerDocument indexerDoc = context.createDocument(); indexerDoc.set(IIndexerDocument.LOCATION, item.getLink().toString()); indexerDoc.set(IIndexerDocument.PROTOCOL, item.getLink().getProtocol()); String title = item.getTitle(); if (title != null && title.length() > 0) { indexerDoc.set(IIndexerDocument.TITLE, title); } String descr = item.getDescription(); if (descr != null && descr.length() > 0) { indexerDoc.set(IIndexerDocument.SUMMARY, descr); } String author = item.getCreator(); if (author != null && author.length() > 0) { indexerDoc.set(IIndexerDocument.AUTHOR, item.getCreator() == null ? "" : item.getCreator()); } Date lastMod = item.getDate(); if (lastMod != null) { indexerDoc.set(IIndexerDocument.LAST_MODIFIED, item.getDate()); } results.add(indexerDoc); } } catch (IOException e) { //do nothing, it just not worked (offline or rss-site problem) this.logger.warn(e); } finally { if (hm != null) hm.releaseConnection(); } } catch (Exception e) { this.logger.error(String.format("Unexpected '%s' while connecting to '%s'.", e.getClass().getName(), (url == null) ? this.feedURL : url)); } }
From source file:me.schiz.jmeter.protocol.smtp.sampler.SMTPSampler.java
private SampleResult sampleNoop(SampleResult sr) { SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient()); SMTPClient client = null;//from w w w . ja va 2s .c o m if (soclient instanceof SMTPClient) client = (SMTPClient) soclient; String request = "NOOP\n"; request += "Client : " + getClient() + "\n"; sr.setRequestHeaders(request); if (client == null) { clientNotFound(sr); } else { synchronized (client) { sr.sampleStart(); try { sr.setSuccessful(client.sendNoOp()); sr.setResponseCode(String.valueOf(client.getReplyCode())); sr.setResponseData(client.getReplyString().getBytes()); setSuccessfulByResponseCode(sr, client.getReplyCode()); } catch (IOException e) { sr.setSuccessful(false); sr.setResponseData(e.toString().getBytes()); sr.setResponseCode(e.getClass().getName()); log.error("client `" + client + "` io exception", e); removeClient(); } sr.sampleEnd(); } } return sr; }
From source file:com.plutext.converter.MyRetryHandler.java
/** * Used <code>retryCount</code> and <code>requestSentRetryEnabled</code> to determine * if the given method should be retried. */// w ww. j a v a 2 s. c o m public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) { Args.notNull(exception, "Exception parameter"); Args.notNull(context, "HTTP context"); if (executionCount > this.retryCount) { // Do not retry if over max retry count return false; } if (this.nonRetriableClasses.contains(exception.getClass())) { return false; } else { for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) { if (rejectException.isInstance(exception)) { return false; } } } final HttpClientContext clientContext = HttpClientContext.adapt(context); final HttpRequest request = clientContext.getRequest(); if (requestIsAborted(request)) { return false; } try { System.out.println("sleeping " + executionCount); Thread.sleep(RETRY_SLEEP_TIME * executionCount); } catch (InterruptedException e) { e.printStackTrace(); } if (handleAsIdempotent(request)) { // Retry if the request is considered idempotent System.out.println("retry handleAsIdempotent " + executionCount); return true; } if (!clientContext.isRequestSent() || this.requestSentRetryEnabled) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent System.out.println("retry " + executionCount); return true; } // otherwise do not retry System.out.println("do not retry " + exception.getClass().getName() + exception.getMessage()); return false; }
From source file:me.schiz.jmeter.protocol.pop3.sampler.POP3Sampler.java
private SampleResult sampleDisconnect(SampleResult sr) { SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient()); POP3Client client = null;//from w w w . ja v a 2 s. co m if (soclient instanceof POP3Client) client = (POP3Client) soclient; String request = "DISCONNECT\n"; request += "Client : " + getClient() + "\n"; sr.setRequestHeaders(request); if (client == null) { clientNotFound(sr); } else { synchronized (client) { sr.sampleStart(); try { client.disconnect(); if (!client.isConnected()) { sr.setResponseCode(RC_200); sr.setSuccessful(true); } else { sr.setResponseCode(RC_500); sr.setSuccessful(false); log.error("can't disconnect client " + getSOClient()); } SessionStorage.getInstance().removeClient(getSOClient()); } catch (IOException e) { sr.setSuccessful(false); sr.setResponseData(e.toString().getBytes()); sr.setResponseCode(e.getClass().getName()); log.error("client `" + client + "` ", e); removeClient(); } sr.sampleEnd(); } } return sr; }
From source file:me.schiz.jmeter.protocol.smtp.sampler.SMTPSampler.java
private SampleResult sampleConnect(SampleResult sr) { SMTPClient client;//ww w .ja va 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; }