Search in sources :

Example 76 with URISyntaxException

use of java.net.URISyntaxException in project XobotOS by xamarin.

the class ProxySelectorRoutePlanner method determineProxy.

/**
     * Determines a proxy for the given target.
     *
     * @param target    the planned target, never <code>null</code>
     * @param request   the request to be sent, never <code>null</code>
     * @param context   the context, or <code>null</code>
     *
     * @return  the proxy to use, or <code>null</code> for a direct route
     *
     * @throws HttpException
     *         in case of system proxy settings that cannot be handled
     */
protected HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
    // the proxy selector can be 'unset', so we better deal with null here
    ProxySelector psel = this.proxySelector;
    if (psel == null)
        psel = ProxySelector.getDefault();
    if (psel == null)
        return null;
    URI targetURI = null;
    try {
        targetURI = new URI(target.toURI());
    } catch (URISyntaxException usx) {
        throw new HttpException("Cannot convert host to URI: " + target, usx);
    }
    List<Proxy> proxies = psel.select(targetURI);
    Proxy p = chooseProxy(proxies, target, request, context);
    HttpHost result = null;
    if (p.type() == Proxy.Type.HTTP) {
        // convert the socket address to an HttpHost
        if (!(p.address() instanceof InetSocketAddress)) {
            throw new HttpException("Unable to handle non-Inet proxy address: " + p.address());
        }
        final InetSocketAddress isa = (InetSocketAddress) p.address();
        // assume default scheme (http)
        result = new HttpHost(getHost(isa), isa.getPort());
    }
    return result;
}
Also used : ProxySelector(java.net.ProxySelector) Proxy(java.net.Proxy) HttpHost(org.apache.http.HttpHost) InetSocketAddress(java.net.InetSocketAddress) HttpException(org.apache.http.HttpException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 77 with URISyntaxException

use of java.net.URISyntaxException in project XobotOS by xamarin.

the class DefaultRedirectHandler method getLocationURI.

public URI getLocationURI(final HttpResponse response, final HttpContext context) throws ProtocolException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    //get the location header to find out where to redirect to
    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");
    }
    String location = locationHeader.getValue();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Redirect requested to location '" + location + "'");
    }
    URI uri;
    try {
        uri = new URI(location);
    } catch (URISyntaxException ex) {
        throw new ProtocolException("Invalid redirect URI: " + location, ex);
    }
    HttpParams params = response.getParams();
    // Location       = "Location" ":" absoluteURI
    if (!uri.isAbsolute()) {
        if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) {
            throw new ProtocolException("Relative redirect location '" + uri + "' not allowed");
        }
        // Adjust location URI
        HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        if (target == null) {
            throw new IllegalStateException("Target host not available " + "in the HTTP context");
        }
        HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        try {
            URI requestURI = new URI(request.getRequestLine().getUri());
            URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        } catch (URISyntaxException ex) {
            throw new ProtocolException(ex.getMessage(), ex);
        }
    }
    if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {
        RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(REDIRECT_LOCATIONS);
        if (redirectLocations == null) {
            redirectLocations = new RedirectLocations();
            context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
        }
        URI redirectURI;
        if (uri.getFragment() != null) {
            try {
                HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
                redirectURI = URIUtils.rewriteURI(uri, target, true);
            } catch (URISyntaxException ex) {
                throw new ProtocolException(ex.getMessage(), ex);
            }
        } else {
            redirectURI = uri;
        }
        if (redirectLocations.contains(redirectURI)) {
            throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'");
        } else {
            redirectLocations.add(redirectURI);
        }
    }
    return uri;
}
Also used : HttpRequest(org.apache.http.HttpRequest) ProtocolException(org.apache.http.ProtocolException) CircularRedirectException(org.apache.http.client.CircularRedirectException) HttpParams(org.apache.http.params.HttpParams) Header(org.apache.http.Header) HttpHost(org.apache.http.HttpHost) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 78 with URISyntaxException

use of java.net.URISyntaxException in project XobotOS by xamarin.

the class DefaultRequestDirector method rewriteRequestURI.

protected void rewriteRequestURI(final RequestWrapper request, final HttpRoute route) throws ProtocolException {
    try {
        URI uri = request.getURI();
        if (route.getProxyHost() != null && !route.isTunnelled()) {
            // Make sure the request URI is absolute
            if (!uri.isAbsolute()) {
                HttpHost target = route.getTargetHost();
                uri = URIUtils.rewriteURI(uri, target);
                request.setURI(uri);
            }
        } else {
            // Make sure the request URI is relative
            if (uri.isAbsolute()) {
                uri = URIUtils.rewriteURI(uri, null);
                request.setURI(uri);
            }
        }
    } catch (URISyntaxException ex) {
        throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex);
    }
}
Also used : ProtocolException(org.apache.http.ProtocolException) HttpHost(org.apache.http.HttpHost) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 79 with URISyntaxException

use of java.net.URISyntaxException in project platformlayer by platformlayer.

the class JdbcConfiguration method buildSimple.

private static JdbcConfiguration buildSimple(Configuration configuration, String key) {
    String value = configuration.find(key);
    if (value == null) {
        throw new IllegalStateException("Must define environment variable: " + key);
    }
    URI dbUri;
    try {
        dbUri = new URI(value);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Error parsing database environment variable: " + key, e);
    }
    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String jdbcUrl = "jdbc:postgresql://" + dbUri.getHost() + dbUri.getPath() + ":" + dbUri.getPort();
    String driverClassName = org.postgresql.Driver.class.getName();
    Map<String, String> extraProperties = Maps.newHashMap();
    // Properties extraProperties = System.getProperties();
    JdbcConfiguration jdbcConfig = new JdbcConfiguration(jdbcUrl, username, password, driverClassName, extraProperties);
    return jdbcConfig;
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 80 with URISyntaxException

use of java.net.URISyntaxException in project powermock by powermock.

the class AgentInitialization method getPathToJarFileContainingThisClass.

private String getPathToJarFileContainingThisClass() {
    CodeSource codeSource = AgentInitialization.class.getProtectionDomain().getCodeSource();
    if (codeSource == null) {
        return null;
    }
    // URI is needed to deal with spaces and non-ASCII characters
    URI jarFileURI;
    try {
        jarFileURI = codeSource.getLocation().toURI();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    return new File(jarFileURI).getPath();
}
Also used : URISyntaxException(java.net.URISyntaxException) CodeSource(java.security.CodeSource) URI(java.net.URI) File(java.io.File)

Aggregations

URISyntaxException (java.net.URISyntaxException)1633 URI (java.net.URI)1080 IOException (java.io.IOException)451 URL (java.net.URL)287 File (java.io.File)280 ArrayList (java.util.ArrayList)146 MalformedURLException (java.net.MalformedURLException)102 InputStream (java.io.InputStream)93 HashMap (java.util.HashMap)91 Test (org.testng.annotations.Test)88 Response (javax.ws.rs.core.Response)87 Builder (javax.ws.rs.client.Invocation.Builder)84 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)84 Parameters (org.testng.annotations.Parameters)84 BaseTest (org.xdi.oxauth.BaseTest)84 ResponseType (org.xdi.oxauth.model.common.ResponseType)84 AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)78 Test (org.junit.Test)75 REGISTRATION_CLIENT_URI (org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI)72 Intent (android.content.Intent)63