It worked wonderful with my jmslistener calling a simple smx:bean component.
I have my flow as jms consumer-> bean class-> http provider ( calling
external service)
When I add http provider componenet, it is just hanging. I am sure I am
doing something fundamentally wrong. Please suggest.
Here is the code snippet that I am using to call http provider from smx
bean ( I am using sendSync() method)
client = new ServiceMixClientFacade(context);
QName service = new
QName("http://test","TemperatureConverterService1");
NormalizedMessage message = exchange.getMessage("in");
Source content = message.getContent();
String body = (new
SourceTransformer()).toString(content);
log.info("SimpleConsumer:input message body is:"+body);
EndpointResolver resolver =
client.createResolverForService(service);
boolean transactional =
exchange.getProperty("javax.jbi.transaction.jta") != null;
log.info("given xchange is
transactional:"+transactional);
/* the below way of transaction management not working
throws exception as below
Caused by:
javax.transaction.InvalidTransactionException:
Specified transaction is already associated
with another thread
*/
// TransactionManager tm = (TransactionManager)
context.getTransactionManager();
// tm.begin();
InOut outexchange =
client.createInOutExchange(resolver);
Iterator<String> iterator =
exchange.getPropertyNames().iterator();
while (iterator.hasNext()) {
String propName =
iterator.next();
log.info("RECV:EXCHNG:inside
iterator,propName:"+propName+":"+exchange.getProperty(propName));
log.info("SEND:EXCHNG:inside
iterator,propName:"+propName+":"+outexchange.getProperty(propName));
outexchange.setProperty(propName, exchange.getProperty(propName));
}
NormalizedMessage outmessage =
outexchange.getInMessage();
outmessage.setContent(new StringSource(body));
String uri = getURIFromMessage(body);
log.info("uri is:"+uri);
boolean useDynamicUri = true;
if (useDynamicUri) {
outexchange.getInMessage().setProperty(
JbiConstants.HTTP_DESTINATION_URI,
uri);
/*
outexchange.getInMessage().setProperty(
JbiConstants.HTTP_DESTINATION_URI,
"http://localhost/axis2/services/EchoService"); */
}
boolean success = false;
boolean good = client.sendSync(outexchange);
log.info("SimpleConsumer:invocation is done");
//Object responseContent = client.request(resolver,
null, null,
body);
//log.info("SimpleConsumer:response
is"+responseContent);
log.info("SimpleConsumer:response is"+good);
log.info("SimpleConsumer:response
is"+outexchange.getOutMessage());
log.info("SimpleConsumer:error
is"+outexchange.getError());
Fault fault = outexchange.getFault();
String faultbody=null;
if(fault != null){
Source faultContent = fault.getContent();
faultbody = (new
SourceTransformer()).toString(faultContent);
log.info("SimpleConsumer:fault is"+faultbody);
}
if(outexchange.getOutMessage() != null){
NormalizedMessage responsemessage =
outexchange.getOutMessage();
String responsecontent = (new
SourceTransformer()).toString(responsemessage.getContent());
log.info("SimpleConsumer:response body
is:"+responsecontent);
//log.info("response object is:"+responseContent);
success=true;
}
if(success){
exchange.setStatus(ExchangeStatus.DONE);
channel.send(exchange);
//tm.commit();
log.info("transaction committed");
//outexchange.setStatus(ExchangeStatus.DONE);
}
else{
//Exception ex = new Exception ("ERROR:Fault
occurred"+faultbody);
Exception ex = new Exception ("ERROR:Fault
occurred");
exchange.setError(ex);
exchange.setStatus(ExchangeStatus.ERROR);
channel.send(exchange);
//tm.rollback();
log.info("transaction rollbacked");
//exchange.setStatus(ExchangeStatus.ERROR);
}
iocanel wrote:
>
> The error you have is beacause BootstrapContextFactoryBean requires a
> reference to the transaction manager:
>
> <bean id="bootstrapContext"
> class="org.jencks.factory.BootstrapContextFactoryBean">
> <property name="threadPoolSize" value="15" />
> <property name="transactionManager"
> ref="transactionManager" />
> </bean>
>
> <bean id="transactionManager"
> class="org.jencks.factory.TransactionManagerFactoryBean"/>
>
>
> As I told you in my first post the way that you are going to create the
> bootstrap context depends on your environment setup. In your case
> (servicemix 4) I think that will work.
>
>
http://old.nabble.com/file/p28233842/MyBean.java MyBean.java
--
View this message in context:
http://old.nabble.com/SMX4-handling-transaction-tp28199896p28233842.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.