Search in sources :

Example 46 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class DefaultRestClient method apexCall.

@Override
public void apexCall(String httpMethod, String apexUrl, Map<String, Object> queryParams, InputStream requestDto, ResponseCallback callback) {
    // create APEX call request
    final Request request;
    try {
        request = getRequest(httpMethod, apexCallUrl(apexUrl, queryParams));
        // set request SObject and content type
        if (requestDto != null) {
            request.content(new InputStreamContentProvider(requestDto));
            request.header(HttpHeader.CONTENT_TYPE, PayloadFormat.JSON.equals(format) ? APPLICATION_JSON_UTF8 : APPLICATION_XML_UTF8);
        }
        // requires authorization token
        setAccessToken(request);
        doHttpRequest(request, new DelegatingClientCallback(callback));
    } catch (UnsupportedEncodingException e) {
        String msg = "Unexpected error: " + e.getMessage();
        callback.onResponse(null, new SalesforceException(msg, e));
    } catch (URISyntaxException e) {
        String msg = "Unexpected error: " + e.getMessage();
        callback.onResponse(null, new SalesforceException(msg, e));
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Request(org.eclipse.jetty.client.api.Request) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InputStreamContentProvider(org.eclipse.jetty.client.util.InputStreamContentProvider) URISyntaxException(java.net.URISyntaxException)

Example 47 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class DefaultConnectorComponent method getVerifier.

@SuppressWarnings("unchecked")
@Override
public ComponentVerifier getVerifier() {
    final String scheme = model.getBaseScheme();
    final Component component = getCamelContext().getComponent(scheme);
    if (component instanceof VerifiableComponent) {
        return (scope, map) -> {
            Map<String, Object> options;
            try {
                // A little nasty hack required as verifier uses Map<String, Object>
                // to be compatible with all the methods in CamelContext whereas
                // catalog deals with Map<String, String>
                options = (Map) buildEndpointOptions(null, map);
            } catch (URISyntaxException e) {
                // and stop the validation step.
                return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.OK, scope).error(ResultErrorBuilder.withException(e).build()).build();
            }
            return ((VerifiableComponent) component).getVerifier().verify(scope, options);
        };
    } else {
        return (scope, map) -> {
            return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.UNSUPPORTED, scope).error(ResultErrorBuilder.withCode("unsupported").attribute("camel.connector.name", getConnectorName()).attribute("camel.component.name", getComponentName()).build()).build();
        };
    }
}
Also used : Logger(org.slf4j.Logger) ComponentVerifier(org.apache.camel.ComponentVerifier) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder) Component(org.apache.camel.Component) Endpoint(org.apache.camel.Endpoint) VerifiableComponent(org.apache.camel.VerifiableComponent) DefaultCamelCatalog(org.apache.camel.catalog.DefaultCamelCatalog) Constructor(java.lang.reflect.Constructor) LinkedHashMap(java.util.LinkedHashMap) CamelCatalog(org.apache.camel.catalog.CamelCatalog) IntrospectionSupport(org.apache.camel.util.IntrospectionSupport) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) ResultErrorBuilder(org.apache.camel.impl.verifier.ResultErrorBuilder) DefaultComponent(org.apache.camel.impl.DefaultComponent) URISyntaxException(java.net.URISyntaxException) Component(org.apache.camel.Component) VerifiableComponent(org.apache.camel.VerifiableComponent) DefaultComponent(org.apache.camel.impl.DefaultComponent) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) VerifiableComponent(org.apache.camel.VerifiableComponent)

Example 48 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class NettyHttpHelper method createURL.

/**
     * Creates the URL to invoke.
     *
     * @param exchange the exchange
     * @param endpoint the endpoint
     * @return the URL to invoke
     */
public static String createURL(Exchange exchange, NettyHttpEndpoint endpoint) throws URISyntaxException {
    String uri = endpoint.getEndpointUri();
    // resolve placeholders in uri
    try {
        uri = exchange.getContext().resolvePropertyPlaceholders(uri);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
    }
    // append HTTP_PATH to HTTP_URI if it is provided in the header
    String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
    // NOW the HTTP_PATH is just related path, we don't need to trim it
    if (path != null) {
        if (path.startsWith("/")) {
            path = path.substring(1);
        }
        if (path.length() > 0) {
            // inject the dynamic path before the query params, if there are any
            int idx = uri.indexOf("?");
            // if there are no query params
            if (idx == -1) {
                // make sure that there is exactly one "/" between HTTP_URI and HTTP_PATH
                uri = uri.endsWith("/") ? uri : uri + "/";
                uri = uri.concat(path);
            } else {
                // there are query params, so inject the relative path in the right place
                String base = uri.substring(0, idx);
                base = base.endsWith("/") ? base : base + "/";
                base = base.concat(path);
                uri = base.concat(uri.substring(idx));
            }
        }
    }
    // ensure uri is encoded to be valid
    uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);
    return uri;
}
Also used : RuntimeExchangeException(org.apache.camel.RuntimeExchangeException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RuntimeExchangeException(org.apache.camel.RuntimeExchangeException)

Example 49 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class RestSwaggerEndpoint method determineHost.

String determineHost(final Swagger swagger) {
    if (isNotEmpty(host)) {
        return host;
    }
    final String componentHost = component().getHost();
    if (isNotEmpty(componentHost)) {
        return componentHost;
    }
    final String swaggerScheme = pickBestScheme(specificationUri.getScheme(), swagger.getSchemes());
    final String swaggerHost = swagger.getHost();
    if (isNotEmpty(swaggerScheme) && isNotEmpty(swaggerHost)) {
        return swaggerScheme + "://" + swaggerHost;
    }
    final CamelContext camelContext = getCamelContext();
    final RestConfiguration specificRestConfiguration = camelContext.getRestConfiguration(assignedComponentName, false);
    final String specificConfigurationHost = hostFrom(specificRestConfiguration);
    if (specificConfigurationHost != null) {
        return specificConfigurationHost;
    }
    final RestConfiguration componentRestConfiguration = camelContext.getRestConfiguration("rest-swagger", false);
    final String componentConfigurationHost = hostFrom(componentRestConfiguration);
    if (componentConfigurationHost != null) {
        return componentConfigurationHost;
    }
    final RestConfiguration globalRestConfiguration = camelContext.getRestConfiguration();
    final String globalConfigurationHost = hostFrom(globalRestConfiguration);
    if (globalConfigurationHost != null) {
        return globalConfigurationHost;
    }
    final String specificationScheme = specificationUri.getScheme();
    if (specificationUri.isAbsolute() && specificationScheme.toLowerCase().startsWith("http")) {
        try {
            return new URI(specificationUri.getScheme(), specificationUri.getUserInfo(), specificationUri.getHost(), specificationUri.getPort(), null, null, null).toString();
        } catch (final URISyntaxException e) {
            throw new IllegalStateException("Unable to create a new URI from: " + specificationUri, e);
        }
    }
    final boolean areTheSame = "rest-swagger".equals(assignedComponentName);
    throw new IllegalStateException("Unable to determine destionation host for requests. The Swagger specification" + " does not specify `scheme` and `host` parameters, the specification URI is not absolute with `http` or" + " `https` scheme, and no RestConfigurations configured with `scheme`, `host` and `port` were found for `" + (areTheSame ? "rest-swagger` component" : assignedComponentName + "` or `rest-swagger` components") + " and there is no global RestConfiguration with those properties");
}
Also used : CamelContext(org.apache.camel.CamelContext) RestConfiguration(org.apache.camel.spi.RestConfiguration) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 50 with URISyntaxException

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

the class InferringPublicAddress method get.

@Override
public URI get() {
    Request request = Execution.current().maybeGet(Request.class).orElseThrow(() -> new IllegalStateException("Inferring the public address is only supported during a request execution."));
    String scheme = determineScheme(request);
    String host;
    int port;
    HostAndPort forwardedHostData = getForwardedHostData(request);
    if (forwardedHostData != null) {
        host = forwardedHostData.getHostText();
        port = forwardedHostData.getPortOrDefault(-1);
    } else {
        URI absoluteRequestURI = getAbsoluteRequestUri(request);
        if (absoluteRequestURI != null) {
            host = absoluteRequestURI.getHost();
            port = absoluteRequestURI.getPort();
        } else {
            HostAndPort hostData = getHostData(request);
            if (hostData != null) {
                host = hostData.getHostText();
                port = hostData.getPortOrDefault(-1);
            } else {
                HostAndPort localAddress = request.getLocalAddress();
                host = localAddress.getHostText();
                port = ProtocolUtil.isDefaultPortForScheme(localAddress.getPort(), scheme) ? -1 : localAddress.getPort();
            }
        }
    }
    try {
        return new URI(scheme, null, host, port, null, null, null);
    } catch (URISyntaxException ex) {
        throw Exceptions.uncheck(ex);
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Request(ratpack.http.Request) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

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