Apache flink external api call - apache-flink

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.

Related

No endpoint could be found for - Camel Http Integration

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.

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

Google Cloud Pub/Sub node library error parsing

I'm trying to handle error responses returned from the Google Cloud Pub/Sub api using their node client library. From what I can see, if you use their REST API directly (ie. not through the client library) they return common HTTP error codes:
https://cloud.google.com/pubsub/docs/reference/error-codes
However, their client library returns RPC style errors that do not adhere to http status code conventions.
I have a worker that is processing these responses and is expecting responses to conform to standard http response conventions. Does anyone know if there is a way to intercept the actual HTTP response that the client is handling and extract a status code from it? Alternatively, is there documentation somewhere listing out the potential RPC errors the node client can return so I can set up a mapping from them to http codes?
Thanks!
FYI this got answered as a Github issue here: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/2761#issuecomment-348358474

Can Firebase used callback on embedded system

Now I just get and post Firebase request through sending https request using C language.
Is there any way to use callback for this?
Because I want to get the latest data, now I just polling the https get requests. The SSL handshake may cause delay, so I want to add callback for this.

How to Send POST method with multipart request using CAMEL

How to Send POST method with multipart request using CAMEL
I have an application with camel setup and i need to attach documents and send and HTTP POST request.
How can i do this,
You can always write some java code with the apache httpcompenents library. see http://hc.apache.org/
It is not difficult to use

Resources