KEYCLOAK-7400 Remove dead code
This commit can only be merged once the Camel 2.21.2 would be released, otherwise the code won't compile due to missing dependencies. See https://issues.apache.org/jira/browse/CAMEL-12514 for details.
This commit is contained in:
parent
c4b375c1fc
commit
c8bc0d6d7b
2 changed files with 3 additions and 142 deletions
|
@ -87,12 +87,12 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-undertow</artifactId>
|
||||
<version>2.21.0</version>
|
||||
<version>2.21.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-core</artifactId>
|
||||
<version>2.21.0</version>
|
||||
<version>2.21.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -19,20 +19,9 @@ package org.keycloak.adapters.camel.undertow;
|
|||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Consumer;
|
||||
import org.apache.camel.Processor;
|
||||
import org.apache.camel.component.undertow.RestUndertowHttpBinding;
|
||||
import org.apache.camel.component.undertow.UndertowComponent;
|
||||
import org.apache.camel.component.undertow.UndertowEndpoint;
|
||||
import org.apache.camel.spi.RestConfiguration;
|
||||
import org.apache.camel.util.FileUtil;
|
||||
import org.apache.camel.util.HostUtils;
|
||||
import org.apache.camel.util.ObjectHelper;
|
||||
import org.apache.camel.util.URISupport;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -52,136 +41,8 @@ public class UndertowKeycloakComponent extends UndertowComponent {
|
|||
return new UndertowKeycloakEndpoint(endpointUri.toString(), component);
|
||||
}
|
||||
|
||||
// TODO: uncomment line below after backport of https://issues.apache.org/jira/browse/CAMEL-12514 into fuse
|
||||
// @Override
|
||||
@Override
|
||||
protected String getComponentName() {
|
||||
return "undertow-keycloak";
|
||||
}
|
||||
|
||||
// TODO: remove all below this line after backport of https://issues.apache.org/jira/browse/CAMEL-12514 into fuse
|
||||
@Override
|
||||
public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
|
||||
String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters) throws Exception {
|
||||
return doCreateConsumer(camelContext, processor, verb, basePath, uriTemplate, consumes, produces, configuration, parameters, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Consumer createApiConsumer(CamelContext camelContext, Processor processor, String contextPath,
|
||||
RestConfiguration configuration, Map<String, Object> parameters) throws Exception {
|
||||
// reuse the createConsumer method we already have. The api need to use GET and match on uri prefix
|
||||
return doCreateConsumer(camelContext, processor, "GET", contextPath, null, null, null, configuration, parameters, true);
|
||||
}
|
||||
|
||||
Consumer doCreateConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
|
||||
String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters, boolean api) throws Exception {
|
||||
String path = basePath;
|
||||
if (uriTemplate != null) {
|
||||
// make sure to avoid double slashes
|
||||
if (uriTemplate.startsWith("/")) {
|
||||
path = path + uriTemplate;
|
||||
} else {
|
||||
path = path + "/" + uriTemplate;
|
||||
}
|
||||
}
|
||||
path = FileUtil.stripLeadingSeparator(path);
|
||||
String scheme = "http";
|
||||
String host = "";
|
||||
int port = 0;
|
||||
|
||||
RestConfiguration config = configuration;
|
||||
if (config == null) {
|
||||
config = camelContext.getRestConfiguration(getComponentName(), true);
|
||||
}
|
||||
if (config.getScheme() != null) {
|
||||
scheme = config.getScheme();
|
||||
}
|
||||
if (config.getHost() != null) {
|
||||
host = config.getHost();
|
||||
}
|
||||
int num = config.getPort();
|
||||
if (num > 0) {
|
||||
port = num;
|
||||
}
|
||||
|
||||
// prefix path with context-path if configured in rest-dsl configuration
|
||||
String contextPath = config.getContextPath();
|
||||
if (ObjectHelper.isNotEmpty(contextPath)) {
|
||||
contextPath = FileUtil.stripTrailingSeparator(contextPath);
|
||||
contextPath = FileUtil.stripLeadingSeparator(contextPath);
|
||||
if (ObjectHelper.isNotEmpty(contextPath)) {
|
||||
path = contextPath + "/" + path;
|
||||
}
|
||||
}
|
||||
|
||||
// if no explicit hostname set then resolve the hostname
|
||||
if (ObjectHelper.isEmpty(host)) {
|
||||
if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
|
||||
host = "0.0.0.0";
|
||||
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
|
||||
host = HostUtils.getLocalHostName();
|
||||
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
|
||||
host = HostUtils.getLocalIp();
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
// build query string, and append any endpoint configuration properties
|
||||
if (config.getComponent() == null || config.getComponent().equals(getComponentName())) {
|
||||
// setup endpoint options
|
||||
if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
|
||||
map.putAll(config.getEndpointProperties());
|
||||
}
|
||||
}
|
||||
|
||||
boolean explicitOptions = true;
|
||||
// must use upper case for restrict
|
||||
String restrict = verb.toUpperCase(Locale.US);
|
||||
// allow OPTIONS in rest-dsl to allow clients to call the API and have responses with ALLOW headers
|
||||
if (!restrict.contains("OPTIONS")) {
|
||||
restrict += ",OPTIONS";
|
||||
// this is not an explicit OPTIONS path in the rest-dsl
|
||||
explicitOptions = false;
|
||||
}
|
||||
|
||||
boolean cors = config.isEnableCORS();
|
||||
if (cors) {
|
||||
// allow HTTP Options as we want to handle CORS in rest-dsl
|
||||
map.put("optionsEnabled", "true");
|
||||
} else if (explicitOptions) {
|
||||
// the rest-dsl is using OPTIONS
|
||||
map.put("optionsEnabled", "true");
|
||||
}
|
||||
|
||||
String query = URISupport.createQueryString(map);
|
||||
|
||||
String url;
|
||||
if (api) {
|
||||
url = getComponentName() + ":%s://%s:%s/%s?matchOnUriPrefix=true&httpMethodRestrict=%s";
|
||||
} else {
|
||||
url = getComponentName() + ":%s://%s:%s/%s?matchOnUriPrefix=false&httpMethodRestrict=%s";
|
||||
}
|
||||
|
||||
// get the endpoint
|
||||
url = String.format(url, scheme, host, port, path, restrict);
|
||||
|
||||
if (!query.isEmpty()) {
|
||||
url = url + "&" + query;
|
||||
}
|
||||
|
||||
UndertowEndpoint endpoint = camelContext.getEndpoint(url, UndertowEndpoint.class);
|
||||
setProperties(camelContext, endpoint, parameters);
|
||||
|
||||
if (!map.containsKey("undertowHttpBinding")) {
|
||||
// use the rest binding, if not using a custom http binding
|
||||
endpoint.setUndertowHttpBinding(new RestUndertowHttpBinding());
|
||||
}
|
||||
|
||||
// configure consumer properties
|
||||
Consumer consumer = endpoint.createConsumer(processor);
|
||||
if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
|
||||
setProperties(camelContext, consumer, config.getConsumerProperties());
|
||||
}
|
||||
|
||||
return consumer;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue