Showing posts with label Liberty Profile. Show all posts
Showing posts with label Liberty Profile. Show all posts

Thursday, October 4, 2018

Message Queue in Liberty Profile ​

I didn't know that Liberty Profile has come with an internal embedded messaging server? This sound interesting to me, I should to give it a try now. For this to work, it required the full profile version of Liberty Profile. When I first start, I didn’t realize the one I'm using now is a web profile version, end up I'm not able to configure the messaging features in the server. I got the Liberty full profile from here. According to the tutorial found on the web, the configuration on the server.xml is pretty straightforward. Here is the work done in PTP configuration:

The <jmsactivationspec> tag is the very crucial part of connecting the embedded messaging engine to the MDB deployed in the server. The documentation mentions here has detail explanation on how the things should work. Without this tag or miss configure the id will give a friendly error reminding you that there are some problem with the tag. Below is the sample error in my case, notice the name of the id has mentioned in the error:
[WARNING ] CNTR4015W: The message endpoint for the MessageBean message-driven bean cannot be activated because the jms2-0.0.1-SNAPSHOT/MessageBean activation specification is not available. The message endpoint will not receive messages until the activation specification becomes available.
Code snippet below is a simple MDB app for the sake of this testing purpose:


Connect to MDB without using JNDI 

Now the server is ready to accept the incoming messages. The sample below is a standalone Java program that will establish a connection to Liberty Profile, it doesn’t use the JNDI to send the message to MDB. This is the hardest part as not much information available on the web. Eventually, I have identified 3 libraries which are needed in order to build this program, there are available in the WAS installation path located at AppServer/runtimes​. Here are the 3 libraries:
  1. com.ibm.ws.ejb.thinclient_8.5.0.jar
  2. com.ibm.ws.sib.client.thin.jms_8.5.0.jar
  3. com.ibm.ws.orb_8.5.0.jar
Looking at the code above, I have no idea what the setBusName() on line 16 trying to do? It will just throw an error as seen below if I remove that line:
Caused by: com.ibm.websphere.sib.exception.SIIncorrectCallException: CWSIT0003E: No busName property was found in the connection properties.
  at com.ibm.ws.sib.trm.client.ClientAttachProperties.< init>(ClientAttachProperties.java:109)
  at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.createConnection(TrmSICoreConnectionFactoryImpl.java:295)
  at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.createConnection(TrmSICoreConnectionFactoryImpl.java:222)
  at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createCoreConnection(JmsJcaConnectionFactoryImpl.java:711)
  at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createCoreConnection(JmsJcaConnectionFactoryImpl.java:647)
  at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createConnection(JmsJcaConnectionFactoryImpl.java:376)
  at com.ibm.ws.sib.api.jms.impl.JmsManagedConnectionFactoryImpl.createConnection(JmsManagedConnectionFactoryImpl.java:162)
  ... 3 more

Connect to MDB with JNDI

This is much easier to implement as compare to the previous client app just because it uses JNDI. It doesn’t require any additional library from WAS server. Long story short, here is the code:

Monday, August 26, 2013

Launching WebSphere Liberty Profile from MAVEN

Good day ^o^ Finally I have successfully launch WebSphere Liberty Profile from MAVEN. But only in Linux, not in Windows. I wasn't really sure what is happening on Windows? Because when I launch the server directly from command prompt as shown below will immediately return an error.

server.bat start MyServer

Since even command prompt has failed, it will be the same in MAVEN. Anyhow that only happened on Windows. Only Windows will always cause trouble to me! Now my objective is to configuration MAVEN goal like this > clean install liberty:start-server. To achieve this, some workaround is needed.

1. First thing to do is to declare a repository for Liberty Profile in pom.xml as shown below:
 
  
   WASdev
   WASdev Repository
   http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/
   default
   
    false
   
   
    true
   
  
 
2. Then declare a start-server goal as shown below:
  
   com.ibm.websphere.wlp.maven.plugins
   liberty-maven-plugin
   1.0
   
      /home/kokhoe/tool/wlp
      MyInstance
   
   
      
         start-server
         pre-integration-test
         
            start-server
         
         
            200
            /home/kokhoe/tool/wlp/usr/servers/MyInstance/server.xml
         
      
   
   ...
   ...
3. Open the server.xml which I have specified during the step 2 of the MAVEN configuration, add/replace the following code.

*NOTE: The default value of location attribute is without the full path and version number.

To determine the location attribute, this is how I do it. At the beginning of MAVEN configuration, I have this:
    org.huahsin
    WebProject
    0.0.1-SNAPSHOT
    war
That is for MAVEN allocate my web application in repository. With this information, I know that during the install stage life cycle, my application will be installed into following location:

/home/kokhoe/.m2/repository/org/huahsin/WebProject/0.0.1-SNAPSHOT/

By now when MAVEN build is trigger, it will automatically package and deploy, and the server is ready to listening incoming request.

Sunday, July 28, 2013

Unable to find data source in Liberty Profile server

Recently the data source at my local server have create so much trouble to me. I'm using WebSphere Liberty Profile server in my development. In order to ease my work on deployment into production server with minimum changes as possible, I created a data source at my local server. But the data source doesn't seem function properly. I have the following code that grabs the data source from the server and establishes a connection to database server.
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

datasourceJndi="jdbc/informixDB";
Context jndiCntx = new InitialContext();
           
DataSource ds = (javax.sql.DataSource)jndiCntx.lookup(datasourceJndi);
            
//set the connection.
super.con = ds.getConnection();

The code was not working and following stack trace is being thrown.
java.sql.SQLNonTransientException: J2CA8030E: Unable to find jdbcDriverRef com.ibm.ws.jdbc.jdbcDriver_gen_d3507f1a-ecba-4697-9861-d2fe2c14d742 for dataSource jdbc/informixDB.

 at org.huahsin.util.DaoManager.getDaoConnection(DaoManager.java:56)
 at org.huahsin.util.DaoManager.setSql(DaoManager.java:65)
 at org.huahsin.dao.MenuItemDao.findMenuByUserId(MenuItemDao.java:43)
 at org.huahsin.web.MenuBean.getMenuList(MenuBean.java:32)
 at org.huahsin.LoginBean.doLogin(LoginBean.java:243)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.el.parser.AstValue.invoke(AstValue.java:266)
 at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
 at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:70)
 at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:88)
 at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:100)
 at javax.faces.component.UICommand.broadcast(UICommand.java:120)
 at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:937)
 at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:271)
 at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1249)
 at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:675)
 at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34)
 at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
 at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1221)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:757)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:440)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:92)
 at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:97)
 at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
 at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
 at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:939)
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1036)
 at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:81)
 at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:930)
 at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$1.run(DynamicVirtualHost.java:253)
 at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:457)
 at com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:398)
 at com.ibm.ws.threading.internal.Worker.run(Worker.java:380)
 at java.lang.Thread.run(Thread.java:662)

It was very hard for me to analyze this problem because there are not much people know there is a lightweight WebSphere Application Server ever exists in this world. And since this is new, the support usually is very limited. I have run out of clues on this issue. The temporary solution for this is to switch back to JDBC connection just for my local development
Class.forName("com.informix.jdbc.IfxDriver");
super.con = DriverManager.getConnection("jdbc:informix-sqli://xxx.xxx.xx.xx:2020/dbname:INFORMIXSERVER=online", "username", "password");