I want to define cxf:rsclient in Java dsl instead of xml based dsl.
I have the following defined in Java dsl.
from("direct:fromChannel")
.split()
.tokenizeXML("APIDataMessage").streaming()
.unmarshal(jaxb)
.convertBodyTo(com.testing.camel.MeasureEvent.class)
.setHeader("Content-Type", constant("application/json"))
.to("cxfrs://bean://toClient");
And I have the following for RSClient
#Bean
public SpringJAXRSClientFactoryBean toClient()
{
SpringJAXRSClientFactoryBean springJAXRSClientFactoryBean = new SpringJAXRSClientFactoryBean();
String measurementEventURL = "http://" + connectorsConfig.getHost() +
":" + connectorsConfig.getPort() + "/api/measurementEvents";
springJAXRSClientFactoryBean.setBeanId("toClient");
springJAXRSClientFactoryBean.setAddress(measurementEventURL);
springJAXRSClientFactoryBean.setServiceClass(com.testing.camel.MeasurementEventEndpoint.class);
springJAXRSClientFactoryBean.setLoggingFeatureEnabled(true);
springJAXRSClientFactoryBean.setSkipFaultLogging(true);
springJAXRSClientFactoryBean.setProvider(jsonProvider());
return springJAXRSClientFactoryBean;
}
And here is my jsonProvider definition:
JacksonJsonProvider jsonProvider()
{
return new JacksonJsonProvider();
}
And following is the stacktrace that I see while calling this route.
Stacktrace
org.apache.camel.component.cxf.CxfOperationException: JAXRS operation failed invoking http://0.0.0.0:8089/monnitmysqltsdb?restletMethods=POST with statusCode: 405
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.populateCxfRsProducerException(CxfRsProducer.java:419)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeHttpClient(CxfRsProducer.java:232)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:89)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:169)
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:341)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:164)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:668)
at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:596)
at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:237)
at org.apache.camel.processor.Splitter.process(Splitter.java:104)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:141)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)
at org.apache.camel.processor.MulticastProcessor.doProcessParallel(MulticastProcessor.java:814)
at org.apache.camel.processor.MulticastProcessor.access$200(MulticastProcessor.java:84)
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:314)
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:299)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Related
I have an error with Apache Camel when starting Spring boot
Can someone tell me how can I fix it ?
Thank you !
org.apache.camel.FailedToStartRouteException: Failed to start route
route1 because of null at
org.apache.camel.impl.engine.RouteService.setUp(RouteService.java:132)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.InternalRouteStartupManager.doInitRoutes(InternalRouteStartupManager.java:92)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:3010)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.support.service.BaseService.init(BaseService.java:83)
~[camel-api-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2679)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.support.service.BaseService.start(BaseService.java:111)
~[camel-api-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2698)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:262)
~[camel-core-engine-3.20.1.jar:3.20.1] at
org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:119)
~[camel-spring-3.20.1.jar:3.20.1] at
org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:151)
~[camel-spring-3.20.1.jar:3.20.1] at
org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
~[spring-context-5.3.25.jar:5.3.25] at
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
~[spring-context-5.3.25.jar:5.3.25] at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
~[spring-context-5.3.25.jar:5.3.25] at
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)
~[spring-context-5.3.25.jar:5.3.25] at
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
~[spring-context-5.3.25.jar:5.3.25] at
org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938)
~[spring-context-5.3.25.jar:5.3.25] at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
~[spring-context-5.3.25.jar:5.3.25] at
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
~[spring-boot-2.7.8.jar:2.7.8] at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
~[spring-boot-2.7.8.jar:2.7.8] at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
~[spring-boot-2.7.8.jar:2.7.8] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
~[spring-boot-2.7.8.jar:2.7.8] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
~[spring-boot-2.7.8.jar:2.7.8] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
~[spring-boot-2.7.8.jar:2.7.8] at
com.example.gestiunestudenti.GestiuneStudentiApplication.main(GestiuneStudentiApplication.java:10)
~[classes/:na] Caused by: org.apache.camel.NoSuchBeanException: No
bean could be found in the registry for: servlet of type:
org.apache.camel.spi.RestApiConsumerFactory at
org.apache.camel.component.rest.RestApiEndpoint.createConsumer(RestApiEndpoint.java:220)
~[camel-rest-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.DefaultRoute.gatherRootServices(DefaultRoute.java:636)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.DefaultRoute.gatherServices(DefaultRoute.java:620)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.DefaultRoute.initializeServices(DefaultRoute.java:205)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.RouteService.doSetup(RouteService.java:151)
~[camel-base-engine-3.20.1.jar:3.20.1] at
org.apache.camel.impl.engine.RouteService.setUp(RouteService.java:130)
~[camel-base-engine-3.20.1.jar:3.20.1] ... 23 common frames omitted
Here is my code for CamelRouter
#Component
public class CamelRouter extends RouteBuilder {
#Autowired
private Environment env;
#Value("${camel.servlet.mapping.context-path}")
private String contextPath;
#Override
public void configure() throws Exception {
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.enableCORS(true)
.port(8080)
.contextPath("/api")
// turn on openapi api-doc
.apiContextPath("/api-doc")
.apiProperty("api.title", "User API")
.apiProperty("api.version", "1.0.0");
rest("/users").description("User REST service")
.consumes("application/json")
.produces("application/json")
.get().description("Find all users").outType(User[].class)
.responseMessage().code(200).message("All users successfully returned").endResponseMessage()
.to("bean:userService?method=findUsers")
.get("/{id}").description("Find user by ID")
.outType(User.class)
.param().name("id").type(path).description("The ID of the user").dataType("integer").endParam()
.responseMessage().code(200).message("User successfully returned").endResponseMessage()
.to("bean:userService?method=findUser(${header.id})")
.put("/{id}").description("Update a user").type(User.class)
.param().name("id").type(path).description("The ID of the user to update").dataType("integer").endParam()
.param().name("body").type(body).description("The user to update").endParam()
.responseMessage().code(204).message("User successfully updated").endResponseMessage()
.to("direct:update-user");
from("direct:update-user")
.to("bean:userService?method=updateUser")
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(204))
.setBody(constant(""));
}
}
I tried to make a simple REST API using Spring Boot and Apache Camel
In Spring Boot, I am trying to use Spring Batch to read a JSON file having a 1000 entries, do some processing and then write the output to a CSV file. The issue occurs whenever I use a TaskExecutor to enable multiThreaded steps.
Code for my implementation of TaskExecutor
#Bean
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(2);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("GithubLookup-");
executor.initialize();
return executor;
}
Code for my Step implementation
#SuppressWarnings({ "unchecked" })
#Bean
public Step humanStep() throws MalformedURLException {
return stepBuilderFactory
.get("humanStep")
.<Human, Human>chunk(20)
.reader(jsonItemReader())
.processor(processor())
.writer(humanItemWriter())
.taskExecutor(taskExecutor())
.build();
}
Code for my ItemReader implementation
#SuppressWarnings({ "rawtypes", "unchecked" })
#Bean
public JsonItemReader jsonItemReader() throws MalformedURLException {
Resource input_resource1 = new FileSystemResource(inputPath);
return new JsonItemReaderBuilder()
.jsonObjectReader(new JacksonJsonObjectReader(Human.class))
.resource(input_resource1)
.name("humanJsonItemReader")
.build();
}
The format of my JSON file is as follows
[
{"id":1,"first_name":"Hendrika","last_name":"Glossop","email":"hglossop0#samsung.com","gender":"Female","car":"SALFR2BGXFH882836"},
{"id":2,"first_name":"Batsheva","last_name":"Drysdell","email":"bdrysdell1#example.com","gender":"Female","car":"2C3CA5CGXBH086890"},
{"id":3,"first_name":"Xenos","last_name":"Evered","email":"xevered2#independent.co.uk","gender":"Male","car":"2C3CCAEG5FH423486"},
{"id":4,"first_name":"Worthington","last_name":"Oleksinski","email":"woleksinski3#unicef.org","gender":"Male","car":"3VWML7AJ7EM658490"},
{"id":5,"first_name":"Dee","last_name":"Weston","email":"dweston4#tripod.com","gender":"Female","car":"WBA3B3C59FJ781374"},
.
.
.
]
The error thrown is as follows :
org.springframework.batch.item.ParseException: Unable to read next JSON object
at org.springframework.batch.item.json.JacksonJsonObjectReader.read(JacksonJsonObjectReader.java:84) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.item.json.JsonItemReader.doRead(JsonItemReader.java:103) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:93) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:99) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:180) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:126) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:118) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:71) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate$ExecutingRunnable.run(TaskExecutorRepeatTemplate.java:262) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:1.8.0_261]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:1.8.0_261]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_261]
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('_' (code 95)): was expecting comma to separate Object entries
at [Source: (sun.nio.ch.ChannelInputStream); line: 1, column: 24]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1851) ~[jackson-core-2.11.2.jar:2.11.2]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:707) ~[jackson-core-2.11.2.jar:2.11.2]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:632) ~[jackson-core-2.11.2.jar:2.11.2]
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:741) ~[jackson-core-2.11.2.jar:2.11.2]
at org.springframework.batch.item.json.JacksonJsonObjectReader.read(JacksonJsonObjectReader.java:80) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 19 common frames omitted
Can anyone give me an idea as to what I am doing wrong?
The JsonItemReader is not thread-safe as mentioned in its Javadoc. So using it in a multi-threaded step is incorrect.
I keep receiving this error message when I attempt to send a webhook to my server.
a
<html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>
The full url for my api is http://localhost:8081/api.
I am using ngrok to tunnel this url to the internet. The resulting urls are https://75bb9fa8.ngrok.io and http://75bb9fa8.ngrok.io
In the Stripe dashboard, I created a webhook and set the endpoint to https://75bb9fa8.ngrok.io/api/webhooks/webhook, as this is the full url and path of my sever method that receives webhooks.
Webhook.JPG
Here is my complete webhook receiver class. It is based on https://stripe.com/docs/webhooks/setup...
package core.services;
import java.util.Optional;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.JsonSyntaxException;
import com.stripe.model.Event;
import com.stripe.model.EventDataObjectDeserializer;
import com.stripe.model.StripeObject;
import com.stripe.net.ApiResource;
import spark.Request;
import spark.Response;
#Path("/webhooks")
public final class WebhookService {
private static final Logger LOGGER = LoggerFactory.getLogger(WebhookService.class);
public WebhookService() {
}
// Retrieve webhook endpoint's signing secret
final String endpointSecret = "whsec_4S4Htm9f2qU8llC70kDRP0AkP5Fl6gkx";
// Using the Spark framework (http://sparkjava.com)
#POST
#Path("/webhook")
public Object handle(RequestResponse requestresponse) {
Request request = requestresponse.request;
Response response = requestresponse.response;
String payload = request.body();
Event event = null;
try {
event = ApiResource.GSON.fromJson(payload, Event.class);
} catch (JsonSyntaxException e) {
// Invalid payload
response.status(400);
return "";
}
// Deserialize the nested object inside the event
EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
Optional<StripeObject> stripeObject = null;
if (dataObjectDeserializer.getObject().isPresent()) {
stripeObject = dataObjectDeserializer.getObject();
} else {
// Deserialization failed, probably due to an API version mismatch.
// Refer to the Javadoc documentation on `EventDataObjectDeserializer` for
// instructions on how to handle this case, or return an error here.
}
// Handle the event
switch (event.getType()) {
case "customer.created":
System.out.println("customer created webhook");
break;
default:
// Unexpected event type
response.status(400);
return "";
}
response.status(200);
return "";
}
public static class RequestResponse {
Response response;
Request request;
}
}
And for the sake of completeness, here are my server logs...
2019-07-25 03:09:01.997 DESKTOP-2AB6RK0 server.Server$Builder 766 INFO Initializing server at http://192.168.1.91:8081/ in C:\Users\User\Documents\Work\projectDir\core\.
2019-07-25 03:09:02.024 DESKTOP-2AB6RK0 org.eclipse.jetty.util.log 793 INFO Logging initialized #1511ms to org.eclipse.jetty.util.log.Slf4jLog
2019-07-25 03:09:02.366 DESKTOP-2AB6RK0 org.eclipse.jetty.server.Server 1135 INFO jetty-9.4.12.v20180830; built: 2018-08-30T13:59:14.071Z; git: 27208684755d94a92186989f695db2d7b21ebc51; jvm 1.8.0_191-b12
2019-07-25 03:09:03.619 DESKTOP-2AB6RK0 org.hibernate.validator.internal.util.Version 2388 INFO HV000001: Hibernate Validator 6.0.11.Final
2019-07-25 03:09:04.038 DESKTOP-2AB6RK0 org.eclipse.jetty.server.handler.ContextHandler 2807 INFO Started o.e.j.s.ServletContextHandler#402f80f5{/,null,AVAILABLE}
2019-07-25 03:09:04.296 DESKTOP-2AB6RK0 org.eclipse.jetty.server.AbstractConnector 3065 INFO Started ServerConnector#5c909414{HTTP/1.1,[http/1.1]}{0.0.0.0:8081}
2019-07-25 03:09:04.297 DESKTOP-2AB6RK0 org.eclipse.jetty.server.Server 3066 INFO Started #3787ms
2019-07-25 03:09:35.763 DESKTOP-2AB6RK0 server.ExceptionMappers$OtherExceptionMapper 34532 ERROR java.lang.NullPointerException
java.lang.NullPointerException: null
at core.services.WebhookService.handle(WebhookService.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ObjectOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:192)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:469)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:391)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:80)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:253)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:232)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:679)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:392)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:365)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:318)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:873)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:542)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:703)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:505)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
2019-07-25 03:09:35.911 DESKTOP-2AB6RK0 org.glassfish.jersey.server.ServerRuntime$Responder 34680 ERROR Error occurred when processing a response created from an already mapped exception.
2019-07-25 03:09:35.916 DESKTOP-2AB6RK0 org.eclipse.jetty.server.HttpChannel 34685 WARN /api/webhooks/webhook
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.eclipse.jetty.util.BufferUtil.remaining([Ljava/nio/ByteBuffer;)J
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:408)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:365)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:318)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:873)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:542)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:703)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:505)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
Caused by: org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.eclipse.jetty.util.BufferUtil.remaining([Ljava/nio/ByteBuffer;)J
at org.glassfish.jersey.servlet.internal.ResponseWriter.rethrow(ResponseWriter.java:254)
at org.glassfish.jersey.servlet.internal.ResponseWriter.failure(ResponseWriter.java:236)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:436)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:261)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:232)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:679)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:392)
... 26 common frames omitted
Caused by: java.lang.NoSuchMethodError: org.eclipse.jetty.util.BufferUtil.remaining([Ljava/nio/ByteBuffer;)J
at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:392)
at org.eclipse.jetty.io.WriteFlusher.write(WriteFlusher.java:277)
at org.eclipse.jetty.io.AbstractEndPoint.write(AbstractEndPoint.java:380)
at org.eclipse.jetty.server.HttpConnection$SendCallback.process(HttpConnection.java:814)
at org.eclipse.jetty.util.IteratingCallback.processing(IteratingCallback.java:241)
at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:224)
at org.eclipse.jetty.server.HttpConnection.send(HttpConnection.java:550)
at org.eclipse.jetty.server.HttpChannel.sendResponse(HttpChannel.java:845)
at org.eclipse.jetty.server.HttpChannel.write(HttpChannel.java:921)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:249)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:225)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:550)
at org.glassfish.jersey.servlet.internal.ResponseWriter$NonCloseableOutputStreamWrapper.write(ResponseWriter.java:301)
at java.io.ByteArrayOutputStream.writeTo(Unknown Source)
at org.glassfish.jersey.message.internal.CommittingOutputStream.flushBuffer(CommittingOutputStream.java:278)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:232)
at org.glassfish.jersey.message.internal.CommittingOutputStream.close(CommittingOutputStream.java:247)
at org.glassfish.jersey.message.internal.OutboundMessageContext.close(OutboundMessageContext.java:824)
at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:389)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:710)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:371)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:417)
... 36 common frames omitted
What am I doing incorrectly?
Thank you.
Perhaps the problem has to do with the parameters of my webhook method. The #POST and #Path annotations require that the method only take a single JSON object as a parameter. However, the webhook might be sending two separate parameters - a request object and a response object. If you think this inconsistency is the source of the problem, then how can I refactor the server code to accommodate the structure of the webhook?
You can try add this under the path parameter
#Consumes("application/x-www-form-urlencoded")
Because header authentication relation
I want to scan a directory periodically for files matching a specific pattern and launch a job for the found file.
#Configuration
#EnableBatchProcessing
public class BatchConfiguration {
private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;
#Autowired
public BatchConfiguration(final JobBuilderFactory jobBuilderFactory, final StepBuilderFactory stepBuilderFactory) {
this.jobBuilderFactory = jobBuilderFactory;
this.stepBuilderFactory = stepBuilderFactory;
}
#Bean
public FileMessageToJobRequest fileMessageToJobRequestTransformer(final Job myJob) {
return new FileMessageToJobRequest(myJob, "input.file.name");
}
#Bean
public MessageSource<File> fileMessageSource() {
final FileReadingMessageSource fileReadingMessageSource = new FileReadingMessageSource();
fileReadingMessageSource.setDirectory(directory));
fileReadingMessageSource.setFilter(new CompositeFileListFilter<>(Arrays.asList(
new AcceptOnceFileListFilter<>(),
new SimplePatternFileListFilter(pattern)
)));
return fileReadingMessageSource;
}
#Bean
public IntegrationFlow pollingFlow(final FileMessageToJobRequest fileMessageToJobRequest, final JobLaunchingGateway jobLaunchingGateway) {
return IntegrationFlows.from(fileMessageSource(),
c -> c.poller(Pollers.fixedDelay(10, TimeUnit.SECONDS)))
.transform(fileMessageToJobRequest)
.handle(jobLaunchingGateway)
.get();
}
#Bean
public JobLaunchingGateway jobLaunchingGateway(final JobLauncher jobLauncher) {
return new JobLaunchingGateway(jobLauncher);
}
// Step definition omitted for readability
#Bean(name = "myJob")
public Job myJob(final JobCompletionNotificationListener listener, final #Qualifier("step1") Step step) {
return jobBuilderFactory.get("myJob")
.preventRestart()
.incrementer(new RunIdIncrementer())
.listener(listener)
.flow(myStep)
.end()
.build();
}
}
Everything works but I keep getting the following exception after job execution:
2017-06-28 16:55:20.510 ERROR 5480 --- [ask-scheduler-1] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessagingException: Dispatcher failed to deliver Message; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available, failedMessage=GenericMessage [payload=JobLaunchRequest: myJob, parameters={input.file.name=/tmp/example.csv}, headers={id=99f4784a-1531-7d64-5abd-4ffe23455c45, timestamp=1498661720296}]
at org.springframework.integration.dispatcher.AbstractDispatcher.wrapExceptionIfNecessary(AbstractDispatcher.java:133)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:120)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:148)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:89)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:292)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:212)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:129)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:115)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:148)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:89)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.handleMessage(SourcePollingChannelAdapter.java:210)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:272)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:58)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:190)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:186)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:353)
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:55)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:344)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:287)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:212)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:129)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:115)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
... 41 more
How can I stop JobLaunchingGateway from posting Messages to output-channel after executing a Job?
That's because JobLaunchingGateway is reqeust/reply component, which requires an outputChannel or replyChannel header. At the same time you have only this in your config:
.handle(jobLaunchingGateway)
.get();
If you are not interested in the reply from there, you can just add this in the end:
.handle(jobLaunchingGateway)
.channel("nullChannel")
.get();
I am using Spring Integration 4.2.5.RELEASE and Spring Integration Java DSL 1.1.2.RELEASE.
I am having trouble getting a custom conversion to work. I have registered the custom converter to convert from byte[] to my.object.MyClass
#Bean
#IntegrationConverter
public Converter bytesToMyClass() {
return new Converter<byte[], my.object.MyClass>() {
#Override
public my.object.MyClass convert(byte[] source) {
try {
return my.object.MyClass.newBuilder().mergeFrom(source).build();
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Could not convert message.", e);
}
}
};
}
Then I set up my integration flow. The goal is to route messages down one of two paths based on a variable called insertBuffer. If insertBuffer is > 1, then aggregate messages. Otherwise, just wrap the single message in a collection and send it to the service method. Here is my flow:
#Bean
public IntegrationFlow routeInput( MessageChannel input, MyClassService service ) {
return IntegrationFlows.from(input)
.<my.object.MyClass, Boolean>route((my.object.MyClass payload) -> insertBuffer > 1, mapping -> mapping
.subFlowMapping("true", aggregateflow -> aggregateflow
.<my.object.MyClass, Collection<my.object.MyClass>>aggregate(a -> a
.correlationStrategy(message -> 0) //all messages are part of the same group for now.
.releaseStrategy(group -> group.size() >= insertBuffer)
.sendPartialResultOnExpiry(true)
.expireGroupsUponCompletion(true)
.expireGroupsUponTimeout(true)
.groupTimeout(2000)))
.subFlowMapping("false", single -> single
.<my.object.MyClass, Collection<my.object.MyClass>>transform(Arrays::asList)
))
.handle(Collection.class, (payload, headers) ->
service.saveResult(payload))
.get();
}
However, when I try running this, I get the following Exception java.lang.ClassCastException: [B cannot be cast to my.object.MyClass (full stack below).
After some debugging, I notice that when org.springframework.integration.dsl.LambdaMessageProcessor#processMessage is trying to process the message, the payloadType is java.lang.Object when I think it should be my.object.MyClass.
It seems like I have all of my generics correct, what am I missing?
Full stacktrace:
ERROR o.s.i.handler.LoggingHandler - org.springframework.messaging.MessageHandlingException: nested exception is java.lang.ClassCastException: [B cannot be cast to my.object.MyClass
at org.springframework.integration.dsl.LambdaMessageProcessor.processMessage(LambdaMessageProcessor.java:130)
at org.springframework.integration.router.AbstractMessageProcessingRouter.getChannelKeys(AbstractMessageProcessingRouter.java:80)
at org.springframework.integration.router.AbstractMappingMessageRouter.determineTargetChannels(AbstractMappingMessageRouter.java:148)
at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:154)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:231)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.endpoint.PollingConsumer.handleMessage(PollingConsumer.java:103)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:251)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:57)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:176)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:173)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:330)
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:55)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:324)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: [B cannot be cast to my.object.MyClass
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.integration.dsl.LambdaMessageProcessor.processMessage(LambdaMessageProcessor.java:127)
... 37 more
The problem with Lambda that it can't determine generic type at runtime: Java: how to resolve generic type of lambda parameter?
That's why we have there an overloaded method on the matter:
.<my.object.MyClass, Boolean>route(my.object.MyClass.class, payload -> insertBuffer > 1, mapping -> mapping