Camel exception before reaching route - exception

I have a restlet route as below
from("restlet:/api?restletMethod=GET").log("API Reached");
The problem is from("restlet:/api?restletMethod=GET") throws an exception when I send an invalid url like http://localhost:8080/api?query=%s%n%s.
How to handle this exception? onException is not working as the request is not reaching the route

I believe you should configure endpoint like this.
RestletEndpoint endpoint = context.getEndpoint("restlet:http://localhost:8080/api", RestletEndpoint.class);
endpoint.configureProperties(Collections.singletonMap("bridgeErrorHandler", true));

Related

Circular error-handler detected at route: {} - breaking out processing Exchange: {}

I am having multiple camel routes written in Java DSL exceptions are handled using OnException.
Below are my requirements.
Fetch token from cache and make http call
If http call fails with invalid token then make a back end call to get new token and then make http call
If http call fails with specific error then needs to handle it properly.
Issue:
If http call fails with invalid token then it is making backend call to fetch the token and then calling http request using exception handling code. Now the http call failed again while calling from OnException with some other error and it is not going to OnException and giving circular error handler message.
Please help me to handle this error. Thankyou
I am using SpringBoot camel starter 3.8.0 and Java 11

I wan to send exception message from one quarkus service and another quarkus service. How do I do that?

I have two services, If any exception is thrown is one service I should be able to receive that exception is other service which is making the call to that service. In short I want to communicate the exception body from one service to another.
Currently the exception response is :
Received: 'Server response is: 500' when invoking: Rest Client method: 'XXX' regardless of whatever the exception message is thrown.
I want the exception message message to be communicated to the calling services.
Solution but not conventional : The Error message I am currently sending throw headers, The exception body is not picked.
From your service1 you send Response with any http status you want. At your service2 to while writing client you need to catch WebApplicationException to know what status returned by service1 client.
[Optional]
You can use org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper to map http response status to your custom exceptions at your service2

Intercept Http Endpoint Exception [Mule ESB]

I'am using Mule 3.3.0 CE and I would have a custom behaviour when an exception is thrown in an http outbound endpoint (i.e when I get a Connection Refused Exception or Connection Timeout Exception). Let's assume that I have this scenario: a SOAP Component and a Http Outbound Endpoint that realize together a cxf service client and let's assume that I can't use any exception strategy.
I would write an Interceptor which intercept the http exception (i.e Connection Refused) and in which I can write a custon behaviour (i.e send the message in a queue).
I need of an interceptor that intercept che http exception and no a SOAP Fault (that could be intercepted with a SOAPFaultInterceptor).
How can I realize this model?
Thank you all for any help
I found the solution. I used a custom interceptor ( component) just before the Http component and I extended the AbstractEnvelopeInterceptor that gives to me the possibility to work before, after and during the component is processing the message.
With this perspective, I implemented the last method. This method's sign contains a boolean value that is setted is an exception occurred. In this way I can leverage this method to handle any kind of exceptions that is related to Http Component.

In Spring 3.0.5 and coding it to serve JSON, what is this log output trying to tell me?

Using Spring 3.0.5, I am trying to return a list of strings in JSON format.
I read the post spring-mvc-json-response
I have available to me jackson-mapper code 1.4.2 and it's on my classpath.
I am also using <context:component-scan base-package="com.funfun.foofoo2" /> which should satisfy the <mvc:annotation-driven> requirement.
I am returning a List<String> although I have tried just a bean too.
When I return raw JSON as a String, it works.
What is the following log output telling me? Is it saying it cannot find the Jackson JSON Mapper and thus the MappingJacksonHttpMessageConverter is not loaded?
17:19:01,037 DEBUG [AnnotationMethodHandlerExceptionResolver:132] Resolving exception from handler [com.funfun.foofoo2.CarModelsController#181fa4b]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
17:19:01,037 DEBUG [ResponseStatusExceptionResolver:132] Resolving exception from handler [com.funfun.foofoo2.CarModelsController#181fa4b]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
17:19:01,037 DEBUG [DefaultHandlerExceptionResolver:132] Resolving exception from handler [com.funfun.foofoo2.CarModelsController#181fa4b]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
17:19:01,053 DEBUG [DispatcherServlet:824] Null ModelAndView returned to DispatcherServlet with name 'appServlet': assuming HandlerAdapter completed request handling
Update: I am using jQuery's getJSON. In Firefox Firebug, I see the header coming over as application/json. The Spring method is constrained to only handle requests for JSON.
You need more than jackson-mapper, you need jackson-core as well, and preferably something newer than the rather old 1.4.x versions.
Basically what this exception (HttpMediaTypeNotAcceptableException) means is that the client is specifying an accepts header in their HTTP request, and it likely isn't accepting JSON. How are you making this request? AJAX call? If so, use Firebug or something to inspect the XHR and see what the accepts header is set to.
Just check the Accept param in your HTTP request header. If you are using XMLHttpRequest to make the ajax call, don't forget to change the requestHeader as follow:
xmlhttp.open("POST", custom_url, this.async);
xmlhttp.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml,application/json;q=0.9,*/*;q=0.8");
Regards,
David.

java.lang.IllegalStateException: Cannot create a session after the response has been committed

I've got this really strange request for an invalid URL on:
Invalid URL: /cgi-bin/1st.cgi
This is causing the following error:
SEVERE: Exception initializing page context
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2381)
at org.apache.catalina.connector.Request.getSession(Request.java:2098)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:544)
...
How can I solve this issue?
What's happening is the response stream has been closed. Either you already sent a redirect, or committed some other type of response. I recommend getting your session object before you perform any response, and save the response until there is nothing left to do with the HttpServletRequest or HttpServletResponse objects.
A good practice is to return from your Servlet right away after performing a redirect, that way you can avoid some of these problems.
I had this problem because of multiple tag <h:outputScript target="head">