Camel kafka logging incorrect details in messageHistory - java

I am using camel kafka component 2.19 (Latest). I am initializing kafka producer endpoint with "my-topic". but topic is calculated at the runtime say "my-error-topic" and I set it in the header so the message is produced to "my-error-topic". Everything works fine.
The problem is when messageHistory is logged, it logs initial route with the topic which I used for initialization which makes it misleading information for support guys because it gives them an idea that message is produced to "my-topic." As a workaround, I have stopped logging message history. But still I got it in logs from defaultErrorHandler.log(). Hence it is still misleading.
Please tell me the solution.

No this is correct as it does it, as it logs the endpoint url from the route (eg you can find exactly where in the route it was). Any kind of header override is a special use-case here, you can log the headers if you use error handling in Camel where you can log anything you want, such as the exception message, stacktrace, message body, headers etc.

Related

Apache does not update documentation? Major Bug in Java

I'm getting this error
Cannot display ObjectMessage body. Reason: Failed to build the body from content. Serializable class not available to the broker. Reason: java.lang.ClassNotFoundException: Forbidden class com.company.data.TicketData! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at this for more information on how to configure trusted classes.
I added System.setProperty("org.apache.activemq.SERIALIZABLE_PACKAGES","*"); in my code that invokes the creation of the JMS and doesn't work.
I also set setx org.apache.activemq.SERIALIZABLE_PACKAGES "*" in the cmd but still the same error.
Even if you check the error page.
it talks about an env script file that does not exist when you download the Apache ActiveMQ.
What can I do?? There are some files in /config but I don't see how do enable this? Why Apache has documentation that even doesn't work?
This is expected. The Java runtime of your broker can only deserialize the ObjectMessage if
The class is part of the broker's classpath. The exception
"java.lang.ClassNotFoundException" sounds like that's the issue. Try adding your company's jar file into the ActiveMQ classpath.
The class implements java.io.Serializable. Adding something to your
client's Java runtime won't help. It must be know to the broker, so
best is really to let your class implement that interface.
ActiveMQ
also requires to 'trust' an Object. So your Broker must have this class whitelisted, for example by starting the Broker with -Dorg.apache.activemq.SERIALIZABLE_PACKAGES=* - this only works onwards from a certain ActiveMQ version > 5.12.2
Quite frankly, you should stay away from JMS ObjectMessage. There was an ActiveMQ bug in the area a while ago and it's a constant security hole. Try to send as BytesMessage as externalized Object, or maybe send your Object as TextMessage in XML or JSON format.

Failed to build body from content in activeMQ - Spring generic message used

I send a org.springframework.messaging.support.GenericMessage to a queue in ActiveMQ by org.springframework.jms.core.JmsTemplate. in ActiveMQ, I see this message :
Cannot display ObjectMessage body. Reason: Failed to build body from content.
Serializable class not available to broker.
Reason: java.lang.ClassNotFoundException: org.springframework.messaging.support.GenericMessage
and so I can't read that message in a client.
I set trustAllPackages to true in my activeMQConnectionFactory and problem doesn't solve. How to solve it ?
The JmsTemplate will serialize the entire GenericMessage as a java object, so spring-messaging is needed on the class path of the receiving system as well.
class not available to broker.
It looks like you might be trying to view the message in the admin UI, which doesn't understand spring-messaging classes.
If you want to map the GenericMessage to a JMS Message instead, use the JmsMessagingTemplate instead (one of the send() methods); the broker might be able to display such a message (depending on the payload type).
Simply put:
Add the required jar or class files or the serialised messages in the lib folder of activemq and restart activemq.
It worked for me

Trying to capture response from ActiveMQ in my camel route

I am attempting to create a camel route using blueprint that sends a message on an activeMQ queue then listens to the response on the temporary queue created in the request. This seems pretty basic, but I can't find an example that utilizes it.
I have tried searching and reading the docs and here's what I've found:
http://camel.apache.org/jms.html
http://camel.apache.org/exchange-pattern.html
http://camel.apache.org/request-reply.html
https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/EIP_Transaction_Guide/files/FMRTxnJMSSynchronous.html
http://kosalads.blogspot.com/2014/04/ApacheCamelRequestReplyPatternWithJavaDS.html
http://grokbase.com/t/camel/users/128n88xeva/how-to-use-request-reply-in-jms
http://camel.465427.n5.nabble.com/ExchangePattern-InOut-I-Can-t-get-any-response-td5056301.html
https://examples.javacodegeeks.com/enterprise-java/apache-camel/apache-camel-exchange-example/
Which is frustrating.
I have my activeMQ component set up such:
<to pattern="InOut" uri="activemq:queue:tripRequest.updateStatus.v1.0?useMessageIDAsCorrelationID=true"/>
<log message="Update Status responded ${out.body}"/>
The log shows the input XML, which surprised me. After checking the docs, I created a new activeMQ instance that listens to the same queue and dumps to a log, but this threw errors and it keeps mixing up my log and unmarshal objects on my other route.
How can I accomplish this?
Check the answer in the link below. It should give you hints on how to build your active-mq uri for a request/reply scenario.
Implement Request-Reply pattern using ActiveMQ, Camel and Spring

Spring Webapp throwing 404 errors with no console log

I am working on a web application using the Spring framework and Hibernate. My problem is that I often receive 404 errors caused by a mistake I have made somewhere in the codebase but there are no exception messages in the console. Because of this I am struggling to find where the mistake is because the project has become very large and manually trying to find the problem is impractical. I'm assuming that Spring is causing the problem so my question is: is there some way of enabling more detailed error messages? Thanks
404 is an http error and only your web server might be knowing of it. Very likely with these failed requests, your application server or Spring container was never hit. Look for web server logs to identify the problem.
Troubleshooting 404 on IIS server
http://blogs.iis.net/tomkmvp/archive/2009/04/27/troubleshooting-a-404.aspx
Troubleshooting 404 on RAD web server
http://www-304.ibm.com/support/docview.wss?uid=swg27035752&aid=1
As a couple of people have already alluded to it, the issue here is that certain errors (like the 404 exception) get intercepted by the Servlet container, therefore never reaching Spring and whatever logging mechanisms you have may have set up. So the trick here is to change the order of importance of your Exceptions so that Spring gets a crack at it.
The best approach I have ever come across to catch, handle and adequately log all exceptions in Spring is described in this article: http://steveliles.github.io/configuring_global_exception_handling_in_spring_mvc.html
I have been implementing this setup since I came across that blog post, and it has been a lifesaver to say the least. It will give you the detailed error messages you need. The key is to basically create a custom Exception Handler by implementing Spring's HandlerExceptionResolver and Ordered interfaces, then returning the lowest possible order number, thus moving your exception handling up the totem pole:
import org.springframework.core.*;
import org.springframework.web.servlet.*
public class LoggingHandlerExceptionResolver
implements HandlerExceptionResolver, Ordered {
public int getOrder() {
return Integer.MIN_VALUE; // we're first in line, yay!
}
public ModelAndView resolveException(
HttpServletRequest aReq, HttpServletResponse aRes,
Object aHandler, Exception anExc
) {
anExc.printStackTrace(); // again, you can do better than this ;)
return null; // trigger other HandlerExceptionResolver's
}
}
The problem ended up being that there were a couple of missing annotations from one of my Hibernate entities. Following the procedure from the link below helped track it down by providing more detailed error messages:
http://www.captaindebug.com/2011/07/using-hibernate-validation-annotation.html
I also hit the problem of no console output while 404 error.
As in The Saint's answer, one of the causes of no console log:
the issue here is that certain errors (like the 404 exception) get intercepted by the Servlet container
"spring-framework-reference-3.2.3.pdf" --> 1.3 --> Logging --> Using Log4J, solved the problem in my environment.

Stop RestTemplate logging warning on 404 not found

We have a service based platform where its possible (/common) for a resource not to be found - e.g. calling our security module with the wrong username will return 404 Not Found, something that will happen every time a user makes a typo in their login box.
We use Spring RestTemplate for these calls, which is great, but every time a 404 is encountered it dutifully logs a warning which is spamming our logs.
We obviously don't want to suppress warnings, except in the specific case of 404 not found but there doesn't appear to be a way to do this (logger is private/final, method to invoke it is private etc).
Our solution is not good - to return 200/OK with empty dataset and handle a null pointer, which is both nasty and not a good restful implementation.
Does anyone know a better way to do this?
How about using a RegexFilter filter on your logging appender?
http://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter
... that's the Log4J way of doing it, but I'm guessing there must be similar filters for other logging libraries.
Implement a ResponseErrorHandler that returns false for hasError().
Assign it to your rest template using setErrorHandler().
The warning will not be logged.
This was logged in as issue SPR-12760 in the issue tracker of Spring Framework and resolved earlier this year (2015) in version 4.1.6. The solution was twofold: first, the warning message was downgraded to a debug message, and second, it was made easier to override the part of the code that is responsible for handling errors. So as a solution to your problem, upgrade the org.springframework:spring-web module to at least version 4.1.6.RELEASE.

Categories

Resources