Skip to content

Commit

Permalink
Fix apache#184 Leverage platform http service
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Oct 1, 2019
1 parent 9843061 commit 7c292eb
Show file tree
Hide file tree
Showing 25 changed files with 1,432 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* `camel-quarkus-microprofile-metrics`
* `camel-quarkus-netty-http`
* `camel-quarkus-paho`
* `camel-quarkus-platform-http`
* `camel-quarkus-rest`
* `camel-quarkus-salesforce`
* `camel-quarkus-servlet`
Expand Down
96 changes: 96 additions & 0 deletions extensions/platform-http/component/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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.2.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>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>apt</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-package-maven-plugin</artifactId>
<version>${camel.version}</version>
<configuration>
<failFast>false</failFast>
</configuration>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>prepare-components</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>${jandex-maven-plugin.version}</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
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);
}

}
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() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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.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.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;

@UriParam(label = "consumer", description = "A comma separated list of HTTP methods to serve, e.g. GET,POST ."
+ " 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);
path = remaining;
}

@Override
public Producer createProducer() throws Exception {
throw new UnsupportedOperationException("Producer is not supported");
}

@Override
public Consumer createConsumer(Processor processor) throws Exception {
return platformHttpEngine.createConsumer(this, processor);
}

@Override
public HeaderFilterStrategy getHeaderFilterStrategy() {
return headerFilterStrategy;
}

@Override
public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
this.headerFilterStrategy = headerFilterStrategy;
}

public String getPath() {
return path;
}

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;
}

@Override
protected void doStart() throws Exception {
super.doStart();
if (platformHttpEngine == null) {
platformHttpEngine = getCamelContext().getRegistry()
.lookupByNameAndType(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, PlatformHttpEngine.class);
if (platformHttpEngine == null) {
throw new IllegalStateException(PlatformHttpEngine.class.getSimpleName() + " neither set on this "
+ PlatformHttpEndpoint.class.getSimpleName() + " neither found in Camel Registry.");
}
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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;

/**
* A copy of {@code org.apache.camel.http.common.HttpHeaderFilterStrategy}. Keep in sync or refactor
* {@code camel-http-common} not to depend on {@code javax.servlet-api} and then use the {@code HttpHeaderFilterStrategy}
* from there.
*/
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]*");
}
}

0 comments on commit 7c292eb

Please sign in to comment.