No endpoint could be found for - Camel Http Integration - apache-camel

I'm trying to run a simple test with Apache Camel:
from("http://localhost:61554/api/v1/MyController/my-endpoint")
.to("direct:a")
.log("$({body}");
I'm getting the following error: "No endpoint could be found for: http://localhost:61554/api/v1/MyController/my-endpoint, please check your classpath contains the needed Camel component jar"
I'm very new to Camel and Java. Can someone please tell me why this error is coming up? Should I be using from("direct:x")... ? If, so where do I map my "direct" endpoints to concrete ones?
Thanks

You cannot use the http component as consumer (eg in from) - its a http client for calling HTTP servers (so its a producer, eg to).
Instead to have HTTP as consumer you can use camel-servlet, camel-jetty, camel-undertow, etc.

Related

How to add an trailing slash to the camel http component of camel

Im am trying to call a rest post service from my Camel route.
The rest service is deployed at https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag/.
Calling the Service from a Rest Client like VS Code works if there is a trailing slash (after verteileauftrag).
In my camel route I have configured the following:
restConfiguration().host("https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1").component("http").bindingMode(RestBindingMode.json);
and in then later using the config:
.to("rest:post:verteileauftrag?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType")
If I execute the code, I get a 404 HTTP Error from the Backend as the URL used is
https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag. So without a trailing slash.
I have tried to add it like .to("rest:post:verteileauftrag/?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType")
but no success.
Do you have any idea how to tell the http component in the rest configuration how to add the trailing slash?
Thank you very much.
Using redhat fuse 7_10_2.
Regards Michel
Based on a collegues example I reimplemented the Rest Service call with a normal .to("URL") configuration in the routebuilder with setting the appropriate Headers for HTTP Post and content type json. Would still be interessted in any answer, but not waiting on one.

Camel netty4-http client handling of http 100-Continue

We are using netty4-http as a client and have a problem when the server side answers with a http 100-Continue.
I expected the client to handle that internally and continue the call but it's actually returning http 100.
The test org.apache.camel.component.netty4.http.NettyHttpClientExpectContinueTest in the Camel code seems to test exactly that situation but it's ignored with the comment "TODO Fix it, need to send the response back". So I guess it has been a plan to implement it.
I'm new too Netty I wondering if it's possible to handle that in the Netty pipeline by overriding the ClientInitializerFactory (I found out it's the HttpObjectAggregator that returns 100)?
So any help how do achieve that in the Netty pipeline or any tips how to achieve that in some other way is welcome.

Is there ValueInputOption parameter support in google sheet component in Apache camel?

The google sheet API (https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption) mentions ValueInputOption as mandatory.
I am trying to write to googlesheet using google sheet component of Apache camel.
I am getting ResolveEndpointFailedException:
org.apache.camel.ResolveEndpointFailedException: Failed to resolve
endpoint:
google-sheets://data/update?ValueInputOption=USER_ENTERED&accessToken=....&applicationName=CamelGoogleApp&clientId=...&clientSecret=....&refreshToken=.....&spreadsheetId=....&values=#vrobj
due to: There are 1 parameters that couldn't be set on the endpoint.
Check the uri if the parameters are spelt correctly and that they are
properties of the endpoint. Unknown
parameters=[{ValueInputOption=USER_ENTERED}]
where camel version is 3.0.0-M3 and jars in use are camel-spring-boot-starter and camel-google-sheets-starter.
You can use header CamelGoogleSheets.valueInputOption to pass ValueInputOption into producer.
from("direct:writeToSheet")
.setHeader("CamelGoogleSheets.valueInputOption", constant("USER_ENTERED"))
.to("google-sheets://xxx")

Apache Camel http mock testing fails with Connection refused

I am testing this Camel route:
from("direct:start")
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
.to("http://127.0.0.1:8088/")
.to("mock:result");
...using this mock server:
mockServer = MockRestServiceServer.createServer(new RestTemplate());
mockServer.expect(
requestTo("http://127.0.0.1:8088/"))
.andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK)
.contentType(MediaType.APPLICATION_JSON)
.body("")
);
...but receive:
I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
Are there anything obvious I am missing? How can I proceed to find the cause?
You cannot use MockRestServiceServer. This does not start real server and therefore can be used only for mocking responses to Spring RestTemplate. Apache Camel does not utilize RestTemplate for sending requests, it uses Apache HttpClient.
You can either:
Advice your http endpoint with mock endpoint - preferred way. Example using isMockEndpointsAndSkip eg here: camel mock - MockEndpoint.whenAnyExchangeReceived process method not execute
Or start any full Http server in your unit test - For this you can extend HttpServerTestSupport containing some prepared methods - example HttpBodyTest

Apache flink external api call

Is it possible to call an external api (RESTful) inside apache flink code. If it is possible then how we can do that.
I am calling an api from simple java code, it is working fine but when i use the same code in apache flink, it throws an exception :
java.io.IOException: Server returned HTTP response code: 500 for URL: http://example.com/someapi
Is it possible to call an external api (RESTful) inside apache flink code. If it is possible then how we can do that.
You can use the Async I/O feature provided in Flink Streaming API. Flinkā€™s Async I/O API allows users to use asynchronous request clients with data streams. More details and examples here.
java.io.IOException: Server returned HTTP response code: 500 for URL: http://example.com/someapi
This seems to non-flink error since the response is 500. Check the request headers/parameters that is being sent and verify if the http request is being properly created. Try some utilities like PostMan to test the API first.

Resources