You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by ra...@wipro.com on 2008/04/08 13:24:01 UTC
Transaction in a Bean SU
Hi All,
I want to control transaction in a servicemix-bean SU. I am trying to
talk to multiple endpoints from a bean. The problem is when I get a DONE
from one of the endpoints without an error, transaction with that
endpoint is committed by default..
But I want to club multiple endpoint interactions in a transaction. Is
this possible?? If yes, how can I get the transaction manager??
I can not use the following line of code as mentioned @
http://servicemix.apache.org/transactions.html
TransactionManager tm = (TransactionManager)
getContext().getTransactionManager();
Any ideas..how to get the component context in a bean-su. Am I missing
something????
Regards,
Rabi Mishra
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
RE: Transaction in a Bean SU
Posted by ra...@wipro.com.
Bruce,
Requirement is to develop a batch engine with multiple steps (dynamically configurable and controllable). We are thinking in the lines of developing SpringBatch SE for ServiceMix.
In the present release it would static. I think we had thought of using Static Routing slip in the beginning. I do not exactly remember why we did not go ahead with static routing slip.
In addition to this..
- At present there is some sharing of data between steps ( We can get rid of this by storing the data in some persistent store)..
- There is some business/processing logic the bean (I think we can replace them with some bean components)
Anyway, I will check again if we can use routing slip for this release..
Regards,
Rabi Mishra
Wipro Technologies
Hinjewadi, Pune
Cell: +91(0)9765391877
http://rabisblog.blogspot.com/
________________________________
From: Bruce Snyder [mailto:bruce.snyder@gmail.com]
Sent: Tue 4/8/2008 9:54 PM
To: users@servicemix.apache.org
Subject: Re: Transaction in a Bean SU
On Tue, Apr 8, 2008 at 6:14 PM, <ra...@wipro.com> wrote:
> There no error. The problem I am having is.. all calls to all previous endpoints succeed inspite of error in call to one subsequent endpoint. I want them to be rolled back aswell.
>
> This bean is a target to file poller. So the file is not deleted (which should be the case if there is an error). But, some of the jdbc and camel persist calls succeed...
>
> I test this by dropping one of the db objects used..
Could you please outline the flow through the components for me so I
can better understand what you're doing? I'm asking this partially
because I'm wondering about suggesting that you make use of a static
routing slip instead of trying to use the servicemix-bean component as
a generic router.
Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'
Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Blog: http://bruceblog.org/
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
RE: Transaction in a Bean SU
Posted by ra...@wipro.com.
Now I remember what I perceived an issue with static routing slip. We have to call 2 InOnlyMEP endpoints in a sequence.
Call x FTPSender endpoint->Call y FTPSender endpoint
I think static routing slip only supports In-Out MEP. Please correct me if I am wrong..
Regards,
Rabi Mishra
________________________________
From: Bruce Snyder [mailto:bruce.snyder@gmail.com]
Sent: Tue 4/8/2008 9:54 PM
To: users@servicemix.apache.org
Subject: Re: Transaction in a Bean SU
On Tue, Apr 8, 2008 at 6:14 PM, <ra...@wipro.com> wrote:
> There no error. The problem I am having is.. all calls to all previous endpoints succeed inspite of error in call to one subsequent endpoint. I want them to be rolled back aswell.
>
> This bean is a target to file poller. So the file is not deleted (which should be the case if there is an error). But, some of the jdbc and camel persist calls succeed...
>
> I test this by dropping one of the db objects used..
Could you please outline the flow through the components for me so I
can better understand what you're doing? I'm asking this partially
because I'm wondering about suggesting that you make use of a static
routing slip instead of trying to use the servicemix-bean component as
a generic router.
Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'
Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Blog: http://bruceblog.org/
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
Re: Transaction in a Bean SU
Posted by Bruce Snyder <br...@gmail.com>.
On Tue, Apr 8, 2008 at 6:14 PM, <ra...@wipro.com> wrote:
> There no error. The problem I am having is.. all calls to all previous endpoints succeed inspite of error in call to one subsequent endpoint. I want them to be rolled back aswell.
>
> This bean is a target to file poller. So the file is not deleted (which should be the case if there is an error). But, some of the jdbc and camel persist calls succeed...
>
> I test this by dropping one of the db objects used..
Could you please outline the flow through the components for me so I
can better understand what you're doing? I'm asking this partially
because I'm wondering about suggesting that you make use of a static
routing slip instead of trying to use the servicemix-bean component as
a generic router.
Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'
Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Blog: http://bruceblog.org/
RE: Transaction in a Bean SU
Posted by ra...@wipro.com.
There no error. The problem I am having is.. all calls to all previous endpoints succeed inspite of error in call to one subsequent endpoint. I want them to be rolled back aswell.
This bean is a target to file poller. So the file is not deleted (which should be the case if there is an error). But, some of the jdbc and camel persist calls succeed...
I test this by dropping one of the db objects used..
Regards,
Rabi Mishra
Wipro Technologies
Hinjewadi, Pune
Cell: +91(0)9765391877
http://rabisblog.blogspot.com/
________________________________
From: Guillaume Nodet [mailto:gnodet@gmail.com]
Sent: Tue 4/8/2008 9:38 PM
To: users@servicemix.apache.org
Subject: Re: Transaction in a Bean SU
Ok, the only problem I see in the code is a missing DONE status when sending
an InOut mep.
Could you paste the stack trace of the exception that is being thrown please
?
On Tue, Apr 8, 2008 at 5:59 PM, <ra...@wipro.com> wrote:
> I am attaching the bean code. This includes some calls to a simple JDBC BC
> that I have developed..
>
>
> ------------------------------------------------------------------------------------------------
>
> public class BeanRouter implements MessageExchangeListener {
> @Resource
> DeliveryChannel channel;
>
> @Resource
> ComponentContext context;
>
> public void setContext(ComponentContext context)
> {
> this.context=context;
> }
>
> public ComponentContext getContext()
> {
> return context;
> }
>
> // private static Map myMap = java.util.Collections.synchronizedMap(new
> // HashMap());
> // private static int key;
> // private static final Log log = LogFactory.getLog(BeanRouter.class);
> public void onMessageExchange(MessageExchange exchange)
> throws MessagingException {
> InOnly in = (InOnly) exchange;
> if (in.getStatus() == ExchangeStatus.DONE) {
> return;
> } else if (in.getStatus() == ExchangeStatus.ERROR) {
> return;
> }
> System.err.println(in.getService().getLocalPart() + " requested");
> TransactionManager tm=null;
> try {
>
> NormalizedMessage message = exchange.getMessage("in");
> Source content = message.getContent();
> String inStr = getStringFromSource(content);
>
> tm = (TransactionManager) getContext().getTransactionManager();
> tm.begin();
>
> // Camel Persist SU
> String contentStr = DBLoggerTemplate.getDBXML("J20", "S20",
> true);
> Source persistSource = new StreamSource(new
> java.io.StringReader(
> contentStr));
> callEndpointInOnlyMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "persist", persistSource);
>
> // JDBC SP Call
> String callSpInput = "<jdbc:input xmlns:jdbc='
> http://servicemix.apache.org/jdbc/1.0' "
> + "operationType='SimpleSP' "
> + "sql='call sp_audit(?,?,?,?)' "
> + "paramValues ='01,S02,2007-02-11,DONE' />";
> Source spSource = new StreamSource(new java.io.StringReader(
> callSpInput));
> callEndpointInOnlyMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "jdbcService", spSource);
>
> // JDBC Encoded Insert
> String encodedObject = (String) Base64Util.encodeObject(inStr);
> String callInsert = "<jdbc:input xmlns:jdbc='
> http://servicemix.apache.org/jdbc/1.0' "
> + "operationType='Insert' "
> + "sql='insert into ncoarequest values(?,?)' "
> + "paramValues ='ID01," + encodedObject + "' />";
> Source insertSource = new StreamSource(new
> java.io.StringReader(
> callInsert));
> callEndpointInOnlyMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "jdbcService", insertSource);
>
> // JDBC Decoded Query
> String selectInput = "<jdbc:input xmlns:jdbc='
> http://servicemix.apache.org/jdbc/1.0' "
> + "operationType='SIMPLEQUERY' "
> + "sql='select reqXML from ncoarequest where id=?' "
> + "returnType='STRING' " + "paramValues ='ID01' />";
> Source selectSource = new StreamSource(new
> java.io.StringReader(
> selectInput));
> Source resultSource = callEndpointInOutMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "jdbcService", selectSource);
> String selectedString = getStringFromSource(resultSource);
> String encodedXML = getXPathValue("//*/ResultSet/text()",
> selectedString);
> String decodedString = (String) Base64Util
> .decodeToObject(encodedXML);
> System.err.println("Output from jdbc call:" + decodedString);
>
> // JDBC Delete
> String callDelete = "<jdbc:input xmlns:jdbc='
> http://servicemix.apache.org/jdbc/1.0' "
> + "operationType='Delete' "
> + "sql='delete from ncoarequest where id=?' "
> + "paramValues ='ID01'/>";
> Source deleteSource = new StreamSource(new
> java.io.StringReader(
> callDelete));
> callEndpointInOnlyMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "jdbcService", deleteSource);
> exchange.setStatus(ExchangeStatus.DONE);
> channel.send(exchange);
> tm.commit();
> } catch (Exception e) {
> try
> {
> System.err.println("Rollbacking Transaction");
> tm.rollback();
> }catch(Exception ex)
> {
> }
> exchange.setError(e);
> channel.send(exchange);
> }
> }
>
> //Helper Method - In MEP call
> private void callEndpointInOnlyMEP(String namespace, String
> serviceName,
> Source source) throws Exception {
> QName targetService = new QName(namespace, serviceName);
> MessageExchangeFactory exchangeFact = channel
> .createExchangeFactoryForService(targetService);
> InOnly exchange = exchangeFact.createInOnlyExchange();
> NormalizedMessage message = exchange.createMessage();
> message.setContent(source);
> exchange.setInMessage(message);
> channel.sendSync(exchange);
> if (exchange.getStatus() == ExchangeStatus.ERROR) {
> Exception e = exchange.getError();
> if (e == null) {
> e = new JBIException("Unkown error");
> }
> throw e;
> }
> }
>
> //Helper Method - In-Out MEP call
>
> private Source callEndpointInOutMEP(String namespace, String
> serviceName,
> Source source) throws Exception {
> QName targetService = new QName(namespace, serviceName);
> MessageExchangeFactory exchangeFact = channel
> .createExchangeFactoryForService(targetService);
> InOut exchange = exchangeFact.createInOutExchange();
> NormalizedMessage message = exchange.createMessage();
> message.setContent(source);
> exchange.setInMessage(message);
> channel.sendSync(exchange);
> if (exchange.getStatus() == ExchangeStatus.ERROR) {
> Exception e = exchange.getError();
> if (e == null) {
> e = new JBIException("Unkown error");
> }
> throw e;
> }
> return exchange.getMessage("out").getContent();
> }
>
> //Helper String from Source
> private String getStringFromSource(Source source) throws Exception {
> StringWriter stringWriter = new StringWriter();
> Result result = new StreamResult(stringWriter);
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer();
> transformer.transform(source, result);
> return stringWriter.getBuffer().toString();
> }
>
> //Helper to get xPath Value
> private String getXPathValue(String xPath, String selectedString)
> throws Exception {
> DocumentBuilderFactory docFactory = DocumentBuilderFactory
> .newInstance();
> docFactory.setNamespaceAware(true); // never forget this!
> DocumentBuilder builder = docFactory.newDocumentBuilder();
> Document doc = builder.parse(new InputSource(new
> java.io.StringReader(
> selectedString)));
> XPathFactory factory = XPathFactory.newInstance();
> XPath xpath = factory.newXPath();
> XPathExpression expr = xpath.compile(xPath);
> return (String) expr.evaluate(doc, XPathConstants.STRING);
> }
> }
>
>
>
> ------------------------------------------------------------------------------------------------
>
> Regards,
> Rabi Mishra
> Wipro Technologies
> Hinjewadi, Pune
> Cell: +91(0)9765391877
> http://rabisblog.blogspot.com/
>
> ________________________________
>
> From: Guillaume Nodet [mailto:gnodet@gmail.com]
> Sent: Tue 4/8/2008 9:13 PM
> To: users@servicemix.apache.org
> Subject: Re: Transaction in a Bean SU
>
>
>
> Maybe you could create a junit test so that we can have a look at the code
> used ?
>
> On Tue, Apr 8, 2008 at 5:31 PM, <ra...@wipro.com> wrote:
>
> > oops... sorry about the typo..
> >
> > Yes, I could not control the transaction. I am calling these endpoints
> > using sendSync() as there is a particular sequence of calling these
> > endpoints, so I am calling them synchronously.....
> >
> > ________________________________
> >
> > From: Bruce Snyder [mailto:bruce.snyder@gmail.com]
> > Sent: Tue 4/8/2008 8:57 PM
> > To: users@servicemix.apache.org
> > Subject: Re: Transaction in a Bean SU
> >
> >
> >
> > On Tue, Apr 8, 2008 at 2:32 PM, <ra...@wipro.com> wrote:
> > > Thanx Bruce.. I could get the transaction manager this way.
> >
> > Great :-).
> >
> > > But I could manage to control the transaction with multipe endpoints
> > > with it.
> >
> > Do you mean that you *cannot* control the transaction?
> >
> > > Is this because this is the transaction manager in the component
> > > context?? Does JBI support transaction rollbacks with endpoints??
> >
> > From within the servicemix-bean POJO, to send messages to these other
> > endpoints, are you calling send() or sendSync()?
> >
> > Bruce
> > --
> > perl -e 'print
> > unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> > );'
> >
> > Apache ActiveMQ - http://activemq.org/
> > Apache Camel - http://activemq.org/camel/
> > Apache ServiceMix - http://servicemix.org/
> > Apache Geronimo - http://geronimo.apache.org/
> >
> > Blog: http://bruceblog.org/
> >
> >
> >
> > The information contained in this electronic message and any attachments
> > to this message are intended for the exclusive use of the addressee(s)
> and
> > may contain proprietary, confidential or privileged information. If you
> are
> > not the intended recipient, you should not disseminate, distribute or
> copy
> > this e-mail. Please notify the sender immediately and destroy all copies
> of
> > this message and any attachments.
> >
> > WARNING: Computer viruses can be transmitted via email. The recipient
> > should check this email and any attachments for the presence of viruses.
> The
> > company accepts no liability for any damage caused by any virus
> transmitted
> > by this email.
> >
> > www.wipro.com
> >
> >
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
>
>
>
> The information contained in this electronic message and any attachments
> to this message are intended for the exclusive use of the addressee(s) and
> may contain proprietary, confidential or privileged information. If you are
> not the intended recipient, you should not disseminate, distribute or copy
> this e-mail. Please notify the sender immediately and destroy all copies of
> this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient
> should check this email and any attachments for the presence of viruses. The
> company accepts no liability for any damage caused by any virus transmitted
> by this email.
>
> www.wipro.com
>
>
--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
Re: Transaction in a Bean SU
Posted by Guillaume Nodet <gn...@gmail.com>.
Ok, the only problem I see in the code is a missing DONE status when sending
an InOut mep.
Could you paste the stack trace of the exception that is being thrown please
?
On Tue, Apr 8, 2008 at 5:59 PM, <ra...@wipro.com> wrote:
> I am attaching the bean code. This includes some calls to a simple JDBC BC
> that I have developed..
>
>
> ------------------------------------------------------------------------------------------------
>
> public class BeanRouter implements MessageExchangeListener {
> @Resource
> DeliveryChannel channel;
>
> @Resource
> ComponentContext context;
>
> public void setContext(ComponentContext context)
> {
> this.context=context;
> }
>
> public ComponentContext getContext()
> {
> return context;
> }
>
> // private static Map myMap = java.util.Collections.synchronizedMap(new
> // HashMap());
> // private static int key;
> // private static final Log log = LogFactory.getLog(BeanRouter.class);
> public void onMessageExchange(MessageExchange exchange)
> throws MessagingException {
> InOnly in = (InOnly) exchange;
> if (in.getStatus() == ExchangeStatus.DONE) {
> return;
> } else if (in.getStatus() == ExchangeStatus.ERROR) {
> return;
> }
> System.err.println(in.getService().getLocalPart() + " requested");
> TransactionManager tm=null;
> try {
>
> NormalizedMessage message = exchange.getMessage("in");
> Source content = message.getContent();
> String inStr = getStringFromSource(content);
>
> tm = (TransactionManager) getContext().getTransactionManager();
> tm.begin();
>
> // Camel Persist SU
> String contentStr = DBLoggerTemplate.getDBXML("J20", "S20",
> true);
> Source persistSource = new StreamSource(new
> java.io.StringReader(
> contentStr));
> callEndpointInOnlyMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "persist", persistSource);
>
> // JDBC SP Call
> String callSpInput = "<jdbc:input xmlns:jdbc='
> http://servicemix.apache.org/jdbc/1.0' "
> + "operationType='SimpleSP' "
> + "sql='call sp_audit(?,?,?,?)' "
> + "paramValues ='01,S02,2007-02-11,DONE' />";
> Source spSource = new StreamSource(new java.io.StringReader(
> callSpInput));
> callEndpointInOnlyMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "jdbcService", spSource);
>
> // JDBC Encoded Insert
> String encodedObject = (String) Base64Util.encodeObject(inStr);
> String callInsert = "<jdbc:input xmlns:jdbc='
> http://servicemix.apache.org/jdbc/1.0' "
> + "operationType='Insert' "
> + "sql='insert into ncoarequest values(?,?)' "
> + "paramValues ='ID01," + encodedObject + "' />";
> Source insertSource = new StreamSource(new
> java.io.StringReader(
> callInsert));
> callEndpointInOnlyMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "jdbcService", insertSource);
>
> // JDBC Decoded Query
> String selectInput = "<jdbc:input xmlns:jdbc='
> http://servicemix.apache.org/jdbc/1.0' "
> + "operationType='SIMPLEQUERY' "
> + "sql='select reqXML from ncoarequest where id=?' "
> + "returnType='STRING' " + "paramValues ='ID01' />";
> Source selectSource = new StreamSource(new
> java.io.StringReader(
> selectInput));
> Source resultSource = callEndpointInOutMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "jdbcService", selectSource);
> String selectedString = getStringFromSource(resultSource);
> String encodedXML = getXPathValue("//*/ResultSet/text()",
> selectedString);
> String decodedString = (String) Base64Util
> .decodeToObject(encodedXML);
> System.err.println("Output from jdbc call:" + decodedString);
>
> // JDBC Delete
> String callDelete = "<jdbc:input xmlns:jdbc='
> http://servicemix.apache.org/jdbc/1.0' "
> + "operationType='Delete' "
> + "sql='delete from ncoarequest where id=?' "
> + "paramValues ='ID01'/>";
> Source deleteSource = new StreamSource(new
> java.io.StringReader(
> callDelete));
> callEndpointInOnlyMEP(
> "http://servicemix.apache.org/samples/logging-sample",
> "jdbcService", deleteSource);
> exchange.setStatus(ExchangeStatus.DONE);
> channel.send(exchange);
> tm.commit();
> } catch (Exception e) {
> try
> {
> System.err.println("Rollbacking Transaction");
> tm.rollback();
> }catch(Exception ex)
> {
> }
> exchange.setError(e);
> channel.send(exchange);
> }
> }
>
> //Helper Method - In MEP call
> private void callEndpointInOnlyMEP(String namespace, String
> serviceName,
> Source source) throws Exception {
> QName targetService = new QName(namespace, serviceName);
> MessageExchangeFactory exchangeFact = channel
> .createExchangeFactoryForService(targetService);
> InOnly exchange = exchangeFact.createInOnlyExchange();
> NormalizedMessage message = exchange.createMessage();
> message.setContent(source);
> exchange.setInMessage(message);
> channel.sendSync(exchange);
> if (exchange.getStatus() == ExchangeStatus.ERROR) {
> Exception e = exchange.getError();
> if (e == null) {
> e = new JBIException("Unkown error");
> }
> throw e;
> }
> }
>
> //Helper Method - In-Out MEP call
>
> private Source callEndpointInOutMEP(String namespace, String
> serviceName,
> Source source) throws Exception {
> QName targetService = new QName(namespace, serviceName);
> MessageExchangeFactory exchangeFact = channel
> .createExchangeFactoryForService(targetService);
> InOut exchange = exchangeFact.createInOutExchange();
> NormalizedMessage message = exchange.createMessage();
> message.setContent(source);
> exchange.setInMessage(message);
> channel.sendSync(exchange);
> if (exchange.getStatus() == ExchangeStatus.ERROR) {
> Exception e = exchange.getError();
> if (e == null) {
> e = new JBIException("Unkown error");
> }
> throw e;
> }
> return exchange.getMessage("out").getContent();
> }
>
> //Helper String from Source
> private String getStringFromSource(Source source) throws Exception {
> StringWriter stringWriter = new StringWriter();
> Result result = new StreamResult(stringWriter);
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer();
> transformer.transform(source, result);
> return stringWriter.getBuffer().toString();
> }
>
> //Helper to get xPath Value
> private String getXPathValue(String xPath, String selectedString)
> throws Exception {
> DocumentBuilderFactory docFactory = DocumentBuilderFactory
> .newInstance();
> docFactory.setNamespaceAware(true); // never forget this!
> DocumentBuilder builder = docFactory.newDocumentBuilder();
> Document doc = builder.parse(new InputSource(new
> java.io.StringReader(
> selectedString)));
> XPathFactory factory = XPathFactory.newInstance();
> XPath xpath = factory.newXPath();
> XPathExpression expr = xpath.compile(xPath);
> return (String) expr.evaluate(doc, XPathConstants.STRING);
> }
> }
>
>
>
> ------------------------------------------------------------------------------------------------
>
> Regards,
> Rabi Mishra
> Wipro Technologies
> Hinjewadi, Pune
> Cell: +91(0)9765391877
> http://rabisblog.blogspot.com/
>
> ________________________________
>
> From: Guillaume Nodet [mailto:gnodet@gmail.com]
> Sent: Tue 4/8/2008 9:13 PM
> To: users@servicemix.apache.org
> Subject: Re: Transaction in a Bean SU
>
>
>
> Maybe you could create a junit test so that we can have a look at the code
> used ?
>
> On Tue, Apr 8, 2008 at 5:31 PM, <ra...@wipro.com> wrote:
>
> > oops... sorry about the typo..
> >
> > Yes, I could not control the transaction. I am calling these endpoints
> > using sendSync() as there is a particular sequence of calling these
> > endpoints, so I am calling them synchronously.....
> >
> > ________________________________
> >
> > From: Bruce Snyder [mailto:bruce.snyder@gmail.com]
> > Sent: Tue 4/8/2008 8:57 PM
> > To: users@servicemix.apache.org
> > Subject: Re: Transaction in a Bean SU
> >
> >
> >
> > On Tue, Apr 8, 2008 at 2:32 PM, <ra...@wipro.com> wrote:
> > > Thanx Bruce.. I could get the transaction manager this way.
> >
> > Great :-).
> >
> > > But I could manage to control the transaction with multipe endpoints
> > > with it.
> >
> > Do you mean that you *cannot* control the transaction?
> >
> > > Is this because this is the transaction manager in the component
> > > context?? Does JBI support transaction rollbacks with endpoints??
> >
> > From within the servicemix-bean POJO, to send messages to these other
> > endpoints, are you calling send() or sendSync()?
> >
> > Bruce
> > --
> > perl -e 'print
> > unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> > );'
> >
> > Apache ActiveMQ - http://activemq.org/
> > Apache Camel - http://activemq.org/camel/
> > Apache ServiceMix - http://servicemix.org/
> > Apache Geronimo - http://geronimo.apache.org/
> >
> > Blog: http://bruceblog.org/
> >
> >
> >
> > The information contained in this electronic message and any attachments
> > to this message are intended for the exclusive use of the addressee(s)
> and
> > may contain proprietary, confidential or privileged information. If you
> are
> > not the intended recipient, you should not disseminate, distribute or
> copy
> > this e-mail. Please notify the sender immediately and destroy all copies
> of
> > this message and any attachments.
> >
> > WARNING: Computer viruses can be transmitted via email. The recipient
> > should check this email and any attachments for the presence of viruses.
> The
> > company accepts no liability for any damage caused by any virus
> transmitted
> > by this email.
> >
> > www.wipro.com
> >
> >
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
>
>
>
> The information contained in this electronic message and any attachments
> to this message are intended for the exclusive use of the addressee(s) and
> may contain proprietary, confidential or privileged information. If you are
> not the intended recipient, you should not disseminate, distribute or copy
> this e-mail. Please notify the sender immediately and destroy all copies of
> this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient
> should check this email and any attachments for the presence of viruses. The
> company accepts no liability for any damage caused by any virus transmitted
> by this email.
>
> www.wipro.com
>
>
--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
RE: Transaction in a Bean SU
Posted by ra...@wipro.com.
I am attaching the bean code. This includes some calls to a simple JDBC BC that I have developed..
------------------------------------------------------------------------------------------------
public class BeanRouter implements MessageExchangeListener {
@Resource
DeliveryChannel channel;
@Resource
ComponentContext context;
public void setContext(ComponentContext context)
{
this.context=context;
}
public ComponentContext getContext()
{
return context;
}
// private static Map myMap = java.util.Collections.synchronizedMap(new
// HashMap());
// private static int key;
// private static final Log log = LogFactory.getLog(BeanRouter.class);
public void onMessageExchange(MessageExchange exchange)
throws MessagingException {
InOnly in = (InOnly) exchange;
if (in.getStatus() == ExchangeStatus.DONE) {
return;
} else if (in.getStatus() == ExchangeStatus.ERROR) {
return;
}
System.err.println(in.getService().getLocalPart() + " requested");
TransactionManager tm=null;
try {
NormalizedMessage message = exchange.getMessage("in");
Source content = message.getContent();
String inStr = getStringFromSource(content);
tm = (TransactionManager) getContext().getTransactionManager();
tm.begin();
// Camel Persist SU
String contentStr = DBLoggerTemplate.getDBXML("J20", "S20", true);
Source persistSource = new StreamSource(new java.io.StringReader(
contentStr));
callEndpointInOnlyMEP(
"http://servicemix.apache.org/samples/logging-sample",
"persist", persistSource);
// JDBC SP Call
String callSpInput = "<jdbc:input xmlns:jdbc='http://servicemix.apache.org/jdbc/1.0' "
+ "operationType='SimpleSP' "
+ "sql='call sp_audit(?,?,?,?)' "
+ "paramValues ='01,S02,2007-02-11,DONE' />";
Source spSource = new StreamSource(new java.io.StringReader(
callSpInput));
callEndpointInOnlyMEP(
"http://servicemix.apache.org/samples/logging-sample",
"jdbcService", spSource);
// JDBC Encoded Insert
String encodedObject = (String) Base64Util.encodeObject(inStr);
String callInsert = "<jdbc:input xmlns:jdbc='http://servicemix.apache.org/jdbc/1.0' "
+ "operationType='Insert' "
+ "sql='insert into ncoarequest values(?,?)' "
+ "paramValues ='ID01," + encodedObject + "' />";
Source insertSource = new StreamSource(new java.io.StringReader(
callInsert));
callEndpointInOnlyMEP(
"http://servicemix.apache.org/samples/logging-sample",
"jdbcService", insertSource);
// JDBC Decoded Query
String selectInput = "<jdbc:input xmlns:jdbc='http://servicemix.apache.org/jdbc/1.0' "
+ "operationType='SIMPLEQUERY' "
+ "sql='select reqXML from ncoarequest where id=?' "
+ "returnType='STRING' " + "paramValues ='ID01' />";
Source selectSource = new StreamSource(new java.io.StringReader(
selectInput));
Source resultSource = callEndpointInOutMEP(
"http://servicemix.apache.org/samples/logging-sample",
"jdbcService", selectSource);
String selectedString = getStringFromSource(resultSource);
String encodedXML = getXPathValue("//*/ResultSet/text()",
selectedString);
String decodedString = (String) Base64Util
.decodeToObject(encodedXML);
System.err.println("Output from jdbc call:" + decodedString);
// JDBC Delete
String callDelete = "<jdbc:input xmlns:jdbc='http://servicemix.apache.org/jdbc/1.0' "
+ "operationType='Delete' "
+ "sql='delete from ncoarequest where id=?' "
+ "paramValues ='ID01'/>";
Source deleteSource = new StreamSource(new java.io.StringReader(
callDelete));
callEndpointInOnlyMEP(
"http://servicemix.apache.org/samples/logging-sample",
"jdbcService", deleteSource);
exchange.setStatus(ExchangeStatus.DONE);
channel.send(exchange);
tm.commit();
} catch (Exception e) {
try
{
System.err.println("Rollbacking Transaction");
tm.rollback();
}catch(Exception ex)
{
}
exchange.setError(e);
channel.send(exchange);
}
}
//Helper Method - In MEP call
private void callEndpointInOnlyMEP(String namespace, String serviceName,
Source source) throws Exception {
QName targetService = new QName(namespace, serviceName);
MessageExchangeFactory exchangeFact = channel
.createExchangeFactoryForService(targetService);
InOnly exchange = exchangeFact.createInOnlyExchange();
NormalizedMessage message = exchange.createMessage();
message.setContent(source);
exchange.setInMessage(message);
channel.sendSync(exchange);
if (exchange.getStatus() == ExchangeStatus.ERROR) {
Exception e = exchange.getError();
if (e == null) {
e = new JBIException("Unkown error");
}
throw e;
}
}
//Helper Method - In-Out MEP call
private Source callEndpointInOutMEP(String namespace, String serviceName,
Source source) throws Exception {
QName targetService = new QName(namespace, serviceName);
MessageExchangeFactory exchangeFact = channel
.createExchangeFactoryForService(targetService);
InOut exchange = exchangeFact.createInOutExchange();
NormalizedMessage message = exchange.createMessage();
message.setContent(source);
exchange.setInMessage(message);
channel.sendSync(exchange);
if (exchange.getStatus() == ExchangeStatus.ERROR) {
Exception e = exchange.getError();
if (e == null) {
e = new JBIException("Unkown error");
}
throw e;
}
return exchange.getMessage("out").getContent();
}
//Helper String from Source
private String getStringFromSource(Source source) throws Exception {
StringWriter stringWriter = new StringWriter();
Result result = new StreamResult(stringWriter);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(source, result);
return stringWriter.getBuffer().toString();
}
//Helper to get xPath Value
private String getXPathValue(String xPath, String selectedString)
throws Exception {
DocumentBuilderFactory docFactory = DocumentBuilderFactory
.newInstance();
docFactory.setNamespaceAware(true); // never forget this!
DocumentBuilder builder = docFactory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new java.io.StringReader(
selectedString)));
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile(xPath);
return (String) expr.evaluate(doc, XPathConstants.STRING);
}
}
------------------------------------------------------------------------------------------------
Regards,
Rabi Mishra
Wipro Technologies
Hinjewadi, Pune
Cell: +91(0)9765391877
http://rabisblog.blogspot.com/
________________________________
From: Guillaume Nodet [mailto:gnodet@gmail.com]
Sent: Tue 4/8/2008 9:13 PM
To: users@servicemix.apache.org
Subject: Re: Transaction in a Bean SU
Maybe you could create a junit test so that we can have a look at the code
used ?
On Tue, Apr 8, 2008 at 5:31 PM, <ra...@wipro.com> wrote:
> oops... sorry about the typo..
>
> Yes, I could not control the transaction. I am calling these endpoints
> using sendSync() as there is a particular sequence of calling these
> endpoints, so I am calling them synchronously.....
>
> ________________________________
>
> From: Bruce Snyder [mailto:bruce.snyder@gmail.com]
> Sent: Tue 4/8/2008 8:57 PM
> To: users@servicemix.apache.org
> Subject: Re: Transaction in a Bean SU
>
>
>
> On Tue, Apr 8, 2008 at 2:32 PM, <ra...@wipro.com> wrote:
> > Thanx Bruce.. I could get the transaction manager this way.
>
> Great :-).
>
> > But I could manage to control the transaction with multipe endpoints
> > with it.
>
> Do you mean that you *cannot* control the transaction?
>
> > Is this because this is the transaction manager in the component
> > context?? Does JBI support transaction rollbacks with endpoints??
>
> From within the servicemix-bean POJO, to send messages to these other
> endpoints, are you calling send() or sendSync()?
>
> Bruce
> --
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
>
> Apache ActiveMQ - http://activemq.org/
> Apache Camel - http://activemq.org/camel/
> Apache ServiceMix - http://servicemix.org/
> Apache Geronimo - http://geronimo.apache.org/
>
> Blog: http://bruceblog.org/
>
>
>
> The information contained in this electronic message and any attachments
> to this message are intended for the exclusive use of the addressee(s) and
> may contain proprietary, confidential or privileged information. If you are
> not the intended recipient, you should not disseminate, distribute or copy
> this e-mail. Please notify the sender immediately and destroy all copies of
> this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient
> should check this email and any attachments for the presence of viruses. The
> company accepts no liability for any damage caused by any virus transmitted
> by this email.
>
> www.wipro.com
>
>
--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
Re: Transaction in a Bean SU
Posted by Guillaume Nodet <gn...@gmail.com>.
Maybe you could create a junit test so that we can have a look at the code
used ?
On Tue, Apr 8, 2008 at 5:31 PM, <ra...@wipro.com> wrote:
> oops... sorry about the typo..
>
> Yes, I could not control the transaction. I am calling these endpoints
> using sendSync() as there is a particular sequence of calling these
> endpoints, so I am calling them synchronously.....
>
> ________________________________
>
> From: Bruce Snyder [mailto:bruce.snyder@gmail.com]
> Sent: Tue 4/8/2008 8:57 PM
> To: users@servicemix.apache.org
> Subject: Re: Transaction in a Bean SU
>
>
>
> On Tue, Apr 8, 2008 at 2:32 PM, <ra...@wipro.com> wrote:
> > Thanx Bruce.. I could get the transaction manager this way.
>
> Great :-).
>
> > But I could manage to control the transaction with multipe endpoints
> > with it.
>
> Do you mean that you *cannot* control the transaction?
>
> > Is this because this is the transaction manager in the component
> > context?? Does JBI support transaction rollbacks with endpoints??
>
> From within the servicemix-bean POJO, to send messages to these other
> endpoints, are you calling send() or sendSync()?
>
> Bruce
> --
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
>
> Apache ActiveMQ - http://activemq.org/
> Apache Camel - http://activemq.org/camel/
> Apache ServiceMix - http://servicemix.org/
> Apache Geronimo - http://geronimo.apache.org/
>
> Blog: http://bruceblog.org/
>
>
>
> The information contained in this electronic message and any attachments
> to this message are intended for the exclusive use of the addressee(s) and
> may contain proprietary, confidential or privileged information. If you are
> not the intended recipient, you should not disseminate, distribute or copy
> this e-mail. Please notify the sender immediately and destroy all copies of
> this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient
> should check this email and any attachments for the presence of viruses. The
> company accepts no liability for any damage caused by any virus transmitted
> by this email.
>
> www.wipro.com
>
>
--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
RE: Transaction in a Bean SU
Posted by ra...@wipro.com.
oops... sorry about the typo..
Yes, I could not control the transaction. I am calling these endpoints using sendSync() as there is a particular sequence of calling these endpoints, so I am calling them synchronously.....
________________________________
From: Bruce Snyder [mailto:bruce.snyder@gmail.com]
Sent: Tue 4/8/2008 8:57 PM
To: users@servicemix.apache.org
Subject: Re: Transaction in a Bean SU
On Tue, Apr 8, 2008 at 2:32 PM, <ra...@wipro.com> wrote:
> Thanx Bruce.. I could get the transaction manager this way.
Great :-).
> But I could manage to control the transaction with multipe endpoints
> with it.
Do you mean that you *cannot* control the transaction?
> Is this because this is the transaction manager in the component
> context?? Does JBI support transaction rollbacks with endpoints??
>From within the servicemix-bean POJO, to send messages to these other
endpoints, are you calling send() or sendSync()?
Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'
Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Blog: http://bruceblog.org/
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
Re: Transaction in a Bean SU
Posted by Bruce Snyder <br...@gmail.com>.
On Tue, Apr 8, 2008 at 2:32 PM, <ra...@wipro.com> wrote:
> Thanx Bruce.. I could get the transaction manager this way.
Great :-).
> But I could manage to control the transaction with multipe endpoints
> with it.
Do you mean that you *cannot* control the transaction?
> Is this because this is the transaction manager in the component
> context?? Does JBI support transaction rollbacks with endpoints??
>From within the servicemix-bean POJO, to send messages to these other
endpoints, are you calling send() or sendSync()?
Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'
Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Blog: http://bruceblog.org/
RE: Transaction in a Bean SU
Posted by ra...@wipro.com.
Thanx Bruce.. I could get the transaction manager this way.
But I could manage to control the transaction with multipe endpoints
with it.
Is this because this is the transaction manager in the component
context?? Does JBI support transaction rollbacks with endpoints??
Regards,
Rabi Mishra,
-----Original Message-----
From: Bruce Snyder [mailto:bruce.snyder@gmail.com]
Sent: Tuesday, April 08, 2008 5:09 PM
To: users@servicemix.apache.org
Subject: Re: Transaction in a Bean SU
On Tue, Apr 8, 2008 at 1:24 PM, <ra...@wipro.com> wrote:
>
> Hi All,
>
> I want to control transaction in a servicemix-bean SU. I am trying to
> talk to multiple endpoints from a bean. The problem is when I get a
> DONE from one of the endpoints without an error, transaction with
> that endpoint is committed by default..
>
> But I want to club multiple endpoint interactions in a transaction.
> Is this possible?? If yes, how can I get the transaction manager??
>
> I can not use the following line of code as mentioned @
> http://servicemix.apache.org/transactions.html
>
> TransactionManager tm = (TransactionManager)
> getContext().getTransactionManager();
>
> Any ideas..how to get the component context in a bean-su. Am I
> missing something????
You need to add the following to your bean:
1) a property to hold the context reference
2) getContext()/setContext() methods to get/set the property
Upon adding these items, the BeanEndpoint will automatically inject the
component context using the setter. Then your call to getContext() will
succeed and you will be able to grab the transaction manager.
Bruce
--
perl -e 'print
unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'
Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/ Apache ServiceMix -
http://servicemix.org/ Apache Geronimo - http://geronimo.apache.org/
Blog: http://bruceblog.org/
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
Re: Transaction in a Bean SU
Posted by Bruce Snyder <br...@gmail.com>.
On Tue, Apr 8, 2008 at 1:24 PM, <ra...@wipro.com> wrote:
>
> Hi All,
>
> I want to control transaction in a servicemix-bean SU. I am trying to
> talk to multiple endpoints from a bean. The problem is when I get a DONE
> from one of the endpoints without an error, transaction with that
> endpoint is committed by default..
>
> But I want to club multiple endpoint interactions in a transaction. Is
> this possible?? If yes, how can I get the transaction manager??
>
> I can not use the following line of code as mentioned @
> http://servicemix.apache.org/transactions.html
>
> TransactionManager tm = (TransactionManager)
> getContext().getTransactionManager();
>
> Any ideas..how to get the component context in a bean-su. Am I missing
> something????
You need to add the following to your bean:
1) a property to hold the context reference
2) getContext()/setContext() methods to get/set the property
Upon adding these items, the BeanEndpoint will automatically inject
the component context using the setter. Then your call to getContext()
will succeed and you will be able to grab the transaction manager.
Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'
Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Blog: http://bruceblog.org/