This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push: new 8b5ec9bdc5f CAMEL-19177: camel-platform-http - Spring Boot implementation that use directly the HTTP server (#793) 8b5ec9bdc5f is described below commit 8b5ec9bdc5f8da04e130d516800d5897f79e3098 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Mar 22 08:55:18 2023 +0100 CAMEL-19177: camel-platform-http - Spring Boot implementation that use directly the HTTP server (#793) --- .../camel-platform-http-starter/pom.xml | 5 +- .../springboot/CamelRequestHandlerMapping.java | 113 ++++++++++++++++ .../http/springboot/PlatformHttpMessage.java | 107 +++++++++++++++ .../http/springboot/ServletPlatformHttpEngine.java | 48 ------- ...> SpringBootPlatformHttpAutoConfiguration.java} | 38 +++--- .../springboot/SpringBootPlatformHttpBinding.java | 50 +++++++ .../SpringBootPlatformHttpConstants.java} | 12 +- .../springboot/SpringBootPlatformHttpConsumer.java | 143 ++++++++++++++++++++ .../springboot/SpringBootPlatformHttpEngine.java} | 8 +- ...rk.boot.autoconfigure.AutoConfiguration.imports | 2 +- .../JettyCustomPlatformHttpConsumer.java | 130 ------------------ .../platform/http/springboot/JettyServerTest.java | 53 -------- ...PlatformHttpBase.java => PlatformHttpBase.java} | 6 +- .../platform/http/springboot/PlatformHttpTest.java | 145 --------------------- ...stPlatformHttpContextPathConfigurationTest.java | 130 ------------------ ...java => SpringBootPlatformHttpRestDSLTest.java} | 19 ++- ...tpTest.java => SpringBootPlatformHttpTest.java} | 17 +-- 17 files changed, 461 insertions(+), 565 deletions(-) diff --git a/components-starter/camel-platform-http-starter/pom.xml b/components-starter/camel-platform-http-starter/pom.xml index 418f26d4a46..79127a611eb 100644 --- a/components-starter/camel-platform-http-starter/pom.xml +++ b/components-starter/camel-platform-http-starter/pom.xml @@ -40,15 +40,14 @@ <version>${camel-version}</version> </dependency> <dependency> - <groupId>org.apache.camel.springboot</groupId> - <artifactId>camel-servlet-starter</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-http-common</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring-boot-version}</version> - <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> diff --git a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/CamelRequestHandlerMapping.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/CamelRequestHandlerMapping.java new file mode 100644 index 00000000000..7d6bb54adc4 --- /dev/null +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/CamelRequestHandlerMapping.java @@ -0,0 +1,113 @@ +/* + * 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.springboot; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.apache.camel.component.platform.http.HttpEndpointModel; +import org.apache.camel.component.platform.http.PlatformHttpComponent; +import org.apache.camel.component.platform.http.PlatformHttpEndpoint; +import org.apache.camel.component.platform.http.PlatformHttpListener; +import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; +import org.apache.camel.util.ReflectionHelper; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.mvc.method.RequestMappingInfo; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; +import org.springframework.web.util.ServletRequestPathUtils; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CamelRequestHandlerMapping extends RequestMappingHandlerMapping implements PlatformHttpListener { + + private final PlatformHttpComponent component; + private final PlatformHttpEngine engine; + private final Map<String, RequestMappingInfo> mappings = new HashMap<>(); + + public CamelRequestHandlerMapping(PlatformHttpComponent component, PlatformHttpEngine engine) { + this.component = component; + this.engine = engine; + this.component.addPlatformHttpListener(this); + } + + @Override + public int getOrder() { + return -1; + } + + @Override + protected String[] getCandidateBeanNames() { + // no candidates + return new String[]{}; + } + + @Override + protected boolean isHandler(Class<?> beanType) { + return false; + } + + @Override + protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { + // not in use as we do not use class scanning but Camel platform-http component + return null; + } + + @Override + protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception { + ServletRequestPathUtils.parseAndCache(request); + return super.getHandlerInternal(request); + } + + @Override + public void registerHttpEndpoint(HttpEndpointModel model) { + RequestMappingInfo info = asRequestMappingInfo(model); + Method m = ReflectionHelper.findMethod(SpringBootPlatformHttpConsumer.class, "service", HttpServletRequest.class, HttpServletResponse.class); + registerMapping(info, model.getConsumer(), m); + } + + @Override + public void unregisterHttpEndpoint(HttpEndpointModel model) { + // noop + } + + private RequestMappingInfo asRequestMappingInfo(HttpEndpointModel model) { + // allowed methods from model or endpoint + List<RequestMethod> methods = new ArrayList<>(); + String verbs = model.getVerbs(); + if (verbs == null && model.getConsumer() != null) { + PlatformHttpEndpoint endpoint = (PlatformHttpEndpoint) model.getConsumer().getEndpoint(); + verbs = endpoint.getHttpMethodRestrict(); + } + if (verbs != null) { + for (String v : model.getVerbs().split(",")) { + RequestMethod rm = RequestMethod.resolve(v); + methods.add(rm); + } + } + + RequestMappingInfo info = RequestMappingInfo + .paths(model.getUri()) + .methods(methods.toArray(new RequestMethod[0])) + .options(this.getBuilderConfiguration()).build(); + return info; + } + +} diff --git a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/PlatformHttpMessage.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/PlatformHttpMessage.java new file mode 100644 index 00000000000..5818a70cad1 --- /dev/null +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/PlatformHttpMessage.java @@ -0,0 +1,107 @@ +/* + * 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.springboot; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.apache.camel.Exchange; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.http.common.HttpBinding; +import org.apache.camel.support.DefaultMessage; +import org.apache.camel.util.ObjectHelper; + +import java.io.IOException; + +public class PlatformHttpMessage extends DefaultMessage { + + private HttpServletRequest request; + private HttpServletResponse response; + private HttpBinding binding; + private boolean requestRead; + + public PlatformHttpMessage(Exchange exchange, HttpBinding binding, HttpServletRequest request, HttpServletResponse response) { + super(exchange); + this.init(exchange, binding, request, response); + } + + private PlatformHttpMessage(HttpServletRequest request, HttpServletResponse response, Exchange exchange, HttpBinding binding, boolean requestRead) { + super(exchange); + this.request = request; + this.response = response; + this.binding = binding; + this.requestRead = requestRead; + } + + public void init(Exchange exchange, HttpBinding binding, HttpServletRequest request, HttpServletResponse response) { + this.setExchange(exchange); + this.requestRead = false; + this.binding = binding; + this.request = request; + this.response = response; + this.setHeader("CamelHttpServletRequest", request); + this.setHeader("CamelHttpServletResponse", response); + Boolean flag = (Boolean)exchange.getProperty("CamelSkipWwwFormUrlEncoding", Boolean.class); + if (flag != null && flag) { + this.setHeader("CamelSkipWwwFormUrlEncoding", Boolean.TRUE); + } + + binding.readRequest(request, this); + } + + public void reset() { + super.reset(); + this.request = null; + this.response = null; + this.binding = null; + this.requestRead = false; + } + + public HttpServletRequest getRequest() { + return this.request; + } + + public HttpServletResponse getResponse() { + return this.response; + } + + protected Object createBody() { + if (this.requestRead) { + return null; + } else { + Object body; + try { + body = this.binding.parseBody(request, this); + } catch (IOException var5) { + throw new RuntimeCamelException(var5); + } finally { + this.requestRead = true; + } + + return body; + } + } + + public PlatformHttpMessage newInstance() { + return new PlatformHttpMessage(this.request, this.response, this.getExchange(), this.binding, this.requestRead); + } + + public String toString() { + return "PlatformHttpMessage@" + ObjectHelper.getIdentityHashCode(this); + } + + +} diff --git a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpEngine.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpEngine.java deleted file mode 100644 index db53b753e6f..00000000000 --- a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpEngine.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.springboot; - -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.component.platform.http.PlatformHttpEndpoint; -import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; -import org.apache.camel.component.servlet.ServletComponent; -import org.apache.camel.component.servlet.ServletConsumer; -import org.apache.camel.component.servlet.ServletEndpoint; - -public class ServletPlatformHttpEngine implements PlatformHttpEngine { - - private final ServletComponent servletComponent; - - public ServletPlatformHttpEngine(ServletComponent servletComponent) { - this.servletComponent = servletComponent; - } - - @Override - public Consumer createConsumer(PlatformHttpEndpoint platformHttpEndpoint, Processor processor) { - try { - return new ServletConsumer((ServletEndpoint) servletComponent.createEndpoint(platformHttpEndpoint.getEndpointUri()), processor); - } catch (Exception e) { - throw new IllegalArgumentException("The following endpoint uri " + platformHttpEndpoint.getEndpointUri() + " is not supported", e); - } - } - - @Override - public int getServerPort() { - return PlatformHttpEngine.super.getServerPort(); - } -} diff --git a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpAutoConfiguration.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpAutoConfiguration.java similarity index 57% rename from components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpAutoConfiguration.java rename to components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpAutoConfiguration.java index 7d28d3ccd38..7db3c4b4525 100644 --- a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpAutoConfiguration.java +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpAutoConfiguration.java @@ -17,34 +17,36 @@ package org.apache.camel.component.platform.http.springboot; import org.apache.camel.CamelContext; +import org.apache.camel.component.platform.http.PlatformHttpComponent; import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; -import org.apache.camel.component.servlet.ServletComponent; - +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; -import org.springframework.context.annotation.Lazy; @Configuration(proxyBeanMethods = false) @AutoConfigureAfter(name = { - "org.apache.camel.component.servlet.springboot.ServletComponentAutoConfiguration", - "org.apache.camel.component.servlet.springboot.ServletComponentConverter"}) -public class ServletPlatformHttpAutoConfiguration { + "org.apache.camel.component.servlet.springboot.PlatformHttpComponentAutoConfiguration", + "org.apache.camel.component.servlet.springboot.PlatformHttpComponentConverter"}) +public class SpringBootPlatformHttpAutoConfiguration { + + @Autowired + CamelContext camelContext; - private final CamelContext camelContext; + @Bean(name = "platform-http-engine") + @ConditionalOnMissingBean(PlatformHttpEngine.class) + public PlatformHttpEngine springBootPlatformHttpEngine() { + return new SpringBootPlatformHttpEngine(); + } - public ServletPlatformHttpAutoConfiguration( - CamelContext camelContext) { - this.camelContext = camelContext; - } + @Bean + @DependsOn("configurePlatformHttpComponent") + public CamelRequestHandlerMapping platformHttpEngineRequestMapping(PlatformHttpEngine engine) { + PlatformHttpComponent component = camelContext.getComponent("platform-http", PlatformHttpComponent.class); + CamelRequestHandlerMapping answer = new CamelRequestHandlerMapping(component, engine); + return answer; + } - @Lazy - @Bean(name = "platform-http-engine") - @ConditionalOnMissingBean(PlatformHttpEngine.class) - @DependsOn("configureServletComponent") - public PlatformHttpEngine servletPlatformHttpEngine() { - return new ServletPlatformHttpEngine(camelContext.getComponent("servlet", ServletComponent.class)); - } } diff --git a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpBinding.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpBinding.java new file mode 100644 index 00000000000..4ff0fee0c58 --- /dev/null +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpBinding.java @@ -0,0 +1,50 @@ +/* + * 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.springboot; + +import jakarta.servlet.http.HttpServletRequest; +import org.apache.camel.Message; +import org.apache.camel.component.platform.http.PlatformHttpEndpoint; +import org.apache.camel.http.base.HttpHelper; +import org.apache.camel.http.common.DefaultHttpBinding; + +public class SpringBootPlatformHttpBinding extends DefaultHttpBinding { + + protected void populateRequestParameters(HttpServletRequest request, Message message) { + super.populateRequestParameters(request, message); + String path = request.getRequestURI(); + // skip leading slash + if (path != null && path.startsWith("/")) { + path = path.substring(1); + } + if (path != null) { + PlatformHttpEndpoint endpoint = (PlatformHttpEndpoint) message.getExchange().getFromEndpoint(); + String consumerPath = endpoint.getPath(); + if (consumerPath != null && consumerPath.startsWith("/")) { + consumerPath = consumerPath.substring(1); + } + if (useRestMatching(consumerPath)) { + HttpHelper.evalPlaceholders(message.getHeaders(), path, consumerPath); + } + } + } + + private boolean useRestMatching(String path) { + return path.indexOf('{') > -1; + } + +} diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpEngine.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConstants.java similarity index 64% copy from components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpEngine.java copy to components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConstants.java index fcf83dec539..ec06d4e4975 100644 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpEngine.java +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConstants.java @@ -16,16 +16,10 @@ */ package org.apache.camel.component.platform.http.springboot; -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.component.platform.http.PlatformHttpEndpoint; -import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; +public final class SpringBootPlatformHttpConstants { + public static final String CONTEXT_PATH = "CamelPlatformHttpContextPath"; -public class JettyCustomPlatformHttpEngine implements PlatformHttpEngine { - - @Override - public Consumer createConsumer(PlatformHttpEndpoint platformHttpEndpoint, Processor processor) { - return new JettyCustomPlatformHttpConsumer(platformHttpEndpoint, processor); + private SpringBootPlatformHttpConstants() { } } diff --git a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConsumer.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConsumer.java new file mode 100644 index 00000000000..438a917b6ae --- /dev/null +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConsumer.java @@ -0,0 +1,143 @@ +/* + * 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.springboot; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.Processor; +import org.apache.camel.component.platform.http.PlatformHttpEndpoint; +import org.apache.camel.http.common.DefaultHttpBinding; +import org.apache.camel.http.common.HttpHelper; +import org.apache.camel.support.DefaultConsumer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +public class SpringBootPlatformHttpConsumer extends DefaultConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(SpringBootPlatformHttpConsumer.class); + + private final DefaultHttpBinding binding; + + public SpringBootPlatformHttpConsumer(PlatformHttpEndpoint endpoint, Processor processor) { + super(endpoint, processor); + this.binding = new SpringBootPlatformHttpBinding(); + this.binding.setHeaderFilterStrategy(endpoint.getHeaderFilterStrategy()); + this.binding.setMuteException(endpoint.isMuteException()); + this.binding.setFileNameExtWhitelist(endpoint.getFileNameExtWhitelist()); + } + + @Override + public PlatformHttpEndpoint getEndpoint() { + return (PlatformHttpEndpoint) super.getEndpoint(); + } + + + /** + * This method is invoked by Spring Boot when invoking Camel via platform-http + */ + public void service(HttpServletRequest request, HttpServletResponse response) { + LOG.trace("Service: {}", request); + try { + handleService(request, response); + } catch (Exception e) { + // do not leak exception back to caller + LOG.warn("Error handling request due to: " + e.getMessage(), e); + try { + if (!response.isCommitted()) { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } catch (Exception e1) { + // ignore + } + } + } + + protected void handleService(HttpServletRequest request, HttpServletResponse response) throws Exception { + if (isSuspended()) { + LOG.debug("Consumer suspended, cannot service request: {}", request); + response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); + return; + } + + Exchange exchange = createExchange(true); + exchange.setPattern(ExchangePattern.InOut); + HttpHelper.setCharsetFromContentType(request.getContentType(), exchange); + exchange.setIn(new PlatformHttpMessage(exchange, binding, request, response)); + String contextPath = getEndpoint().getPath(); + exchange.getIn().setHeader(SpringBootPlatformHttpConstants.CONTEXT_PATH, contextPath); + // set context path as header + String httpPath = (String) exchange.getIn().getHeader(Exchange.HTTP_PATH); + // here we just remove the CamelServletContextPath part from the HTTP_PATH + if (contextPath != null + && httpPath.startsWith(contextPath)) { + exchange.getIn().setHeader(Exchange.HTTP_PATH, + httpPath.substring(contextPath.length())); + } + + // TODO: async with CompletionStage returned to spring boot? + + // we want to handle the UoW + try { + createUoW(exchange); + } catch (Exception e) { + throw new ServletException(e); + } + if (LOG.isTraceEnabled()) { + LOG.trace("Processing request for exchangeId: {}", exchange.getExchangeId()); + } + try { + getProcessor().process(exchange); + } catch (Exception e) { + exchange.setException(e); + } finally { + afterProcess(response, exchange, true); + } + } + + protected void afterProcess(HttpServletResponse response, Exchange exchange, boolean rethrow) throws IOException, ServletException { + try { + // now lets output to the res + if (LOG.isTraceEnabled()) { + LOG.trace("Writing res for exchangeId: {}", exchange.getExchangeId()); + } + binding.writeResponse(exchange, response); + } catch (IOException e) { + LOG.error("Error processing request", e); + if (rethrow) { + throw e; + } else { + exchange.setException(e); + } + } catch (Exception e) { + LOG.error("Error processing request", e); + if (rethrow) { + throw new ServletException(e); + } else { + exchange.setException(e); + } + } finally { + doneUoW(exchange); + releaseExchange(exchange, false); + } + } + +} diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpEngine.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpEngine.java similarity index 80% rename from components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpEngine.java rename to components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpEngine.java index fcf83dec539..5e589367509 100644 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpEngine.java +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpEngine.java @@ -21,11 +21,11 @@ import org.apache.camel.Processor; import org.apache.camel.component.platform.http.PlatformHttpEndpoint; import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; - -public class JettyCustomPlatformHttpEngine implements PlatformHttpEngine { +public class SpringBootPlatformHttpEngine implements PlatformHttpEngine { @Override - public Consumer createConsumer(PlatformHttpEndpoint platformHttpEndpoint, Processor processor) { - return new JettyCustomPlatformHttpConsumer(platformHttpEndpoint, processor); + public Consumer createConsumer(PlatformHttpEndpoint endpoint, Processor processor) { + return new SpringBootPlatformHttpConsumer(endpoint, processor); } + } diff --git a/components-starter/camel-platform-http-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/components-starter/camel-platform-http-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index d4b90821e4f..aaf4d4e5306 100644 --- a/components-starter/camel-platform-http-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/components-starter/camel-platform-http-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -17,4 +17,4 @@ org.apache.camel.component.platform.http.springboot.PlatformHttpComponentConverter org.apache.camel.component.platform.http.springboot.PlatformHttpComponentAutoConfiguration -org.apache.camel.component.platform.http.springboot.ServletPlatformHttpAutoConfiguration \ No newline at end of file +org.apache.camel.component.platform.http.springboot.SpringBootPlatformHttpAutoConfiguration \ No newline at end of file diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpConsumer.java b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpConsumer.java deleted file mode 100644 index 1e03b932ae4..00000000000 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyCustomPlatformHttpConsumer.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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.springboot; - -import java.io.BufferedReader; -import java.io.IOException; -import java.util.regex.Pattern; - -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.component.platform.http.PlatformHttpEndpoint; -import org.apache.camel.support.CamelContextHelper; -import org.apache.camel.support.DefaultConsumer; -import org.apache.camel.support.DefaultMessage; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.handler.ContextHandler; - -public class JettyCustomPlatformHttpConsumer extends DefaultConsumer { - private static final Pattern PATH_PARAMETER_PATTERN = Pattern.compile("\\{([^/}]+)\\}"); - - public JettyCustomPlatformHttpConsumer(PlatformHttpEndpoint endpoint, Processor processor) { - super(endpoint, processor); - } - - @Override - protected void doStart() throws Exception { - super.doStart(); - final PlatformHttpEndpoint endpoint = getEndpoint(); - final String path = configureEndpointPath(endpoint); - - JettyServerTest jettyServerTest = CamelContextHelper.mandatoryLookup( - getEndpoint().getCamelContext(), - JettyServerTest.JETTY_SERVER_NAME, - JettyServerTest.class); - - ContextHandler contextHandler = createHandler(endpoint, path); - // add handler after starting server. - jettyServerTest.addHandler(contextHandler); - - } - - private ContextHandler createHandler(PlatformHttpEndpoint endpoint, String path) { - ContextHandler contextHandler = new ContextHandler(); - contextHandler.setContextPath(path); - contextHandler.setResourceBase("."); - contextHandler.setClassLoader(Thread.currentThread().getContextClassLoader()); - contextHandler.setAllowNullPathInfo(true); - contextHandler.setHandler(new AbstractHandler() { - @Override - public void handle( - String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws IOException, ServletException { - Exchange exchg = null; - try { - BufferedReader reader = httpServletRequest.getReader(); - String bodyRequest = ""; - String strCurrentLine = ""; - while ((strCurrentLine = reader.readLine()) != null) { - bodyRequest += strCurrentLine; - } - final Exchange exchange = exchg = toExchange(request, bodyRequest); - createUoW(exchange); - getProcessor().process( - exchange); - httpServletResponse.setStatus(HttpServletResponse.SC_OK); - request.setHandled(true); - httpServletResponse.getWriter().println(exchange.getMessage().getBody()); - } catch (Exception e) { - getExceptionHandler().handleException("Failed handling platform-http endpoint " + endpoint.getPath(), exchg, - e); - } finally { - if (exchg != null) { - doneUoW(exchg); - } - } - } - }); - return contextHandler; - } - - private Exchange toExchange(Request request, String body) { - final Exchange exchange = getEndpoint().createExchange(); - final Message message = new DefaultMessage(exchange); - - final String charset = request.getHeader("charset"); - if (charset != null) { - exchange.setProperty(Exchange.CHARSET_NAME, charset); - message.setHeader(Exchange.HTTP_CHARACTER_ENCODING, charset); - } - - message.setBody(body.length() != 0 ? body : null); - exchange.setMessage(message); - return exchange; - } - - @Override - public PlatformHttpEndpoint getEndpoint() { - return (PlatformHttpEndpoint) super.getEndpoint(); - } - - private String configureEndpointPath(PlatformHttpEndpoint endpoint) { - String path = endpoint.getPath(); - if (endpoint.isMatchOnUriPrefix()) { - path += "*"; - } - // Transform from the Camel path param syntax /path/{key} to vert.x web's /path/:key - return PATH_PARAMETER_PATTERN.matcher(path).replaceAll(":$1"); - } - -} diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyServerTest.java b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyServerTest.java deleted file mode 100644 index 3b0c7ab1f0e..00000000000 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/JettyServerTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.springboot; - -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.server.handler.HandlerCollection; - -public class JettyServerTest { - public static final String JETTY_SERVER_NAME = "JettyServerTest"; - - private Server server; - private HandlerCollection contextHandlerCollection; - - public JettyServerTest(int port) { - server = new Server(port); - contextHandlerCollection = new HandlerCollection(true); - server.setHandler(contextHandlerCollection); - } - - public void start() throws Exception { - server.start(); - } - - public void stop() throws Exception { - server.stop(); - } - - /** - * adds a context handler and starts it - * - * @param contextHandler - * @throws Exception - */ - public void addHandler(ContextHandler contextHandler) throws Exception { - contextHandlerCollection.addHandler(contextHandler); - contextHandler.start(); - } -} diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpBase.java b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/PlatformHttpBase.java similarity index 86% rename from components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpBase.java rename to components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/PlatformHttpBase.java index d9a01c865f2..37d4ade9f7f 100644 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpBase.java +++ b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/PlatformHttpBase.java @@ -22,7 +22,7 @@ import org.assertj.core.api.Assertions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.web.client.TestRestTemplate; -public class ServletPlatformHttpBase { +public class PlatformHttpBase { @Autowired private TestRestTemplate restTemplate; @@ -30,14 +30,14 @@ public class ServletPlatformHttpBase { @Test public void testGet() { Assertions.assertThat( - restTemplate.getForEntity("/camel/get", String.class).getStatusCodeValue()) + restTemplate.getForEntity("/myget", String.class).getStatusCodeValue()) .isEqualTo(200); } @Test public void testPost() { Assertions.assertThat( - restTemplate.postForEntity("/camel/post", "test", String.class).getBody()) + restTemplate.postForEntity("/mypost", "test", String.class).getBody()) .isEqualTo("TEST"); } } diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/PlatformHttpTest.java b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/PlatformHttpTest.java deleted file mode 100644 index 4a60d9e75b1..00000000000 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/PlatformHttpTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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.springboot; - - -import static io.restassured.RestAssured.given; - -import java.util.Iterator; - -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.platform.http.HttpEndpointModel; -import org.apache.camel.component.platform.http.PlatformHttpComponent; -import org.apache.camel.component.platform.http.PlatformHttpConstants; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.apache.camel.spring.boot.CamelContextConfiguration; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import io.restassured.RestAssured; -import io.restassured.response.Response; -import io.restassured.specification.RequestSpecification; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.annotation.DirtiesContext; -import org.apache.camel.test.AvailablePortFinder; -import org.apache.camel.test.spring.junit5.CamelSpringBootTest; - - -@DirtiesContext -@CamelSpringBootTest -@SpringBootTest( - classes = { - CamelAutoConfiguration.class, - PlatformHttpTest.class, - PlatformHttpTest.TestConfiguration.class - } -) -public class PlatformHttpTest { - - static int port = AvailablePortFinder.getNextAvailable(); - - @Autowired - private CamelContext context; - - - - - @Bean - CamelContextConfiguration contextConfiguration() { - return new CamelContextConfiguration() { - @Override - public void beforeApplicationStart(CamelContext context) { - context.getRegistry().bind(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_FACTORY, new JettyCustomPlatformHttpEngine()); - - - JettyServerTest server = new JettyServerTest(port); - - context.getRegistry().bind(JettyServerTest.JETTY_SERVER_NAME, server); - try { - server.start(); - } catch (Exception e) { - - e.printStackTrace(); - } - - } - @Override - public void afterApplicationStart(CamelContext camelContext) { - //do nothing here - } - - }; - } - - @Test - public void testGet() throws Exception { - given() - .header("Accept", "application/json") - .port(port) - .expect() - .statusCode(200) - .when() - .get("/get"); - } - - @Test - public void testPost() { - RequestSpecification request = RestAssured.given(); - request.port(port); - request.body("test"); - Response response = request.get("/post"); - - int statusCode = response.getStatusCode(); - assertEquals(200, statusCode); - assertEquals("TEST", response.body().asString().trim()); - - PlatformHttpComponent phc = context.getComponent("platform-http", PlatformHttpComponent.class); - assertEquals(2, phc.getHttpEndpoints().size()); - Iterator<HttpEndpointModel> it = phc.getHttpEndpoints().iterator(); - assertEquals("/get", it.next().getUri()); - assertEquals("/post", it.next().getUri()); - } - - - // ************************************* - // Config - // ************************************* - - @Configuration - public static class TestConfiguration { - - @Bean - public RouteBuilder routeBuilder() { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("platform-http:/get") - .setBody().constant("get"); - from("platform-http:/post") - .transform().body(String.class, b -> b.toUpperCase()); - } - }; - } - } -} diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/RestPlatformHttpContextPathConfigurationTest.java b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/RestPlatformHttpContextPathConfigurationTest.java deleted file mode 100644 index aa717a5d736..00000000000 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/RestPlatformHttpContextPathConfigurationTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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.springboot; - - -import static org.hamcrest.CoreMatchers.containsString; - - -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.platform.http.PlatformHttpConstants; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.apache.camel.spring.boot.CamelContextConfiguration; - -import org.junit.jupiter.api.Test; - - -import io.restassured.RestAssured; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.annotation.DirtiesContext; -import org.apache.camel.test.AvailablePortFinder; -import org.apache.camel.test.spring.junit5.CamelSpringBootTest; - - -@DirtiesContext -@CamelSpringBootTest -@SpringBootTest( - classes = { - CamelAutoConfiguration.class, - RestPlatformHttpContextPathConfigurationTest.class, - RestPlatformHttpContextPathConfigurationTest.TestConfiguration.class - } -) -public class RestPlatformHttpContextPathConfigurationTest { - - static int port = AvailablePortFinder.getNextAvailable(); - - - @Bean - CamelContextConfiguration contextConfiguration() { - return new CamelContextConfiguration() { - @Override - public void beforeApplicationStart(CamelContext context) { - context.getRegistry().bind(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_FACTORY, new JettyCustomPlatformHttpEngine()); - - - JettyServerTest server = new JettyServerTest(port); - - context.getRegistry().bind(JettyServerTest.JETTY_SERVER_NAME, server); - try { - server.start(); - } catch (Exception e) { - - e.printStackTrace(); - } - - } - @Override - public void afterApplicationStart(CamelContext camelContext) { - //do nothing here - } - - }; - } - - @Test - public void contextPath() { - RestAssured.given() - .port(port) - .get("/rest/get") - .then() - .body(containsString("GET: /get")); - - RestAssured.given() - .port(port) - .contentType("text/plain") - .post("/rest/post") - .then() - .body(containsString("POST: /post")); - } - - - - // ************************************* - // Config - // ************************************* - - @Configuration - public static class TestConfiguration { - - @Bean - public RouteBuilder routeBuilder() { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - restConfiguration() - .component("platform-http") - .contextPath("/rest"); - - rest() - .get("/get").to("direct:get") - .post("/post").consumes("text/plain").produces("text/plain").to("direct:post"); - - from("direct:get") - .setBody(constant("GET: /get")); - from("direct:post") - .setBody(constant("POST: /post")); - - } - }; - } - } -} diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpRestDSLTest.java b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpRestDSLTest.java similarity index 75% rename from components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpRestDSLTest.java rename to components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpRestDSLTest.java index 95ee308ad17..2ac77b14542 100644 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpRestDSLTest.java +++ b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpRestDSLTest.java @@ -17,8 +17,6 @@ package org.apache.camel.component.platform.http.springboot; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.servlet.springboot.ServletComponentAutoConfiguration; -import org.apache.camel.component.servlet.springboot.ServletMappingAutoConfiguration; import org.apache.camel.spring.boot.CamelAutoConfiguration; import org.apache.camel.test.spring.junit5.CamelSpringBootTest; @@ -35,14 +33,13 @@ import org.springframework.test.annotation.DirtiesContext; webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CamelAutoConfiguration.class, - ServletPlatformHttpRestDSLTest.class, - ServletPlatformHttpRestDSLTest.TestConfiguration.class, - ServletPlatformHttpAutoConfiguration.class, - ServletComponentAutoConfiguration.class, - ServletMappingAutoConfiguration.class + SpringBootPlatformHttpRestDSLTest.class, + SpringBootPlatformHttpRestDSLTest.TestConfiguration.class, + PlatformHttpComponentAutoConfiguration.class, + SpringBootPlatformHttpAutoConfiguration.class, } ) -public class ServletPlatformHttpRestDSLTest extends ServletPlatformHttpBase { +public class SpringBootPlatformHttpRestDSLTest extends PlatformHttpBase { // ************************************* // Config @@ -51,13 +48,13 @@ public class ServletPlatformHttpRestDSLTest extends ServletPlatformHttpBase { public static class TestConfiguration { @Bean - public RouteBuilder servletPlatformHttpRestDSLRouteBuilder() { + public RouteBuilder springBootPlatformHttpRestDSLRouteBuilder() { return new RouteBuilder() { @Override public void configure() throws Exception { rest() - .get("get").to("direct:get") - .post("post").to("direct:post"); + .get("myget").to("direct:get") + .post("mypost").to("direct:post"); from("direct:post").transform().body(String.class, b -> b.toUpperCase()); from("direct:get").setBody().constant("get"); diff --git a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpTest.java b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpTest.java similarity index 78% rename from components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpTest.java rename to components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpTest.java index 9af1c965eb7..f88438529c2 100644 --- a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/ServletPlatformHttpTest.java +++ b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpTest.java @@ -17,8 +17,6 @@ package org.apache.camel.component.platform.http.springboot; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.servlet.springboot.ServletComponentAutoConfiguration; -import org.apache.camel.component.servlet.springboot.ServletMappingAutoConfiguration; import org.apache.camel.spring.boot.CamelAutoConfiguration; import org.apache.camel.test.spring.junit5.CamelSpringBootTest; @@ -35,14 +33,13 @@ import org.springframework.test.annotation.DirtiesContext; webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CamelAutoConfiguration.class, - ServletPlatformHttpTest.class, - ServletPlatformHttpTest.TestConfiguration.class, - ServletPlatformHttpAutoConfiguration.class, - ServletComponentAutoConfiguration.class, - ServletMappingAutoConfiguration.class + SpringBootPlatformHttpTest.class, + SpringBootPlatformHttpTest.TestConfiguration.class, + PlatformHttpComponentAutoConfiguration.class, + SpringBootPlatformHttpAutoConfiguration.class } ) -public class ServletPlatformHttpTest extends ServletPlatformHttpBase { +public class SpringBootPlatformHttpTest extends PlatformHttpBase { // ************************************* // Config @@ -55,9 +52,9 @@ public class ServletPlatformHttpTest extends ServletPlatformHttpBase { return new RouteBuilder() { @Override public void configure() throws Exception { - from("platform-http:/get") + from("platform-http:/myget") .setBody().constant("get"); - from("platform-http:/post") + from("platform-http:/mypost") .transform().body(String.class, b -> b.toUpperCase()); } };