org.apache.camel.InvalidPayloadException when sumbitting form data - apache-camel

I have the following apache camel routes in my quarkus code:
rest("/")
.get("/v*").to(MY_SERVICE)
.post("/v*").to(MY_SERVICE)
.put("/v*").to(MY_SERVICE)
.delete("/v*").to(MY_SERVICE)
When I send a POST request with form data using the following code:
given().urlEncodingEnabled(true)
.param("email_address", "user#example.com")
.post("/v3/test");
I get the following error:
ERROR [org.apa.cam.pro.err.DefaultErrorHandler] (vert.x-worker-thread-1) Failed delivery for (MessageId: 2B577A1B8400C13-0000000000000001 on ExchangeId: 2B577A1B8400C13-0000000000000001). Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: {email_address=user#example.com} of type: java.util.HashMap on: Message[2B577A1B8400C13-0000000000000001]. Caused by: No type converter available to convert from type: java.util.HashMap to the required type: java.io.InputStream with value {email_address=user#example.com}. Exchange[2B577A1B8400C13-0000000000000001]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: java.util.HashMap to the required type: java.io.InputStream with value {email_address=user#example.com}]
Message History (complete message history is disabled)
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[route10 ] [route10 ] [from[platform-http:///v*?httpMethodRestrict=POST] ] [ 12]
...
[route6 ] [toD3 ] [{{mailgun.url}}${headers.CamelHttpUri}?bridgeEndpoint=true&throwExceptionOnFai] [ 0]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: {email_address=user#example.com} of type: java.util.HashMap on: Message[2B577A1B8400C13-0000000000000001]. Caused by: No type converter available to convert from type: java.util.HashMap to the required type: java.io.InputStream with value {email_address=user#example.com}. Exchange[2B577A1B8400C13-0000000000000001]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: java.util.HashMap to the required type: java.io.InputStream with value {email_address=user#example.com}]
at org.apache.camel.support.MessageSupport.getMandatoryBody(MessageSupport.java:117)
at org.apache.camel.component.http.HttpProducer.createRequestEntity(HttpProducer.java:576)
at org.apache.camel.component.http.HttpProducer.createMethod(HttpProducer.java:477)
at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:118)
at org.apache.camel.support.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:66)
at org.apache.camel.processor.SendDynamicProcessor.lambda$process$0(SendDynamicProcessor.java:195)
at org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProducer(DefaultProducerCache.java:317)
at org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:180)
at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:395)
at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148)
at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:147)
at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:312)
at org.apache.camel.component.platform.http.vertx.VertxPlatformHttpConsumer.lambda$handleRequest$2(VertxPlatformHttpConsumer.java:184)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:313)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.util.HashMap to the required type: java.io.InputStream with value {email_address=user#example.com}
at org.apache.camel.impl.converter.CoreTypeConverterRegistry.mandatoryConvertTo(CoreTypeConverterRegistry.java:275)
at org.apache.camel.support.MessageSupport.getMandatoryBody(MessageSupport.java:115)
... 18 more
What went wrong? How to fix it?

Try using formParams method to send form data:
Map<String, String> formParams = new HashMap<>();
formParams.put("email_address", "user#example.com");
given()
.contentType("application/form-data")
.formParams(formParams)
.post("/v3/test");

Related

Exposing Rest API with Apache Camel - getting 404

I tried very simple Route:
restConfiguration()
.component("servlet");
rest().get("/hello")
.to("direct:hello");
from("direct:hello")
.log(LoggingLevel.INFO, "Hello World")
.transform().simple("Hello World");
And indeed, when lunching my spring boot application I can see that the route listens to it:
[enter image description here][1]
2021-04-14 15:03:31.759 INFO 25248 --- [ main] o.a.c.i.e.InternalRouteStartupManager : Route: route1 started and consuming from: direct://hello
2021-04-14 15:03:31.760 INFO 25248 --- [ main] o.a.c.i.e.InternalRouteStartupManager : Route: route2 started and consuming from: servlet:/hello
2021-04-14 15:03:31.768 INFO 25248 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Total 2 routes, of which 2 are started
2021-04-14 15:03:31.768 INFO 25248 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Apache Camel 3.7.1 (camel-1) started in 220ms
However, when I tried reaching this address, I get 404 error.
{
"timestamp": "2021-04-14T12:17:11.975+00:00",
"status": 404,
"error": "Not Found",
"message": "",
"path": "/hello"
}
and also in my console:
2021-04-14 15:17:11.973 WARN 25248 --- [nio-8080-exec-4] o.s.web.servlet.PageNotFound : No mapping for GET /hello
Any idea how to solve it?
I would say here that I googled this issue and solution like using "camel.component.servlet.mapping.context-path=/*
" or using "camel" prefix didn't work for me.
Thanks!
create a bean like that any configuration class
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
#Bean
public ServletRegistrationBean camelServletRegistrationBean() {
ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(), "/*");
registration.setName("CamelServlet");
return registration;
}}
for example camel rest and spring boot : https://github.com/erayerdem/camelrest

module not found: Can't resolve '../types/index'

I have spent about an hour trying to figure out this error but haven't had any luck.
I have types index.d.ts in folder types. The content of the types looks like this
export interface tag {
created_at: string
id: number
name: string
}
export interface task {
created_at: string
id: number
title: string
updated_at: string
tags: tag[]
}
export interface allTaksAndTags {
tags: tag[]
tasks: task[]
}
When I am trying to import them, I am getting following error
Failed to compile.
./src/components/task.tsx Module not found: Can't resolve
'../types/index' in '/Users/h/Desktop/timetracking/src/components'
I have attached below the screenshot, Can someone help me in figuring out what I am doing wrong here?
Type definition files are not meant to be used like that.
Remove d.ts in your index file and change its name as index.ts
Type definition files are automatically generated when you build your typescript project.

Hyperlegder fabric node Error: 2 UNKNOWN: Stream removed Unhandled error for request GET /api/fabric/1_0/channels:

This is the issue while running the fabric-sdk-rest code:
"Peer {
_options:
{ 'grpc.ssl_target_name_override': 'peer0',
'grpc.default_authority': 'peer0',
'grpc.max_receive_message_length': -1,
'grpc.max_send_message_length': -1 },
clientCert: undefined,
_url: 'grpc://0.0.0.0:7051',
_endpoint: Endpoint { addr: '0.0.0.0:7051', creds:
ChannelCredentials {} },
_name: '0.0.0.0:7051',
_request_timeout: 45000,
_grpc_wait_for_ready_timeout: 3000,
_endorserClient:
ServiceClient {
'$interceptors': [],
'$interceptor_providers': [],
'$channel': Channel {} },
_discoveryClient:
ServiceClient {
'$interceptors': [],
'$interceptor_providers': [],
'$channel': Channel {} }
}
Error Log:
[fabricconnector.js]: Failed to queryChannels: Error: 2 UNKNOWN: Stream removed
Unhandled error for request GET /api/fabric/1_0/channels: Error: 2 UNKNOWN: Stream removed
at Object.exports.createStatusError (/home/rev-mg/HyperledgerTest/fabric-sdk-rest/packages/loopback-connector-fabric/node_modules/grpc/src/common.js:87:15)
at Object.onReceiveStatus (/home/rev-mg/HyperledgerTest/fabric-sdk-rest/packages/loopback-connector-fabric/node_modules/grpc/src/client_interceptors.js:1188:28)
at InterceptingListener._callNext (/home/rev-mg/HyperledgerTest/fabric-sdk-rest/packages/loopback-connector-fabric/node_modules/grpc/src/client_interceptors.js:564:42)
at InterceptingListener.onReceiveStatus (/home/rev-mg/HyperledgerTest/fabric-sdk-rest/packages/loopback-connector-fabric/node_modules/grpc/src/client_interceptors.js:614:8)
at callback (/home/rev-mg/HyperledgerTest/fabric-sdk-rest/packages/loopback-connector-fabric/node_modules/grpc/src/client_interceptors.js:841:24)"
I had same error message when client tried create insecure connection but server use ssl
If you use node.js try to replace
grpc.credentials.createInsecure()
with
grpc.credentials.createSsl()

Type 'Observable<any>' is not assignable to type 'Observable<T>'

I have the following code
import {HttpClient} from '#ngular/common/http';
private httpClient: HttpClient;
do_request(method: string,
url: string,
headers?: HttpHeaders,
content?: string,
contentType?: string): Observable<MyResponse>{
let options = {
observe: 'response' as 'response',
responseType: 'text' as 'text',
headers: headers,
body: content:
}
return this.httpClient.request(method, url, options)
.map(res=> new MyResponse(res.status, res.body))
.catch(err=>Observable.throw(new MyResponse(err.status)));
}
This code is giving me the following error
error TS2322: Type 'Observable' is not assignable to type 'Observable'. Property 'source' is protected but type 'Observable' is not a class derived from 'Observable'
I'm using Rxjs 5.4.3, Angular 4.4.3 and TypeScript 2.5.3.
I've found several possible error sources and tried the suggested solutions with no luck:
Typescript version(I downgraded to 2.3 with similar results)
Importing a package that also has a dependency on rxjs using npm link (I installed it locally, with same result).
I will appreciate any suggestion on how to fix this issue.
Based on your comment, I think you should be explicit in your typings, hence, import Observable and declare the types:
return this.httpClient.request(method, url, options)
.map((res): MyResponse => new MyResponse(res.status, res.body))
.catch((err):Observable<MyResponse> => Observable.throw<MyResponse>(new MyResponse(err.status)));
The important part is that the throw (as well as from and other operators) can be typed and the syntax is `Observable.operator(operands...)

Camel CXF Component: Call ws with Json String body

I could not get along with the Camel CXF component. The problem is, th WS operation that I want to call has only a String parameter which is a JSON expression.
But , with every dataFormat (MESSAGE,POJO,PAYLOAD), it gives exception.
There are classes which are generated from wsdl2java by cxf itself and I am using them to call ws.
<cxf:cxfEndpoint id="wsEndpoint" address="http://www.wssss.com" serviceClass="aa.bb.cc.WebService" serviceName="sendMessage">
<cxf:properties>
<entry key="dataFormat" value="CXF_MESSAGE"/>
<entry key="defaultOperationName" value="sendMessage"/>
<entry key="relayHeaders" value="false"/>
<entry key="wrapped" value="true"/>
<entry key="loggingFeatureEnabled" value="true"/>
<entry key="synchronous" value="true"/>
<entry key="defaultOperationNamespace" value="http://com.asdad.ns"/>
</cxf:properties>
</cxf:cxfEndpoint>
and I am using this in:
camel:to uri="cxf:bean:wsEndpoint"/>
And generated service class is:
#WebResult(name = "response", targetNamespace = "")
#RequestWrapper(localName = "sendMessage", targetNamespace = "http://com.xxx.comet.ws.notification", className = "aaa.bbb.ccc.SendMessage")
#WebMethod
#ResponseWrapper(localName = "sendMessageResponse", targetNamespace = "http://com.xxx.comet.ws.notification", className = "aaa.bbb.ccc.SendMessageResponse")
public java.lang.String sendMessage(
#WebParam(name = "request", targetNamespace = "")
java.lang.String request
);
Any help will be appreciated
Thanks
EDIT: The problem is, exchange.in body could not be bound with the service method's parameter so request is empty. There is the problem in here
INFO: Outbound Message
---------------------------
ID: 1
Address: http://www.wssss.com
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml
Headers: {Accept=[*/*], breadcrumbId=[ID-TT08328507-61662-1416561287466-0-1], SOAPAction=[""]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/><soap:Body/></soap:Envelope>
--------------------------------------
Nov 21, 2014 4:45:04 AM org.apache.cxf.services.sendMessage.MessagePort.Message
INFO: Inbound Message
----------------------------
ID: 1
Response-Code: 500
Encoding: UTF-8
Content-Type: text/xml;charset=UTF-8
Headers: {connection=[close], Content-Length=[271], content-type=[text/xml;charset=UTF-8], Date=[Fri, 21 Nov 2014 09:15:04 GMT], Server=[Apache-Coyote/1.1]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>No binding operation info while invoking unknown method with params unknown.</faultstring></soap:Fault></soap:Body></soap:Envelope>
--------------------------------------
org.apache.cxf.binding.soap.SoapFault: No binding operation info while invoking unknown method with params unknown.
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:84)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:51)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:40)
The outbind message is an empty SOAP envelop.
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/><soap:Body/></soap:Envelope>
Did setup the invocation parameter rightly?

Resources