Springboot xml bean and container - spring-boot

Hello everyone can someone explain me this lines of code thanks
<!-- websocket client bean -->
<bean id="webSocketClient" class="org.springframework.web.socket.client.standard.StandardWebSocketClient"/>
<!-- inbound-channel-adapter && client-container -->
<int-websocket:client-container id="clientContainer"
client="webSocketClient"
uri="wss://genericurl.com:9443/ws/>
i would understand how websocket client bean and container works togheter

Related

Apache Camel + Spring Boot + IBM MQ

I want to use Apache Camel to get a message on IBM MQ in a spring boot project.
I use sprin boot annotation based.
I dont find any fully example: pom.xml, receiver, configuration class, ...
Is there anyone to help me? Any link, documentation, ...?
Thanks a lot of
Take a look at a new Spring Boot Starter for MQ that may help here. The README shows how to modify the JMS Getting Started sample here to use IBM MQ instead of ActiveMQ. And the MQ jars - including this starter - are all on Maven Central for easy access.
You could search for an example that uses Spring Boot, Camel and ActiveMQ to get a first impression. Since you use Camel most differences between IBM MQ and ActiveMQ should be hidden.
However, you have to use the standard JMS component instead of the dedicated ActiveMQ component of Camel.
In your Application class, you will need create a bean for a IBM component, I just did it for an application in spring xml, like this:
<bean id="cf" class="com.ibm.mq.jms.MQConnectionFactory">
<property name="transportType" value="1" />
<property name="hostName" value="localhost" />
<property name="port" value="1414" />
<property name="queueManager" value="QMGRSCORE" />
<property name="channel" value="EXTAPP.SRVCONN" />
</bean>
But once I did a bean connection for a MongDB in spring boot, may you can do something like this:
#Bean(name = "myDb")
public MongoClient myDb() {
return new MongoClient();
}
But putting the IBM values inside this bean.

The method setExceptionListener is not permitted in this container

I am trying to make current Spring application work with Websphere 7 default JMS provider. I have created a Bus and assign a queue with it, also a SIB QueueConnectionFactory, a SIB Queue and a Activation Specification and link it with the SIB queue. I am assured that the message engine started for the application server.
So there is my web.xml to refer the JNDI resource
<!-- Question: should I define Activation Specification here as well as a resource ? -->
<resource-ref>
<description>JNDI JMS Conn Factory </description>
<res-ref-name>jms/ConnectionFactory</res-ref-name>
<res-type>javax.jms.ConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>JNDI JMS Queue </description>
<res-ref-name>jms/queue/QueueOrderUpdate</res-ref-name>
<res-type>javax.jms.Queue</res-type>
<res-auth>Container</res-auth>
</resource-ref>
The when I start the application, it gives me:
Could not refresh JMS Connection for destination 'ORDER.QUEUE' - retrying in 5000 ms. Cause:
CWSIA0025E: The method setExceptionListener is not permitted in this container.
javax.jms.IllegalStateException: CWSIA0025E: The method setExceptionListener is not permitted
in this container.
ORDER.QUEUE is what the app refers to the queue from WS:
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsCachingConnectionFactory" />
<!-- same queue as jms/queue/QueueOrderUpdate -->
<property name="defaultDestinationName" value="ORDER.QUEUE" />
<property name="messageConverter" ref="orderMessageConverter"/>
</bean>
and that should be
<!-- I think this should be the queue defined for the bus but not the SIB queue right? -->
<jee:jndi-lookup id="jmsQueue" jndi-name="jms/queue/QueueOrderUpdate">
<jee:environment>
java.naming.provider.url=${java.naming.provider.url}
java.naming.factory.initial=${java.naming.factory.initial}
java.naming.factory.url.pkgs=${java.naming.factory.url.pkgs}
</jee:environment>
</jee:jndi-lookup>
It should be the queue I defined in Websphere:
Here are my questions:
If the default JMS provider is chosen from Websphere, then by default it should be the JCA compliant JMS implementation and I assume it should use the Activation Specification adapter instead of listener ports?
If so, then should I link the Activation Specification JNDI in web.xml and Spring bean config instead of the Connection Factory? so there should be three in web.xml, one for ConnectionFactory, one for Queue and one for Activation Specification?
Why the exception thrown?
UPDATE:
I find no listener ports bind to current server, please see following screenshot:
Looking to my old project with Spring JMS for WAS 7 I have nothing regarding JNDI in the web.xml.
My spring config on the matter looks like:
<bean id="connectionFactory" class="org.springframework.jms.connection.DelegatingConnectionFactory">
<property name="targetConnectionFactory">
<jee:jndi-lookup jndi-name="jms/StpConnectionFactory"/>
</property>
<property name="shouldStopConnections" value="true"/>
</bean>
<jee:jndi-lookup id="orderQueue" jndi-name="jms/queue/QueueOrderUpdate"/>
On WAS I remeber that I just used Default JMS Provider for the ConnectionFactory, as well for Destinations.

getting a handle to the application context

I am trying t learn various technologies - want to do some UI stuff using HTML5 with Jquery
In the UI I am making a call to a RESTFUL webservice ( Jersey ) which generates JSON output
In my webservice - I had stubbed the data that was supposed to come from the database ( mysql )
Now I want to learn Spring JDBC template ( and not use plain JDBC )
So my question is about using spring ( only spring jdbc and not spring mvc ) in a web application which hosts my RESTFUL webservice
I want to use spring jdbc template - so have written a spring xml file where I am creating the necessary configurations
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="....."
xsi:schemaLocation="....">
<bean id="examDAO" class="com.examscripts.mockexam.repository.ExamRepositoryImpl">
<property name="ds" ref="ds" />
</bean>
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/mockexam" />
<property name="username" value="xxx" />
<property name="password" value="yyy" />
</bean>
To load these in I added the following in web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
on tomcat startup I can see that the file is loaded :
Loading XML bean definitions from class path resource ....
Now my question is in my service layer where I need to communciate with DAO layer ( jdbc ) - do have to create the actual bean using something like this :
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
// instantiate our spring dao object from the application context
ExamRepositoryImpl impl= (ExamRepositoryImpl)ctx.getBean("examDAO");
I am completely new to spring and googling seems to always show spring mvc web apps or standalone spring examples - my case is a web app minus spring mvc but using spring jdbc template
any pointers ?
Loading XML bean definitions from class path resource ....
You're on the right track. Spring is loading your XML file (when you deploy the app) and instantiating the beans that you declared. Crank up the logging for org.springframework to get more details.
Now my question is in my service layer where I need to communciate
with DAO layer ( jdbc ) - do have to create the actual bean using
something like this :
No, definitely not. The entire purpose of using a dependency injection framework like Spring is to avoid writing code like this.
Declare a setter in your service class that takes the DAO as an argument.
public void setExamDAO(ExamDao examDao) {
this.examDao = examDao;
}
Add a new XML bean definition for your service class in your XML file and create a new <property> that wires in the DAO:
<bean id="yourservice" class="com.foo.YourServiceClass">
<property name="examDao" ref="examDAO"/>
</bean>

Jersey and Spring profiles

I should to create Jersey endpoint that will be available only for some spring profiles. I tried to do it in following way:
<beans profile="teamcity">
<bean id="impactRadiusEndpoint" class="com.jingit.api.service.ImpactRadiusEndpoint">
<constructor-arg ref="impactRadiusQueueProcessor"/>
<constructor-arg ref="messagesReceiver"/>
</bean>
</beans>
But when I start up application with some other profiles and call this endpoint, Jersey ignores spring profiles and trying to start up. I find following output in logs:
SEVERE: Missing dependency for constructor public com.jingit.api.service.ImpactRadiusEndpoint(com.jingit.commons.queue.service.QueueProcessor,com.jingit.commons.queue.service.QueueMessagesReceiver) at parameter index 0
SEVERE: Missing dependency for constructor public com.jingit.api.service.ImpactRadiusEndpoint(com.jingit.commons.queue.service.QueueProcessor,com.jingit.commons.queue.service.QueueMessagesReceiver) at parameter index 1
Also this issue brokes other endpoints. Does anybody have a idea how to fix it?

Spring does not autowire beans with JAX-WS webservice end points

I am trying to consume a JAX-WS webservice written by me. I always get nullPointerException for spring autowired annotated beans. However, everything works fine within serverSide over web, but accessing beans through JAX-WS webservice.
I have tried by extending SpringBeanAutowiringSupport, but still no luck. How can I do this.
regards, Rohit
I had no experience extending SpringBeanAutowiringSupport but had successfuly used this approach:
Annotate webService class such a way :
#Component("yourWebService")
#WebService(endpointInterface ="your.package.YourServicePort")
Create new spring-context xml for webService and define JAX-WS endpoint :
<jaxws:endpoint
id="yourServiceEndpoint"
implementor="#yourWebService"
address="${yourWebService.wsdl.url}"> //load url from properties file
</jaxws:endpoint>
I suppose you know how to use props in spring, but will explain just in case. You should also create yourWebService.properties file and define it in spring context to use this construction ${yourWebService.wsdl.url} :
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>yourWebService.properties</value>
</list>
</property>
Using this approach I had successfuly used JAX with Spring

Resources