JiriOndrusek commented on a change in pull request #1804: URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r495002948
########## File path: integration-tests/velocity/src/main/java/org/apache/camel/quarkus/component/velocity/it/VelocityResource.java ########## @@ -0,0 +1,192 @@ +/* + * 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.quarkus.component.velocity.it; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.velocity.VelocityConstants; +import org.jboss.logging.Logger; + +@Path("/velocity") +@ApplicationScoped +public class VelocityResource { + + private static final Logger LOG = Logger.getLogger(VelocityResource.class); + + @Inject + ProducerTemplate producerTemplate; + private String endpointUri; + + @Path("/template") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Response template(String message, @QueryParam("item") String item, + @QueryParam("name") String name, @QueryParam("template") String template, + @QueryParam("propertiesFile") String propertiesFile, + @QueryParam("contentCache") String contentCache, + @QueryParam("expectFailure") String exectFaiure) throws Exception { + LOG.infof("Sending to velocity: %s", message); + Map<String, Object> headers = new HashMap() { + { + if (item != null) { + put("item", item); + } + if (name != null) { + put("name", name); + } + put(VelocityConstants.VELOCITY_TEMPLATE, message); + } + }; + String endpointUrl = "velocity:" + template; + if (propertiesFile != null) { + endpointUrl = endpointUrl + "?propertiesFile=" + propertiesFile; + } + if (contentCache != null) { + endpointUrl = endpointUrl + "?contentCache=" + contentCache; + } + try { + final String response = producerTemplate.requestBodyAndHeaders(endpointUrl, message, + headers, + String.class); + LOG.infof("Got response from velocity: %s", response); + return Response + .created(new URI("https://camel.apache.org/")) + .entity(response) + .build(); + } catch (Exception e) { + if (exectFaiure != null && Boolean.parseBoolean(exectFaiure)) { + return Response + .created(new URI("https://camel.apache.org/")) + .entity(e.toString()) + .status(500) + .build(); + } else { + throw e; + } + } + } + + @Path("/bodyAsDomainObject") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public Response bodyAsDomainObject(Person person, @QueryParam("givenName") String givenName, + @QueryParam("familyName") String familyName) throws Exception { + LOG.infof("Sending to velocity: %s", person); + final String response = producerTemplate.requestBody("velocity://template/BodyAsDomainObject.vm", person, + String.class); + LOG.infof("Got response from velocity: %s", response); + return Response + .created(new URI("https://camel.apache.org/")) + .entity(response) + .build(); + } + + @Path("/templateViaHeader") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Response templateViaHeader(String message, @QueryParam("body") String body, @QueryParam("item") String item, + @QueryParam("name") String name) throws Exception { + LOG.infof("Sending to velocity: %s", body); + Map<String, Object> headers = new HashMap() { + { + put("item", item); + put("name", name); + put(VelocityConstants.VELOCITY_TEMPLATE, message); + } + }; + final String response = producerTemplate.requestBodyAndHeaders("velocity::dummy?allowTemplateFromHeader=true", body, + headers, + String.class); + LOG.infof("Got response from velocity: %s", response); + return Response + .created(new URI("https://camel.apache.org/")) + .entity(response) + .build(); + } + + @Path("/withProperties") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Response withProperties(String message, @QueryParam("item") String item, + @QueryParam("name") String name) throws Exception { + LOG.infof("Sending to velocity: %s", message); Review comment: I've left logging here because it was generated by the command `fmvn cq:create -N -Dcq.artifactIdBase=foo-abc`. But in future I won't keep it ########## File path: integration-tests/velocity/src/main/java/org/apache/camel/quarkus/component/velocity/it/VelocityResource.java ########## @@ -0,0 +1,192 @@ +/* + * 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.quarkus.component.velocity.it; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.velocity.VelocityConstants; +import org.jboss.logging.Logger; + +@Path("/velocity") +@ApplicationScoped +public class VelocityResource { + + private static final Logger LOG = Logger.getLogger(VelocityResource.class); + + @Inject + ProducerTemplate producerTemplate; + private String endpointUri; + + @Path("/template") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Response template(String message, @QueryParam("item") String item, + @QueryParam("name") String name, @QueryParam("template") String template, + @QueryParam("propertiesFile") String propertiesFile, + @QueryParam("contentCache") String contentCache, + @QueryParam("expectFailure") String exectFaiure) throws Exception { + LOG.infof("Sending to velocity: %s", message); + Map<String, Object> headers = new HashMap() { + { + if (item != null) { + put("item", item); + } + if (name != null) { + put("name", name); + } + put(VelocityConstants.VELOCITY_TEMPLATE, message); + } + }; + String endpointUrl = "velocity:" + template; + if (propertiesFile != null) { + endpointUrl = endpointUrl + "?propertiesFile=" + propertiesFile; + } + if (contentCache != null) { + endpointUrl = endpointUrl + "?contentCache=" + contentCache; + } + try { + final String response = producerTemplate.requestBodyAndHeaders(endpointUrl, message, + headers, + String.class); + LOG.infof("Got response from velocity: %s", response); + return Response + .created(new URI("https://camel.apache.org/")) + .entity(response) + .build(); + } catch (Exception e) { + if (exectFaiure != null && Boolean.parseBoolean(exectFaiure)) { + return Response + .created(new URI("https://camel.apache.org/")) + .entity(e.toString()) + .status(500) + .build(); + } else { + throw e; + } + } + } + + @Path("/bodyAsDomainObject") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public Response bodyAsDomainObject(Person person, @QueryParam("givenName") String givenName, + @QueryParam("familyName") String familyName) throws Exception { + LOG.infof("Sending to velocity: %s", person); + final String response = producerTemplate.requestBody("velocity://template/BodyAsDomainObject.vm", person, + String.class); + LOG.infof("Got response from velocity: %s", response); + return Response + .created(new URI("https://camel.apache.org/")) + .entity(response) + .build(); + } + + @Path("/templateViaHeader") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Response templateViaHeader(String message, @QueryParam("body") String body, @QueryParam("item") String item, + @QueryParam("name") String name) throws Exception { + LOG.infof("Sending to velocity: %s", body); + Map<String, Object> headers = new HashMap() { + { + put("item", item); + put("name", name); + put(VelocityConstants.VELOCITY_TEMPLATE, message); + } + }; + final String response = producerTemplate.requestBodyAndHeaders("velocity::dummy?allowTemplateFromHeader=true", body, + headers, + String.class); + LOG.infof("Got response from velocity: %s", response); + return Response + .created(new URI("https://camel.apache.org/")) + .entity(response) + .build(); + } + + @Path("/withProperties") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Response withProperties(String message, @QueryParam("item") String item, + @QueryParam("name") String name) throws Exception { + LOG.infof("Sending to velocity: %s", message); Review comment: I've left logging here because it was generated by the command `mvn cq:create -N -Dcq.artifactIdBase=foo-abc`. But in the future I won't keep it ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org