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));
}
}
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();
};
}
}
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;
}
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");
}
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);
}
}
Aggregations