I am using a spring configuration like this to add a CustomHandler. It is working fine. As per documentation - customHandlerResolver is called once per proxy.
Here lies the issue. I need to add a dynamic security token header for each SOAP request and since the handler is called only once, my token expires after certain time, I am not able to set a refreshed token.
<bean id="myServicePort" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="serviceInterface" value="org.my.myService" />
<property name="wsdlDocumentUrl" value="classpath:wsdl/mysoap.wsdl" />
<property name="namespaceUri" value="http://services.mycom.org" />
<property name="serviceName" value="OrderService" />
<property name="endpointAddress" ref="OrderEndPoint" />
<property name="handlerResolver" ref="customHandlerResolver"/>
</bean>
Have you tried using bean scope prototype.
<bean id="myServicePort" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean" scope="prototype">
<property name="serviceInterface" value="org.my.myService" />
<property name="wsdlDocumentUrl" value="classpath:wsdl/mysoap.wsdl" />
<property name="namespaceUri" value="http://services.mycom.org" />
<property name="serviceName" value="OrderService" />
<property name="endpointAddress" ref="OrderEndPoint" />
<property name="handlerResolver" ref="customHandlerResolver"/>
As I said HandlerResolver is called only once, no matter what the scope of the bean is. I used CXF - org.apache.cxf.jaxws.JaxWsProxyFactoryBean as I get more control on bean creation, unlike the above Spring proxy where Spring itself creates the proxy.
<bean id="proxyFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="org.my.myService"/>
<property name="address" value="http://localhost:9002/HelloWorld"/>
</bean>
In my client code
//Set a handler
proxyFactory.setHandlers( Arrays.asList((Handler) new TokenHandler(Token)));
OrderService orderServicePort= (myService) proxyFactory.create();
//Call service method, as SOAP message has desired dynamic header
orderServicePort.getXXX()
This works perfectly and is less verbose than my initial spring config
Related
My project is using jms+ibmmq to send a message out. it's working properly, and I'm able to push a message to the outbound queue, and then receive a response from the inbound queue. Recently, a client asks if we can send out an alert email if unable to get a response within like 2 min. I checked the spring integration messaging related document, seems gatway can implement it? but still can't get an idea how to use it. can someone help me out?
my current xml configuration
<integration:service-activator id="serviceActivator1" input-channel="inputChannel"
ref="messageProcessService" method="callMsgProcessor" output-channel="requestChannel" />
<bean id="ibmConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="transportType">
<util:constant static-field="com.ibm.msg.client.wmq.WMQConstants.WMQ_CM_CLIENT"/>
</property>
<property name="hostName" value="${hostName}"/>
<property name="queueManager" value="${queue-manager}"/>
<property name="channel" value="${channel}"/>
<property name="port" value="${port}"/>
</bean>
</property>
<property name="sessionCacheSize" value="5"/>
</bean>
<bean id="requestQueue" class="com.ibm.mq.jms.MQQueue">
<constructor-arg value="${request-queue}"/>
<property name="targetClient">
<util:constant static-field="com.ibm.msg.client.wmq.WMQConstants.WMQ_CLIENT_NONJMS_MQ"/>
</property>
</bean>
<jms:outbound-channel-adapter id="request.queue.adapter" connection-factory="ibmConnectionFactory"
destination="requestQueue" channel="requestChannel"/>
<integration:channel id="requestChannel"/>
<bean id="responseQueue" class="com.ibm.mq.jms.MQQueue">
<constructor-arg value="${response-queue}"/>
</bean>
<jms:message-driven-channel-adapter id="responseJMSAdapater"
destination="responseQueue"
channel="responseChannel"
connection-factory="ibmConnectionFactory"
error-channel="errorChannel"
acknowledge="transacted"
/>
<integration:channel id="responseChannel">
<integration:queue capacity="500"/>
<integration:interceptors>
<integration:wire-tap channel="logger"/>
</integration:interceptors>
</integration:channel>
if add a gateway, it looks like
<integration:gateway id="serviceAdaptedGateway" service-interface="com.mycompany.service.gatewayServiceInterface"
default-request-channel="requestChannel"
default-reply-channel="responseChannel"
default-reply-timeout="120000"/>
my question is
seems timeout not working, nothing happen even the waiting time exceed the timeout
although the gateway provide timeout property, where I can add my business logic like send email alert?
This code is a version of Spring Batch version 1. I have problem migrating this code to version 4 since the org.springframework.batch.item.database.IbatisDrivingQueryItemReader class is no longer available in current version.
The process of the code below is, the withdrawalIbatisKeyGenerator bean should execute first and from the output of that bean, it will use in ibatisWithdrawalReader bean.
My question is, how to implement this reader to current version, since the two bean have dependency with each other.
<bean id="ibatisWithdrawalReader"
class="org.springframework.batch.item.database.IbatisDrivingQueryItemReader">
<property name="detailsQueryId"
value="withdrawalTransactionDao.getWithdrawalTransaction" />
<property name="sqlMapClient" ref="sqlMap" />
<property name="keyCollector"
ref="withdrawalIbatisKeyGenerator" />
</bean>
<bean id="withdrawalIbatisKeyGenerator"
class="ph.pnblife.julia.batch.BatchKeyCollector">
<property name="drivingQuery"
value="withdrawalTransactionDao.getWithdrawalTransactionKey" />
<property name="restartQueryId"
value="withdrawalTransactionDao.restartWithdrawalTransaction" />
<property name="sqlMapClient" ref="sqlMap" />
<property name="parameters">
<list>
<value>%%pricing_date_ibatis:date:pricing_date</value>
<value>%%policy_number:string:pol_no</value>
<value>%%version_no:string:version_no</value>
<value>%%start_date:date:start_dt</value>
<value>%%endt_type:string:endt_code</value>
</list>
</property>
<property name="isKeyAMap">
<value type="java.lang.Boolean">true</value>
</property>
</bean>
The withdrawalIbatisKeyGenerator bean could registered as a StepExecutionListener where the data required by the reader is generated in the StepExecutionListener#beforeStep method.
We use Apache Camel's camel-http component to integrate with HTTP endpoints, HttpConnectionManagerParams is used to configure defaultconnectionsPerHost and maxTotalConnections.
<bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams" id="MyHttpConnectionManagerParams">
<property name="defaultMaxConnectionsPerHost" value="20"/>
<property name="maxTotalConnections" value="200"/>
</bean>
Above parameters takes effect only if the endpoint URL is over HTTP, same configuration becomes void and default HttpConnectionManager takes effect when endpoint is over HTTPS.
Is there something to be additionally configured for HTTPS url?
Adding below beans has solved works for me.
Agreed there is no component named HTTPS in Camel but things are working with below configuration both in older and newer versions of Apache Camel.
<bean class="org.apache.camel.component.http.HttpComponent" id="http">
<property name="camelContext" ref="myCamelContext"/>
<property name="httpConnectionManager" ref="MyHttpConnectionManager"/>
</bean>
<bean class="org.apache.camel.component.http.HttpComponent" id="https">
<property name="camelContext" ref="myCamelContext"/>
<property name="httpConnectionManager" ref="MyHttpConnectionManager"/>
</bean>
<bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" id="MyHttpConnectionManager">
<property name="params" ref="MyHttpConnectionManagerParams"/>
</bean>
<bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams" id="MyHttpConnectionManagerParams">
<property name="defaultMaxConnectionsPerHost" value="100"/>
<property name="maxTotalConnections" value="500"/>
</bean>
I'm really struggling to get my Spring JMS template to work and send messages to a queue. Here's what I've got attempted:
In my XML:
<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<constructor-arg ref="mqQueueConnectionFactory" />
<property name="defaultDestination" ref="mqQueue" />
</bean>
<bean name="mqQueue" class="com.ibm.mq.jms.MQQueue">
<constructor-arg value="${MQ_QUEUE_MANAGER_NAME}" />
<constructor-arg value="${MQ_QUEUE_NAME}" />
</bean>
<bean name="mqQueueConnectionFactory" class="com.ibm.mq.jms.MQXAQueueConnectionFactory">
<property name="hostName" value="${MQ_HOST_NAME}" />
<property name="channel" value="${MQ_CHANNEL}" />
<property name="port" value="${MQ_PORT}" />
<property name="queueManager" value="${MQ_QUEUE_MANAGER_NAME}" />
<property name="transportType" ref="wmq_cl_binding" />
</bean>
So those are my beans for setting up the template/queue.
Now I setup a listener and jmsContainer:
<bean id="messageListener" class="CloseoutListener" />
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="mqQueueConnectionFactory" />
<property name="destination" ref="mqQueue" />
<property name="messageListener" ref="messageListener" />
</bean>
and my implementation of CloseoutListener is the same that is on the Spring JMS docs: Listener
In addition to this, I am trying to send a message in the same way that Spring sends a message in the docs: Sender
Full disclosure: First time using queues and any sort of JMS, as well as my second time using Spring so I'm aware if this is sloppy or just plain wrong. That's why I'm asking for assistance.
No message is appearing in the queue and in addition I'm getting this message in my logs:
INFO DefaultMessageListenerContainer.handleListenerSetupFailure :825 - JMS message listener invoker needs to establish shared Connection
I read on : http://www.javaworld.com/article/2074123/java-web-development/transaction-and-redelivery-in-jms.html?page=2
"Generally, acknowledging a particular message acknowledges all prior messages the session receives" ( in Client acknowledgement mode )
"Message redelivery is not automatic, but messages are redelivered under certain circumstances"
My questions :
how can I ensure there is a new session every time I recive a message (but reuse the connection)?
how to enforce the redelivery for un acknowledge message ?
Im using this configration :
<bean id="jmsConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory"
lazy-init="true">
<property name="queueManager" value="${queueManager}" />
<property name="hostName" value="${hostName}" />
<property name="transportType" value="${transportType}" />
<property name="port" value="${port}" />
<property name="channel" value="${channel}" />
<property name="SSLCipherSuite" value="${SSLCipherSuite}" />
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="maxConnections" value="10"/>
<property name="maximumActive" value="100"/>
<property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="transacted" value="false"/>
</bean>
<bean id="mqNonJmsDestRes" class="calypsox.tk.util.NonJmsMQQueueDestinationResolver" />
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="jmsConfig" />
<property name="acknowledgementModeName" value="CLIENT_ACKNOWLEDGE" />
<property name="destinationResolver" ref="mqNonJmsDestRes" />
</bean>
and I use camel processor as endpoint bean as singleton
That article you referenced is from 2002. All of the MQ based systems have received a lot of work since then. On your AMQ PooledConnectionFactory there are settings to control how long your connections last before they are destroyed and what you should do if you encounter an error. I recommend reading into some of the newer documentation since there has been a lot of changes in the last 14 years. So some things have become much easier.
You can also check into the exceptionListener on "org.apache.camel.component.jms.JmsComponent" to configure how to manage exceptions and even write your own if the current options don't suit your needs.