List of usage examples for org.apache.http.util Args notNull
public static <T> T notNull(T t, String str)
From source file:net.dv8tion.jda.core.managers.fields.PermissionField.java
@Override public void checkValue(Long value) { Args.notNull(value, "permission value"); Permission.getPermissions(value).forEach(p -> { checkPermission(p);// w ww . j a va 2s .com }); }
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. *//*from ww w. ja va2 s .co 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:com.ok2c.lightmtp.impl.protocol.SimpleSendEnvelopCodec.java
@Override public void consumeData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionInputBuffer buf = this.iobuffers.getInbuf(); DeliveryRequest request = sessionState.getRequest(); int bytesRead = buf.fill(iosession.channel()); SMTPReply reply = this.parser.parse(buf, bytesRead == -1); if (reply != null) { switch (this.codecState) { case MAIL_RESPONSE_EXPECTED: if (reply.getCode() == SMTPCodes.OK) { this.codecState = CodecState.RCPT_REQUEST_READY; this.recipients.clear(); this.recipients.addAll(request.getRecipients()); iosession.setEvent(SelectionKey.OP_WRITE); } else { this.deliveryFailed = true; this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); }//w w w . ja v a 2s. c o m break; case RCPT_RESPONSE_EXPECTED: if (this.recipients.isEmpty()) { throw new IllegalStateException("Unexpected state: " + this.codecState); } String recipient = this.recipients.removeFirst(); if (reply.getCode() != SMTPCodes.OK) { sessionState.getFailures().add(new RcptResult(reply, recipient)); } if (this.recipients.isEmpty()) { List<String> requested = request.getRecipients(); List<RcptResult> failured = sessionState.getFailures(); if (requested.size() > failured.size()) { this.codecState = CodecState.DATA_REQUEST_READY; } else { this.deliveryFailed = true; this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); } } else { this.codecState = CodecState.RCPT_REQUEST_READY; } iosession.setEvent(SelectionKey.OP_WRITE); break; case DATA_RESPONSE_EXPECTED: this.codecState = CodecState.COMPLETED; if (reply.getCode() != SMTPCodes.START_MAIL_INPUT) { this.deliveryFailed = true; } sessionState.setReply(reply); break; default: if (reply.getCode() == SMTPCodes.ERR_TRANS_SERVICE_NOT_AVAILABLE) { sessionState.setReply(reply); this.codecState = CodecState.COMPLETED; } else { throw new SMTPProtocolException("Unexpected reply: " + reply); } } } if (bytesRead == -1 && !sessionState.isTerminated()) { throw new UnexpectedEndOfStreamException(); } }
From source file:com.leetchi.api.client.ssl.SSLConnectionSocketFactory.java
public SSLConnectionSocketFactory(final javax.net.ssl.SSLSocketFactory socketfactory, final String[] supportedProtocols, final String[] supportedCipherSuites, final X509HostnameVerifier hostnameVerifier) { this.socketfactory = Args.notNull(socketfactory, "SSL socket factory"); this.supportedProtocols = supportedProtocols; this.supportedCipherSuites = supportedCipherSuites; this.hostnameVerifier = hostnameVerifier != null ? hostnameVerifier : BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; }
From source file:org.dcache.srm.client.FlexibleCredentialSSLConnectionSocketFactory.java
@Override public Socket connectSocket(final int connectTimeout, final Socket socket, final HttpHost host, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpContext context) throws IOException { Args.notNull(host, "HTTP host"); Args.notNull(remoteAddress, "Remote address"); final Socket sock = socket != null ? socket : createSocket(context); if (localAddress != null) { sock.bind(localAddress);//from w w w.j av a2 s .co m } try { if (connectTimeout > 0 && sock.getSoTimeout() == 0) { sock.setSoTimeout(connectTimeout); } LOGGER.debug("Connecting socket to {} with timeout {}", remoteAddress, connectTimeout); sock.connect(remoteAddress, connectTimeout); } catch (final IOException ex) { try { sock.close(); } catch (final IOException ignore) { } throw ex; } // Setup SSL layering if necessary if (sock instanceof SSLSocket) { final SSLSocket sslsock = (SSLSocket) sock; LOGGER.debug("Starting handshake"); sslsock.startHandshake(); verifyHostname(sslsock, host.getHostName()); return sock; } else { return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context); } }
From source file:com.ok2c.lightmtp.impl.protocol.ReceiveDataCodec.java
@Override public void produceData(final IOSession iosession, final ServerState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); synchronized (sessionState) { if (this.pendingDelivery != null) { if (this.pendingDelivery.isDone()) { deliveryCompleted(sessionState); cleanUp();//ww w. j a v a2s.com } while (!this.pendingReplies.isEmpty()) { this.writer.write(this.pendingReplies.removeFirst(), buf); } } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { if (sessionState.getDataType() != null) { this.completed = true; sessionState.reset(); } iosession.clearEvent(SelectionKey.OP_WRITE); } } }
From source file:com.ok2c.lightmtp.impl.protocol.PipeliningReceiveEnvelopCodec.java
@Override public void consumeData(final IOSession iosession, final ServerState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionInputBuffer buf = this.iobuffers.getInbuf(); synchronized (sessionState) { for (;;) { int bytesRead = buf.fill(iosession.channel()); try { SMTPCommand command = this.parser.parse(buf, bytesRead == -1); if (command == null) { if (bytesRead == -1 && !sessionState.isTerminated() && this.pendingActions.isEmpty()) { throw new UnexpectedEndOfStreamException(); } else { break; }// w ww .j a v a 2 s . com } Action<ServerState> action = this.commandHandler.handle(command); this.pendingActions.add(action); } catch (SMTPErrorException ex) { SMTPReply reply = new SMTPReply(ex.getCode(), ex.getEnhancedCode(), ex.getMessage()); this.pendingActions.add(new SimpleAction(reply)); } catch (SMTPProtocolException ex) { SMTPReply reply = new SMTPReply(SMTPCodes.ERR_PERM_SYNTAX_ERR_COMMAND, new SMTPCode(5, 3, 0), ex.getMessage()); this.pendingActions.add(new SimpleAction(reply)); } } if (!this.pendingActions.isEmpty()) { iosession.setEvent(SelectionKey.OP_WRITE); } } }
From source file:io.apiman.gateway.platforms.servlet.connectors.ssl.SSLSessionStrategyFactory.java
/** * Convenience function parses map of options to generate {@link SSLSessionStrategy}. * <p>/*www. jav a2 s . co m*/ * Defaults are provided for some fields, others are options. ClientKeystore is required: * <p> * <ul> * <li>trustStore - default: <a href="https://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores">JSSERefGuide</a></li> * <li>trustStorePassword - none</li> * <li>keyStore - required</li> * <li>keyStorePassword - none</li> * <li>keyAliases - none</li> * <li>keyPassword - none</li> * <li>allowedProtocols - {@link SSLParameters#getProtocols()}</li> * <li>disallowedProtocols - {@link SSLParameters#getCipherSuites()}</li> * <li>allowedCiphers - {@link SSLParameters#getCipherSuites()}</li> * <li>disallowedCiphers - {@link SSLParameters#getCipherSuites()}</li> * <li>allowAnyHost - false</li> * <li>allowSelfSigned - false</li> * </ul> * * @param optionsMap map of options * @return the SSL session strategy * @see #build(String, String, String, String, String[], String, String[], String[], boolean, boolean) * @throws NoSuchAlgorithmException if the selected algorithm is not available on the system * @throws KeyManagementException when particular cryptographic algorithm not available * @throws KeyStoreException problem with keystore * @throws CertificateException if there was a problem with the certificate * @throws IOException if the truststore could not be found or was invalid * @throws UnrecoverableKeyException a key in keystore cannot be recovered */ @SuppressWarnings("nls") public static SSLSessionStrategy buildMutual(TLSOptions optionsMap) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException { Args.notNull(optionsMap.getKeyStore(), "KeyStore"); Args.notEmpty(optionsMap.getKeyStore(), "KeyStore must not be empty"); String[] allowedProtocols = arrayDifference(optionsMap.getAllowedProtocols(), optionsMap.getDisallowedProtocols(), getDefaultProtocols()); String[] allowedCiphers = arrayDifference(optionsMap.getAllowedCiphers(), optionsMap.getDisallowedCiphers(), getDefaultCipherSuites()); return build(optionsMap.getTrustStore(), optionsMap.getTrustStorePassword(), optionsMap.getKeyStore(), optionsMap.getKeyStorePassword(), optionsMap.getKeyAliases(), optionsMap.getKeyPassword(), allowedProtocols, allowedCiphers, optionsMap.isAllowAnyHost(), optionsMap.isTrustSelfSigned()); }
From source file:net.dv8tion.jda.core.entities.impl.VoiceChannelImpl.java
@Override public RestAction<PermissionOverride> createPermissionOverride(Member member) { checkPermission(Permission.MANAGE_PERMISSIONS); Args.notNull(member, "member"); if (!guild.equals(member.getGuild())) throw new IllegalArgumentException("Provided member is not from the same guild as this channel!"); if (getMemberOverrideMap().containsKey(member)) throw new IllegalStateException("Provided member already has a PermissionOverride in this channel!"); final PermissionOverride override = new PermissionOverrideImpl(this, member, null); JSONObject body = new JSONObject().put("id", member.getUser().getId()).put("type", "member").put("allow", 0) .put("deny", 0); Route.CompiledRoute route = Route.Channels.CREATE_PERM_OVERRIDE.compile(id, member.getUser().getId()); return new RestAction<PermissionOverride>(getJDA(), route, body) { @Override//from w ww. j a v a2s .c o m protected void handleResponse(Response response, Request request) { if (!response.isOk()) request.onFailure(response); getMemberOverrideMap().put(member, override); request.onSuccess(override); } }; }
From source file:com.serphacker.serposcope.scraper.http.extensions.ScrapClientSSLConnectionFactory.java
@Override public Socket connectSocket(final int connectTimeout, final Socket socket, final HttpHost host, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpContext context) throws IOException { Args.notNull(host, "HTTP host"); Args.notNull(remoteAddress, "Remote address"); final Socket sock = socket != null ? socket : createSocket(context); if (localAddress != null) { sock.bind(localAddress);// w ww .ja va 2 s . c o m } try { if (connectTimeout > 0 && sock.getSoTimeout() == 0) { sock.setSoTimeout(connectTimeout); } if (this.log.isDebugEnabled()) { this.log.debug("Connecting socket to " + remoteAddress + " with timeout " + connectTimeout); } sock.connect(remoteAddress, connectTimeout); } catch (final IOException ex) { try { sock.close(); } catch (final IOException ignore) { } throw ex; } // Setup SSL layering if necessary if (sock instanceof SSLSocket) { final SSLSocket sslsock = (SSLSocket) sock; this.log.debug("Starting handshake"); sslsock.startHandshake(); verifyHostname(sslsock, host.getHostName()); return sock; } else { return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context); } }