Example usage for org.apache.http.util Args notNull

List of usage examples for org.apache.http.util Args notNull

Introduction

In this page you can find the example usage for org.apache.http.util Args notNull.

Prototype

public static <T> T notNull(T t, String str) 

Source Link

Usage

From source file:net.dv8tion.jda.core.entities.impl.MemberImpl.java

@Override
public boolean hasPermission(Channel channel, Collection<Permission> permissions) {
    Args.notNull(permissions, "Permission Collection");

    return hasPermission(channel, permissions.toArray(new Permission[permissions.size()]));
}

From source file:sabina.integration.TestScenario.java

TestScenario(String backend, int port, boolean secure, boolean externalFiles) {
    this.port = port;
    this.backend = backend;
    this.secure = secure;
    this.externalFiles = externalFiles;

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslFactory(),
            ALLOW_ALL_HOSTNAME_VERIFIER);

    Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", sslConnectionSocketFactory).build();

    HttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(socketFactoryRegistry,
            new ManagedHttpClientConnectionFactory());

    RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.NETSCAPE).build();
    cookieStore = new BasicCookieStore();
    HttpClientContext context = HttpClientContext.create();
    context.setCookieStore(cookieStore);

    this.httpClient = HttpClients.custom().setSchemePortResolver(h -> {
        Args.notNull(h, "HTTP host");
        final int port1 = h.getPort();
        if (port1 > 0) {
            return port1;
        }/* ww w .  ja v  a2  s.  c o  m*/

        final String name = h.getSchemeName();
        if (name.equalsIgnoreCase("http")) {
            return port1;
        } else if (name.equalsIgnoreCase("https")) {
            return port1;
        } else {
            throw new UnsupportedSchemeException("unsupported protocol: " + name);
        }
    }).setConnectionManager(connManager).setDefaultRequestConfig(globalConfig).build();
}

From source file:org.apache.synapse.transport.nhttp.NhttpSharedOutputBuffer.java

@Deprecated
public NhttpSharedOutputBuffer(final int buffersize, final IOControl ioctrl,
        final ByteBufferAllocator allocator) {
    super(buffersize, allocator);
    Args.notNull(ioctrl, "I/O content control");
    this.ioctrl = ioctrl;
    this.lock = new ReentrantLock();
    this.condition = this.lock.newCondition();
}

From source file:org.dcache.srm.client.FlexibleCredentialSSLConnectionSocketFactory.java

/**
 * @since 4.4/*from  ww  w  .java  2  s . c  om*/
 */
public FlexibleCredentialSSLConnectionSocketFactory(SslContextFactory contextProvider,
        String[] supportedProtocols, String[] supportedCipherSuites, HostnameVerifier hostnameVerifier) {
    this.contextProvider = Args.notNull(contextProvider, "SSL socket factory");
    this.supportedProtocols = supportedProtocols;
    this.supportedCipherSuites = supportedCipherSuites;
    this.hostnameVerifier = hostnameVerifier != null ? hostnameVerifier : getDefaultHostnameVerifier();
}

From source file:com.amos.tool.SelfRedirectStrategy.java

public URI getLocationURI(final HttpRequest request, final HttpResponse response, final HttpContext context)
        throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine() + " but no location header");
    }/*  www.java  2  s. co  m*/
    final String location = locationHeader.getValue();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location.replaceAll(" ", "%20"));

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '" + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            Asserts.notNull(target, "Target host");
            final URI requestURI = new URI(request.getRequestLine().getUri());
            final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocations redirectLocations = (RedirectLocations) clientContext
            .getAttribute(HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocations();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}

From source file:com.ok2c.lightmtp.impl.protocol.ReceiveDataCodec.java

@Override
public void reset(final IOSession iosession, final ServerState sessionState)
        throws IOException, SMTPProtocolException {
    Args.notNull(iosession, "IO session");
    Args.notNull(sessionState, "Session state");

    cleanUp();/* ww  w . j a  va  2s. co  m*/

    if (!this.workingDir.exists()) {
        throw new IOException("Invalid working directory '" + this.workingDir + "': directory does not exist");
    }
    if (!this.workingDir.canWrite()) {
        throw new IOException("Invalid working directory '" + this.workingDir + "': directory is not writable");
    }
    this.tempFile = File.createTempFile("incoming-", ".email", this.workingDir);
    this.fileStore = new FileStore(this.tempFile);
    this.lineBuf.clear();

    this.pendingReplies.clear();
    this.dataReceived = false;
    this.pendingDelivery = null;
    this.completed = false;
}

From source file:de.vanita5.twittnuker.util.net.ssl.HostResolvedSSLConnectionSocketFactory.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 ww.  jav a 2s .c  o  m*/
    }
    try {
        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;
        sslsock.startHandshake();
        verifyHostname(sslsock, host.getHostName(), context);
        return sock;
    } else
        return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context);
}

From source file:nl.nn.adapterframework.http.mime.MultipartEntityBuilder.java

public MultipartEntityBuilder addPart(String name, ContentBody contentBody) {
    Args.notNull(name, "Name");
    Args.notNull(contentBody, "Content body");
    return addPart(FormBodyPartBuilder.create(name, contentBody).build());
}