ObjectMessage.setObject() throws javax.jms.JMSException for no apparently reason










0














Having a custom object like this:



package Messages;

import java.io.Serializable;
import javax.jms.TextMessage;

public class MessageObject implements Serializable

private static final long serialVersionUID = 1L;
private TextMessage message;
private String state;
private String sender;
private String receiver;

public MessageObject()



public TextMessage getMessage()
return message;


public void setMessage(TextMessage message)
this.message = message;

* the rest of the getters and setters *




Then I create I try to send to my jms queue an ObjectMessage containing my custom message object:



try {
Context context = new InitialContext();

QueueConnectionFactory factory =
(QueueConnectionFactory)context.lookup("tiwconnectionfactory");
Queue queue = (Queue) context.lookup("tiwqueue");
Connection connection = factory.createConnection();
connection.start();
Session session= connection.createSession(false,
javax.jms.Session.AUTO_ACKNOWLEDGE);

MessageProducer producer = session.createProducer(queue);


MessageObject mymessage = new MessageObject();


ObjectMessage object = session.createObjectMessage();


TextMessage message = session.createTextMessage();
message.setText("Hi");


mymessage.setState("still not read");
mymessage.setMessage(message);
mymessage.setSender("Peter");
mymessage.setReceiver("John");


object.setObject(mymessage);


producer.send(object);


When trying to run the code, exception throwed is:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] [[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()object=Messages.MessageObject@d8b66e3:message=com.sun.messaging.jms.ra.DirectTextPacktatcom.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


So what the problem is? I dont find any errors in my code, and my object is serializable.










share|improve this question























  • Is TextMessage also serializable?
    – Thomas Kläger
    Nov 11 '18 at 19:29










  • @ThomasKläger I'm not sure about that. Do you think thats the problem? Should the error be "exception not serializable" instead of the one i'm getting?
    – Keka Bron
    Nov 11 '18 at 21:09















0














Having a custom object like this:



package Messages;

import java.io.Serializable;
import javax.jms.TextMessage;

public class MessageObject implements Serializable

private static final long serialVersionUID = 1L;
private TextMessage message;
private String state;
private String sender;
private String receiver;

public MessageObject()



public TextMessage getMessage()
return message;


public void setMessage(TextMessage message)
this.message = message;

* the rest of the getters and setters *




Then I create I try to send to my jms queue an ObjectMessage containing my custom message object:



try {
Context context = new InitialContext();

QueueConnectionFactory factory =
(QueueConnectionFactory)context.lookup("tiwconnectionfactory");
Queue queue = (Queue) context.lookup("tiwqueue");
Connection connection = factory.createConnection();
connection.start();
Session session= connection.createSession(false,
javax.jms.Session.AUTO_ACKNOWLEDGE);

MessageProducer producer = session.createProducer(queue);


MessageObject mymessage = new MessageObject();


ObjectMessage object = session.createObjectMessage();


TextMessage message = session.createTextMessage();
message.setText("Hi");


mymessage.setState("still not read");
mymessage.setMessage(message);
mymessage.setSender("Peter");
mymessage.setReceiver("John");


object.setObject(mymessage);


producer.send(object);


When trying to run the code, exception throwed is:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] [[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()object=Messages.MessageObject@d8b66e3:message=com.sun.messaging.jms.ra.DirectTextPacktatcom.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


So what the problem is? I dont find any errors in my code, and my object is serializable.










share|improve this question























  • Is TextMessage also serializable?
    – Thomas Kläger
    Nov 11 '18 at 19:29










  • @ThomasKläger I'm not sure about that. Do you think thats the problem? Should the error be "exception not serializable" instead of the one i'm getting?
    – Keka Bron
    Nov 11 '18 at 21:09













0












0








0







Having a custom object like this:



package Messages;

import java.io.Serializable;
import javax.jms.TextMessage;

public class MessageObject implements Serializable

private static final long serialVersionUID = 1L;
private TextMessage message;
private String state;
private String sender;
private String receiver;

public MessageObject()



public TextMessage getMessage()
return message;


public void setMessage(TextMessage message)
this.message = message;

* the rest of the getters and setters *




Then I create I try to send to my jms queue an ObjectMessage containing my custom message object:



try {
Context context = new InitialContext();

QueueConnectionFactory factory =
(QueueConnectionFactory)context.lookup("tiwconnectionfactory");
Queue queue = (Queue) context.lookup("tiwqueue");
Connection connection = factory.createConnection();
connection.start();
Session session= connection.createSession(false,
javax.jms.Session.AUTO_ACKNOWLEDGE);

MessageProducer producer = session.createProducer(queue);


MessageObject mymessage = new MessageObject();


ObjectMessage object = session.createObjectMessage();


TextMessage message = session.createTextMessage();
message.setText("Hi");


mymessage.setState("still not read");
mymessage.setMessage(message);
mymessage.setSender("Peter");
mymessage.setReceiver("John");


object.setObject(mymessage);


producer.send(object);


When trying to run the code, exception throwed is:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] [[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()object=Messages.MessageObject@d8b66e3:message=com.sun.messaging.jms.ra.DirectTextPacktatcom.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


So what the problem is? I dont find any errors in my code, and my object is serializable.










share|improve this question















Having a custom object like this:



package Messages;

import java.io.Serializable;
import javax.jms.TextMessage;

public class MessageObject implements Serializable

private static final long serialVersionUID = 1L;
private TextMessage message;
private String state;
private String sender;
private String receiver;

public MessageObject()



public TextMessage getMessage()
return message;


public void setMessage(TextMessage message)
this.message = message;

* the rest of the getters and setters *




Then I create I try to send to my jms queue an ObjectMessage containing my custom message object:



try {
Context context = new InitialContext();

QueueConnectionFactory factory =
(QueueConnectionFactory)context.lookup("tiwconnectionfactory");
Queue queue = (Queue) context.lookup("tiwqueue");
Connection connection = factory.createConnection();
connection.start();
Session session= connection.createSession(false,
javax.jms.Session.AUTO_ACKNOWLEDGE);

MessageProducer producer = session.createProducer(queue);


MessageObject mymessage = new MessageObject();


ObjectMessage object = session.createObjectMessage();


TextMessage message = session.createTextMessage();
message.setText("Hi");


mymessage.setState("still not read");
mymessage.setMessage(message);
mymessage.setSender("Peter");
mymessage.setReceiver("John");


object.setObject(mymessage);


producer.send(object);


When trying to run the code, exception throwed is:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] [[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()object=Messages.MessageObject@d8b66e3:message=com.sun.messaging.jms.ra.DirectTextPacktatcom.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


So what the problem is? I dont find any errors in my code, and my object is serializable.







java glassfish jms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 '18 at 19:46

























asked Nov 11 '18 at 19:17









Keka Bron

959




959











  • Is TextMessage also serializable?
    – Thomas Kläger
    Nov 11 '18 at 19:29










  • @ThomasKläger I'm not sure about that. Do you think thats the problem? Should the error be "exception not serializable" instead of the one i'm getting?
    – Keka Bron
    Nov 11 '18 at 21:09
















  • Is TextMessage also serializable?
    – Thomas Kläger
    Nov 11 '18 at 19:29










  • @ThomasKläger I'm not sure about that. Do you think thats the problem? Should the error be "exception not serializable" instead of the one i'm getting?
    – Keka Bron
    Nov 11 '18 at 21:09















Is TextMessage also serializable?
– Thomas Kläger
Nov 11 '18 at 19:29




Is TextMessage also serializable?
– Thomas Kläger
Nov 11 '18 at 19:29












@ThomasKläger I'm not sure about that. Do you think thats the problem? Should the error be "exception not serializable" instead of the one i'm getting?
– Keka Bron
Nov 11 '18 at 21:09




@ThomasKläger I'm not sure about that. Do you think thats the problem? Should the error be "exception not serializable" instead of the one i'm getting?
– Keka Bron
Nov 11 '18 at 21:09












1 Answer
1






active

oldest

votes


















1














I used google to pick apart your error message:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] 
[[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()
object=Messages.MessageObject@d8b66e3:
message=com.sun.messaging.jms.ra.DirectTextPacket
at com.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


It seems that the TextMessage object is actually an instance of com.sun.messaging.jms.ra.DirectTextPacket.



However, for your MessageObject to be serializable all of its fields need to be serializable too. As DirectTextPacket is not serializable, your MessageObject is not serializable.




To answer the question "why do you get this exception instead of NotSerializableException"?



This is because JMS wraps exceptions like NotSerializableException into its own exceptions.




What I do not understand: why do you want your MessageObject to contain a wrapped TextMessage? Why not add the text itself into your MessageObject?






share|improve this answer




















  • you'r right, I changed the textmessage to a String, and works perfectly now.
    – Keka Bron
    Nov 12 '18 at 14:36










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252277%2fobjectmessage-setobject-throws-javax-jms-jmsexception-for-no-apparently-reason%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I used google to pick apart your error message:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] 
[[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()
object=Messages.MessageObject@d8b66e3:
message=com.sun.messaging.jms.ra.DirectTextPacket
at com.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


It seems that the TextMessage object is actually an instance of com.sun.messaging.jms.ra.DirectTextPacket.



However, for your MessageObject to be serializable all of its fields need to be serializable too. As DirectTextPacket is not serializable, your MessageObject is not serializable.




To answer the question "why do you get this exception instead of NotSerializableException"?



This is because JMS wraps exceptions like NotSerializableException into its own exceptions.




What I do not understand: why do you want your MessageObject to contain a wrapped TextMessage? Why not add the text itself into your MessageObject?






share|improve this answer




















  • you'r right, I changed the textmessage to a String, and works perfectly now.
    – Keka Bron
    Nov 12 '18 at 14:36















1














I used google to pick apart your error message:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] 
[[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()
object=Messages.MessageObject@d8b66e3:
message=com.sun.messaging.jms.ra.DirectTextPacket
at com.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


It seems that the TextMessage object is actually an instance of com.sun.messaging.jms.ra.DirectTextPacket.



However, for your MessageObject to be serializable all of its fields need to be serializable too. As DirectTextPacket is not serializable, your MessageObject is not serializable.




To answer the question "why do you get this exception instead of NotSerializableException"?



This is because JMS wraps exceptions like NotSerializableException into its own exceptions.




What I do not understand: why do you want your MessageObject to contain a wrapped TextMessage? Why not add the text itself into your MessageObject?






share|improve this answer




















  • you'r right, I changed the textmessage to a String, and works perfectly now.
    – Keka Bron
    Nov 12 '18 at 14:36













1












1








1






I used google to pick apart your error message:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] 
[[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()
object=Messages.MessageObject@d8b66e3:
message=com.sun.messaging.jms.ra.DirectTextPacket
at com.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


It seems that the TextMessage object is actually an instance of com.sun.messaging.jms.ra.DirectTextPacket.



However, for your MessageObject to be serializable all of its fields need to be serializable too. As DirectTextPacket is not serializable, your MessageObject is not serializable.




To answer the question "why do you get this exception instead of NotSerializableException"?



This is because JMS wraps exceptions like NotSerializableException into its own exceptions.




What I do not understand: why do you want your MessageObject to contain a wrapped TextMessage? Why not add the text itself into your MessageObject?






share|improve this answer












I used google to pick apart your error message:



[2018-11-11T19:20:07.270+0100] [glassfish 5.0] [SEVERE] [tid: _ThreadID=28 _ThreadName=Thread-9] [timeMillis: 1541960407270] [levelValue: 1000] 
[[ javax.jms.JMSException:MQJMSRA_DM4001::Exception:ObjectMessage.setObject()
object=Messages.MessageObject@d8b66e3:
message=com.sun.messaging.jms.ra.DirectTextPacket
at com.sun.messaging.jms.ra.DirectObjectPacket.setObject(DirectObjectPacket.java:218)


It seems that the TextMessage object is actually an instance of com.sun.messaging.jms.ra.DirectTextPacket.



However, for your MessageObject to be serializable all of its fields need to be serializable too. As DirectTextPacket is not serializable, your MessageObject is not serializable.




To answer the question "why do you get this exception instead of NotSerializableException"?



This is because JMS wraps exceptions like NotSerializableException into its own exceptions.




What I do not understand: why do you want your MessageObject to contain a wrapped TextMessage? Why not add the text itself into your MessageObject?







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '18 at 6:28









Thomas Kläger

5,9622718




5,9622718











  • you'r right, I changed the textmessage to a String, and works perfectly now.
    – Keka Bron
    Nov 12 '18 at 14:36
















  • you'r right, I changed the textmessage to a String, and works perfectly now.
    – Keka Bron
    Nov 12 '18 at 14:36















you'r right, I changed the textmessage to a String, and works perfectly now.
– Keka Bron
Nov 12 '18 at 14:36




you'r right, I changed the textmessage to a String, and works perfectly now.
– Keka Bron
Nov 12 '18 at 14:36

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252277%2fobjectmessage-setobject-throws-javax-jms-jmsexception-for-no-apparently-reason%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo