Java Code Examples for java.io.IOException#getClass()

The following examples show how to use java.io.IOException#getClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArchiveService2Impl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public String mergeFromZip(String zipFilePath, String siteId, String creatorId) {
	try {
		String folderName = m_siteZipper.unzipArchive(zipFilePath, m_unzipPath);
		//not a lot we can do with the return value here since it always returns a string. would need a reimplementation/wrapper method to return a better value (boolean or some status)
		if (folderName == null || folderName.isEmpty()) {
			return "Failed to find folder in zip archive";
		}
		try {
			return m_siteMerger.merge(folderName, siteId, creatorId, m_unzipPath, m_filterSakaiServices, m_filteredSakaiServices, m_filterSakaiRoles, m_filteredSakaiRoles);
		} finally {
			FileUtils.deleteDirectory(new File(m_unzipPath,folderName));
		}
	} catch (IOException e) {
		log.error("Error merging from zip: " + e.getClass() + ":" + e.getMessage());
		return "Error merging from zip: " + e.getClass() + ":" + e.getMessage();
	}
}
 
Example 2
Source File: ArchiveService2Impl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public String mergeFromZip(String zipFilePath, String siteId, String creatorId) {
	try {
		String folderName = m_siteZipper.unzipArchive(zipFilePath, m_unzipPath);
		//not a lot we can do with the return value here since it always returns a string. would need a reimplementation/wrapper method to return a better value (boolean or some status)
		if (folderName == null || folderName.isEmpty()) {
			return "Failed to find folder in zip archive";
		}
		try {
			return m_siteMerger.merge(folderName, siteId, creatorId, m_unzipPath, m_filterSakaiServices, m_filteredSakaiServices, m_filterSakaiRoles, m_filteredSakaiRoles);
		} finally {
			FileUtils.deleteDirectory(new File(m_unzipPath,folderName));
		}
	} catch (IOException e) {
		log.error("Error merging from zip: " + e.getClass() + ":" + e.getMessage());
		return "Error merging from zip: " + e.getClass() + ":" + e.getMessage();
	}
}
 
Example 3
Source File: DefaultRepositoryProxyHandler.java    From archiva with Apache License 2.0 6 votes vote down vote up
/**
 * Used to move the temporary file to its real destination. This is patterned from the way WagonManager handles its
 * downloaded files.
 *
 * @param temp   The completed download file
 * @param target The final location of the downloaded file
 * @throws ProxyException when the temp file cannot replace the target file
 */
private void moveTempToTarget( StorageAsset temp, StorageAsset target )
    throws ProxyException
{

    try
    {
        org.apache.archiva.repository.storage.util.StorageUtil.moveAsset( temp, target, true , StandardCopyOption.REPLACE_EXISTING);
    }
    catch ( IOException e )
    {
        log.error( "Move failed from {} to {}, trying copy.", temp, target );
        try
        {
            FsStorageUtil.copyAsset( temp, target, true );
            if (temp.exists()) {
                temp.getStorage( ).removeAsset( temp );
            }
        }
        catch ( IOException ex )
        {
            log.error("Copy failed from {} to {}: ({}) {}", temp, target, e.getClass(), e.getMessage());
            throw new ProxyException("Could not move temp file "+temp.getPath()+" to target "+target.getPath()+": ("+e.getClass()+") "+e.getMessage(), e);
        }
    }
}
 
Example 4
Source File: BintrayImpl.java    From bintray-client-java with Apache License 2.0 6 votes vote down vote up
private HttpResponse execute(HttpUriRequest request, HttpClientContext context) throws BintrayCallException {
    log.debug("Executing {} request to path '{}', with headers: {}", request.getMethod(), request.getURI(),
            Arrays.toString(request.getAllHeaders()));
    try {
        if (context != null) {
            return client.execute(request, responseHandler, context);
        } else {
            return client.execute(request, responseHandler);
        }
    } catch (BintrayCallException bce) {
        log.debug("{}", bce.toString(), bce);
        throw bce;
    } catch (IOException ioe) {
        //Underlying IOException form the client
        String underlyingCause = (ioe.getCause() == null) ? "" : ioe.toString() + " : " + ioe.getCause().getMessage();
        log.debug("{}", ioe.getMessage(), ioe);
        throw new BintrayCallException(400, ioe.getClass() + " : " + ioe.getMessage(), underlyingCause);
    }
}
 
Example 5
Source File: ResponseUtil.java    From react-native-GPay with MIT License 5 votes vote down vote up
public static void onRequestError(
  RCTDeviceEventEmitter eventEmitter,
  int requestId,
  String error,
  IOException e) {
  WritableArray args = Arguments.createArray();
  args.pushInt(requestId);
  args.pushString(error);

  if ((e != null) && (e.getClass() == SocketTimeoutException.class)) {
    args.pushBoolean(true); // last argument is a time out boolean
  }

  eventEmitter.emit("didCompleteNetworkResponse", args);
}
 
Example 6
Source File: MtasTokenizer.java    From mtas with Apache License 2.0 5 votes vote down vote up
/**
 * Prints the.
 *
 * @param r the r
 * @throws MtasParserException the mtas parser exception
 */
public void print(final Reader r) throws MtasParserException {
  try {
    setReader(r);
    reset();
    if (tokenCollection != null) {
      tokenCollection.print();
    }
    end();
    close();
  } catch (IOException e) {
    log.error(e);
    throw new MtasParserException(e.getClass() + " : " + e.getMessage());
  }
}
 
Example 7
Source File: SwiftConnectionManager.java    From stocator with Apache License 2.0 4 votes vote down vote up
/**
 * Creates custom retry handler to be used if HTTP exception happens
 *
 * @return retry handler
 */
private HttpRequestRetryHandler getRetryHandler() {
  final HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {

    public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
      if (executionCount >= connectionConfiguration.getExecutionCount()) {
        // Do not retry if over max retry count
        LOG.debug("Execution count {} is bigger than threshold. Stop", executionCount);
        return false;
      }
      if (exception instanceof NoHttpResponseException) {
        LOG.debug("NoHttpResponseException exception. Retry count {}", executionCount);
        return true;
      }
      if (exception instanceof UnknownHostException) {
        LOG.debug("UnknownHostException. Retry count {}", executionCount);
        return true;
      }
      if (exception instanceof ConnectTimeoutException) {
        LOG.debug("ConnectTimeoutException. Retry count {}", executionCount);
        return true;
      }
      if (exception instanceof SocketTimeoutException
          || exception.getClass() == SocketTimeoutException.class
          || exception.getClass().isInstance(SocketTimeoutException.class)) {
        // Connection refused
        LOG.debug("socketTimeoutException Retry count {}", executionCount);
        return true;
      }
      if (exception instanceof InterruptedIOException) {
        // Timeout
        LOG.debug("InterruptedIOException Retry count {}", executionCount);
        return true;
      }
      if (exception instanceof SSLException) {
        LOG.debug("SSLException Retry count {}", executionCount);
        return true;
      }
      final HttpClientContext clientContext = HttpClientContext.adapt(context);
      final HttpRequest request = clientContext.getRequest();
      boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
      if (idempotent) {
        LOG.debug("HttpEntityEnclosingRequest. Retry count {}", executionCount);
        return true;
      }
      LOG.debug("Retry stopped. Retry count {}", executionCount);
      return false;
    }
  };
  return myRetryHandler;
}
 
Example 8
Source File: ServerConnectionEstablisher.java    From zap-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * 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
 */
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;
}
 
Example 9
Source File: HttpPanelSender.java    From zap-extensions with Apache License 2.0 4 votes vote down vote up
@Override
public void handleSendMessage(Message aMessage) throws IllegalArgumentException, IOException {
    final HttpMessage httpMessage = (HttpMessage) aMessage;
    try {
        getDelegate().sendAndReceive(httpMessage, getButtonFollowRedirects().isSelected());

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

                            final int finalType = HistoryReference.TYPE_ZAP_USER;
                            final Thread t =
                                    new Thread(
                                            new Runnable() {
                                                @Override
                                                public void run() {
                                                    final ExtensionHistory extHistory =
                                                            getHistoryExtension();
                                                    if (extHistory != null) {
                                                        extHistory.addHistory(
                                                                httpMessage, finalType);
                                                    }
                                                }
                                            });
                            t.start();
                        }
                    }
                });

        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 IOException ioe) {
        throw new IOException(
                "IO error in sending request: " + ioe.getClass() + ": " + ioe.getMessage(),
                ioe);

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