forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix apache#184 Leverage platform http service
- Loading branch information
Showing
24 changed files
with
1,383 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-platform-http-parent</artifactId> | ||
<version>0.1.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>camel-quarkus-platform-http-component</artifactId> | ||
<name>Camel Quarkus :: Platform HTTP :: Component</name> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-bom</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>camel-support</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>spi-annotations</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
45 changes: 45 additions & 0 deletions
45
...mponent/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.Endpoint; | ||
import org.apache.camel.spi.annotations.Component; | ||
import org.apache.camel.support.DefaultComponent; | ||
|
||
/** | ||
* Exposes HTTP endpoints leveraging the given platform's (SpringBoot, WildFly, Quarkus, ...) HTTP server. | ||
*/ | ||
@Component("platform-http") | ||
public class PlatformHttpComponent extends DefaultComponent { | ||
|
||
public PlatformHttpComponent() { | ||
super(); | ||
} | ||
|
||
public PlatformHttpComponent(CamelContext context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { | ||
return new PlatformHttpEndpoint(uri, remaining, this); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...mponent/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http; | ||
|
||
public final class PlatformHttpConstants { | ||
|
||
public static final String PLATFORM_HTTP_COMPONENT_NAME = "platform-http"; | ||
public static final String PLATFORM_HTTP_ENGINE_NAME = "platformHttpEngine"; | ||
|
||
private PlatformHttpConstants() { | ||
} | ||
|
||
} |
132 changes: 132 additions & 0 deletions
132
...omponent/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
import org.apache.camel.AsyncEndpoint; | ||
import org.apache.camel.Component; | ||
import org.apache.camel.Consumer; | ||
import org.apache.camel.Processor; | ||
import org.apache.camel.Producer; | ||
import org.apache.camel.component.platform.http.spi.Method; | ||
import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; | ||
import org.apache.camel.spi.HeaderFilterStrategy; | ||
import org.apache.camel.spi.HeaderFilterStrategyAware; | ||
import org.apache.camel.spi.UriEndpoint; | ||
import org.apache.camel.spi.UriParam; | ||
import org.apache.camel.support.DefaultEndpoint; | ||
|
||
@UriEndpoint(/* firstVersion = "3.?.0", */ scheme = "platform-http", title = "Platform HTTP", syntax = "platform-http:[methods:]path", label = "http") | ||
public class PlatformHttpEndpoint extends DefaultEndpoint implements AsyncEndpoint, HeaderFilterStrategyAware { | ||
|
||
private final String path; | ||
private final Set<Method> methods; | ||
|
||
@UriParam(label = "consumer", description = "A comma separated list of HTTP methods to serve. This list will be merged with the methods specified in the URI path. E.g. platform-http:GET,POST:/path?httpMethodRestrict=PUT,DELETE will effectivelly result in GET,POST,PUT,DELETE. If no methods are specified, all methods will be served.") | ||
private String httpMethodRestrict; | ||
|
||
@UriParam(label = "advanced") | ||
private PlatformHttpEngine platformHttpEngine; | ||
|
||
@UriParam(label = "advanced") | ||
private HeaderFilterStrategy headerFilterStrategy = new PlatformHttpHeaderFilterStrategy(); | ||
|
||
public PlatformHttpEndpoint(String uri, String remaining, Component component) { | ||
super(uri, component); | ||
|
||
final String[] remainingParts = remaining.split(":"); | ||
switch (remainingParts.length) { | ||
case 1: | ||
path = remaining; | ||
methods = null; | ||
break; | ||
case 2: | ||
methods = Method.parseList(remainingParts[0]); | ||
path = remainingParts[1]; | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Expected a path or two segments delimited by ':'; found " + remaining); | ||
} | ||
} | ||
|
||
@Override | ||
public Producer createProducer() throws Exception { | ||
throw new UnsupportedOperationException("Producer is not supported"); | ||
} | ||
|
||
@Override | ||
public Consumer createConsumer(Processor processor) throws Exception { | ||
if (platformHttpEngine == null) { | ||
platformHttpEngine = getCamelContext().getRegistry() | ||
.lookupByNameAndType(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, PlatformHttpEngine.class); | ||
} | ||
return platformHttpEngine.createConsumer(this, processor); | ||
} | ||
|
||
public Set<Method> getEffectiveMethods() { | ||
if (methods == null) { | ||
return Method.parseList(getHttpMethodRestrict()); | ||
} else { | ||
final String mr = getHttpMethodRestrict(); | ||
if (mr == null || mr.isEmpty()) { | ||
return methods; | ||
} else { | ||
final Set<Method> result = new TreeSet<>(methods); | ||
result.addAll(Method.parseList(getHttpMethodRestrict())); | ||
return Collections.unmodifiableSet(result); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public HeaderFilterStrategy getHeaderFilterStrategy() { | ||
return headerFilterStrategy; | ||
} | ||
|
||
@Override | ||
public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) { | ||
this.headerFilterStrategy = headerFilterStrategy; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public Set<Method> getMethods() { | ||
return methods; | ||
} | ||
|
||
public PlatformHttpEngine getPlatformHttpEngine() { | ||
return platformHttpEngine; | ||
} | ||
|
||
public void setPlatformHttpEngine(PlatformHttpEngine platformHttpEngine) { | ||
this.platformHttpEngine = platformHttpEngine; | ||
} | ||
|
||
public String getHttpMethodRestrict() { | ||
return httpMethodRestrict; | ||
} | ||
|
||
public void setHttpMethodRestrict(String httpMethodRestrict) { | ||
this.httpMethodRestrict = httpMethodRestrict; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
.../main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http; | ||
|
||
import org.apache.camel.support.DefaultHeaderFilterStrategy; | ||
|
||
public class PlatformHttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy { | ||
|
||
public PlatformHttpHeaderFilterStrategy() { | ||
initialize(); | ||
} | ||
|
||
protected void initialize() { | ||
getOutFilter().add("content-length"); | ||
getOutFilter().add("content-type"); | ||
getOutFilter().add("host"); | ||
// Add the filter for the Generic Message header | ||
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5 | ||
getOutFilter().add("cache-control"); | ||
getOutFilter().add("connection"); | ||
getOutFilter().add("date"); | ||
getOutFilter().add("pragma"); | ||
getOutFilter().add("trailer"); | ||
getOutFilter().add("transfer-encoding"); | ||
getOutFilter().add("upgrade"); | ||
getOutFilter().add("via"); | ||
getOutFilter().add("warning"); | ||
|
||
setLowerCase(true); | ||
|
||
// filter headers begin with "Camel" or "org.apache.camel" | ||
// must ignore case for Http based transports | ||
setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*"); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...orm-http/component/src/main/java/org/apache/camel/component/platform/http/spi/Method.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http.spi; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
/** | ||
* An HTTP method. | ||
*/ | ||
public enum Method { | ||
GET(false), HEAD(false), POST(true), PUT(true), DELETE(false), TRACE(false), OPTIONS(false), CONNECT(false), PATCH( | ||
true); | ||
private static final Set<Method> ALL = Collections.unmodifiableSet(new TreeSet<>(Arrays.asList(values()))); | ||
private final boolean canHaveBody; | ||
|
||
private Method(boolean canHaveBody) { | ||
this.canHaveBody = canHaveBody; | ||
} | ||
|
||
public static Set<Method> getAll() { | ||
return ALL; | ||
} | ||
|
||
/** | ||
* @return {@code true} if HTTP requests with this {@link Method} can have a body; {@code false} otherwise | ||
*/ | ||
public boolean canHaveBody() { | ||
return canHaveBody; | ||
} | ||
|
||
/** | ||
* Parse the given comma separated {@code methodList} to a {@link Set} of {@link Method}s. If {@code methodList} is | ||
* empty or {@code null} returns {@link #ALL}. | ||
* | ||
* @param methodList a comma separated list of HTTP method names. | ||
* @return a {@link Set} of {@link Method}s | ||
*/ | ||
public static Set<Method> parseList(String methodList) { | ||
if (methodList == null) { | ||
return ALL; | ||
} | ||
methodList = methodList.toUpperCase(Locale.ROOT); | ||
String[] methods = methodList.split(","); | ||
if (methods.length == 0) { | ||
return ALL; | ||
} else if (methods.length == 1) { | ||
return Collections.singleton(Method.valueOf(methods[0])); | ||
} else { | ||
Set<Method> result = new TreeSet<>(); | ||
for (String method : methods) { | ||
result.add(Method.valueOf(method.trim())); | ||
} | ||
return ALL.equals(result) ? ALL : Collections.unmodifiableSet(result); | ||
} | ||
} | ||
} |
Oops, something went wrong.