[jboss-user] [Messaging, JMS & JBossMQ] - Re: Exception in JMSCI message listener
nicdo77
do-not-reply at jboss.com
Wed Oct 3 05:57:33 EDT 2007
anonymous wrote : But any problems with Apache Axis aren't an issue for a JBoss JMS forum.
| The only (very tentative) relationship is that you're using Axis from an MDB
| in the business method.
And is this wrong?
My business method look like this
package com.thalys.localys.frontal;
|
| /** imports */
| import java.io.ByteArrayOutputStream;
| import java.io.IOException;
| import java.io.InputStream;
| import java.io.StringWriter;
|
| import java.util....
| ...
|
| import javax.naming.NamingException;
|
| import javax.xml.bind.JAXBContext;
| import javax.xml.bind.JAXBException;
| import javax.xml.bind.Marshaller;
| import javax.xml.bind.PropertyException;
| import javax.xml.bind.Unmarshaller;
|
| import com.thalys.localys.xmlmodel....
| ...
|
| import com.sun.xml.bind.StringInputStream;
|
| /**
| * Class name: MessageTrainCreator
| *
| *
| */
| public class MessageTrainCreator {
| // ~ Static fields/initializers
| // -----------------------------------------------
|
| private static ObjectFactory objFactory;
|
| private static JAXBContext jc = null;
|
| static {
| try {
| jc = JAXBContext.newInstance("com.thalys.localys.xmlmodel");
|
| // creating the ObjectFactory
| objFactory = new ObjectFactory();
| } catch (JAXBException e) {
| }
| }
|
| // ~ Instance fields
| // ----------------------------------------------------------
|
| private SolBordMessage msg = null;
|
| // ~ Methods
| // ------------------------------------------------------------------
|
| /**
| * Create a new instance of a message
| *
| * @return SolBordMessage created from XMLModel ObjectFactory
| *
| * @throws JAXBException
| */
| public SolBordMessage openMessage() throws JAXBException {
| // create an empty PurchaseOrder
| msg = objFactory.createSolBordMessage();
|
| return msg;
| }
|
| /** irrelevant methods here, erased from the quote for better lisibility */
|
|
| /**
| * Generate the xml file by doing a marshaling operation.
| *
| * @return byte array representation of the xml file
| *
| * @throws PropertyException
| * @throws JAXBException
| * @throws NamingException
| */
| public byte[] marshallMessage() throws PropertyException, JAXBException,
| NamingException {
| // create a byte array output stream
| ByteArrayOutputStream ostram = new ByteArrayOutputStream();
|
| Marshaller m = jc.createMarshaller();
| m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
| // Marshall the message to an xml file
| m.marshal(msg, ostram);
|
| byte[] content = ostram.toByteArray();
| msg = null;
|
| return content;
| }
|
| /**
| * Generate the xml file by doing a marshaling operation.
| *
| * @return String representation of the xml file
| *
| * @throws PropertyException
| * @throws JAXBException
| * @throws NamingException
| */
| public String marshall() throws PropertyException, JAXBException,
| NamingException {
| // create a byte array output stream
| StringWriter sw = new StringWriter();
|
| Marshaller m = jc.createMarshaller();
| m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
| // Marshall the message to an xml file
| m.marshal(msg, sw);
|
| return sw.toString();
| }
|
| /**
| * Generate SolBordMessage by doing an unmarshaling operation on the message
| * string
| *
| * @param msg
| * String message to be unmarshalled
| *
| * @return SolBordMessage message
| *
| * @throws JAXBException
| */
| public static SolBordMessage unmarshall(String msg) throws JAXBException {
| // transform String into input stream
| InputStream is = new StringInputStream(msg);
|
| // create a JAXB context capable of handling classes generated into
| // the com.thalys.localys.xmlmodel package
| JAXBContext jc = JAXBContext.newInstance("com.thalys.localys.xmlmodel");
|
| // create an Unmarshaller
| Unmarshaller u = jc.createUnmarshaller();
|
| // activate unmarshalling validation of the xml file
| u.setValidating(true);
|
| // unmarshal a po instance document into a tree of Java content
| // objects composed of classes from the primer.po package.
| return (SolBordMessage) u.unmarshal(is);
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4090939#4090939
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4090939
More information about the jboss-user
mailing list