I was trying to send an ObjectMessage containing a myObject, instance of myClass, using ActiveMQ as JMS Provider. Call to ActiveMQ is made through Mule 4.3.0.
An error occurred in the receiving application:
Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class client.MyClass! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.
the page says:
If you need to exchange object messages, you need to add packages your applications are using. You can do that with by using
org.apache.activemq.SERIALIZABLE_PACKAGES system property of the
broker. You can add this system property to ACTIVEMQ_OPTS variable in
${ACTIVEMQ_HOME}/bin/env script.
I am using ActiveMQ 5.15.4 . In the \bin subfolder, there is no env script, only the activemq script.
Where should I configure ACTIVEMQ_OPTS so that I, will not get forbidden class error. Or if any alternative solutions will help.
You should define ACTIVEMQ_OPTS in your operating system shell, using the appropriate method for that operating system. For example in Linux set it in the user's profile script, or use the bin/env script.
If you are using Windows you can set it using the UI.
Related
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.
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
I am trying to learn JMS by making two small Java applications, one which sends messages to a queue and another one that consumes the messages. Also I installed the J2EE SDK server on my computer and add to it the necessary ConnectionFactory and Destination objects. For doing this I followed this tutorial. The source code I used is in the mentioned tutorial.
The problem is I cannot get rid of the below NoInitialContextException.
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.xeridia.jmstest.sender.Sender.lookup(Sender.java:21)
at com.xeridia.jmstest.sender.Sender.send(Sender.java:85)
at com.xeridia.jmstest.sender.Main.main(Main.java:5)
How is this caused and how can I solve it?
I've already spent more than 2 days trying to make this work without any result. The server is WebLogic 12c with embedded Coherence server. It is important to mention that I do not run Coherence in standalone mode, instead it starts automatically alongside the application server that has access to Coherence via JNDI context. I am trying to implement POF serialization approach using PortableObject interface to serialize certain objects I save in Coherence. I've also created the corresponding pof-config.xml registering the objects I'm planning to serialize. The only problem is: How do I add the override to the coherence class path?
According to http://docs.oracle.com/cd/E24290_01/coh.371/e22837/gs_config.htm#COHDG5014 I can use the following system property:
java -Dtangosol.pof.config=MyPOF.xml -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
The only problem here is that I have no idea which sh/cmd file to edit, since all edits I made to the files in Oracle_Home\coherence\bin\ had no effect.
Also the same article says that there is a way to confirm the pof-config override:
The output for a Coherence node indicates the location and name of the POF configuration deployment descriptors that are loaded at startup. The configuration messages are among the messages that display after the Coherence copyright text is emitted and are associated with the cache service that is configured to use POF. The output is especially helpful when developing and testing Coherence applications and solutions.
Loading POF configuration from resource "file:/D:/coherence/my-pof-config.xml"
But I couldn't find any of the mentioned lines in the logs produced by the server instance.
Any ideas?
Instead of editing files inside of your Oracle_Home, try the following inside of the weblogic admin console:
Login to admin console
Servers link -> Server Name
Click the Server Start tab
Edit the Arguments: text box and add in -Dtangosol.pof.config=MyPOF.xml
You can also change the classpath, Class Path: box, here if you need to
Every time your server starts it should have that property. If you are not using the nodemanager to start your server, you should do the following instead. Keep in mind this will change the properties for every server in your weblogic domain:
Navigate to your <domain home>/bin directory
Edit startWebLogic.sh/cmd
Edit the JAVA_OPTIONS= line and add in -Dtangosol.pof.config=MyPOF.xml
You can also change the classpath CLASSPATH= here if you need to
I'm building a fast web crawler and I need to have multithreaded DNS resolution, so I picked up a multithreaded DNS service provider called dnsjava. Unfortunately, I can't figure out how to replace the default DNS Service Provider.
I went over the README file for dnsjava, but the instructions are not very through.
Replacing the standard Java DNS
functionality:
Beginning with Java 1.4, service
providers can be loaded at runtime.
To load the dnsjava service provider,
build it as explained above and set
the system property:
sun.net.spi.nameservice.provider.1=dns,dnsjava
This instructs the JVM to use the
dnsjava service provide for DNS at the
highest priority.
There are a couple of things that I'm unclear on:
Where do I place the dnsjava.jar?
Where is the system property supposed to be set (is it programmatic or some type of file change)?
I'm running on a Windows 7 machine and I'm not sure what I need to do to find/modify the system properties... help!?
Update:
Got it: System.setProperty("sun.net.spi.nameservice.provider.1","dns,dnsjava");
A wild guess.
Put the dnsjava.jar file in the classpath of your application.
Have the system property set before launching the main method in your application.