Integrate a Bonita BPM process in a Java Client

1
0
-1

Hi there,

Problem with working out how to integrate a java client with a Tomcat portal as per instructions Integrate a process into an application .

Here is what I've done so far:

  • Created a tomcat-portal
  • Copied tomcat/bonita to tomcat/bonitaBatch
  • Edited tomcat/bonitaBatch/conf/bonita-client.properties and commented out #Local while uncommented #HTTP ( Configuring Bonita Home for a client)
  • and copied the code from Integrate a process (Login & Logout only) to my java program
  • Opened the portal and verified the web pages are accessible

But when i execute my java client I get an error saying there is no session available.

My code is as follows:

        public static void main(String[] args) {

                System.out.println("Program started!");
                try {

String hostAPAddress = "192.***.***.***";
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("server.url", "http://"+hostIPAddress+":8080");
                        map.put("application.name", "app");

                        System.out.println("APITypeManager: In");
                        APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, map);
                        System.out.println("APITypeManager: Out");

                        // get the LoginAPI using the TenantAPIAccessor
                        System.out.println("Got a loginAPI: In");
                        LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();
                        System.out.println("Got a loginAPI: Out : " + loginAPI.toString());

                        // Set the username and password for the application
                        System.out.println("login: ");
                        final String username = "walter.bates";
                        final String password = "bpm";
                        // log in to the tenant to create a session
                        APISession apiSession = loginAPI.login(username, password);
                        System.out.println("Got a apiSession: " + apiSession.toString());

                        @SuppressWarnings("unused")
                        ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(apiSession);
                        System.out.println("Got a processAPI: " + processAPI.toString());

                        // Logout
                        loginAPI.logout(apiSession);
                        System.out.println("logout: ");

                } catch (BonitaHomeNotSetException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (ServerAPIException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (UnknownAPITypeException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (LoginException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (SessionNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (LogoutException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

                System.out.println("Program ended!");

        }

and the log is as follows, how do I fix this?

Program started!
APITypeManager: In
APITypeManager: Out
Got a loginAPI: In
Feb 12, 2015 3:40:40 PM org.bonitasoft.engine.api.HTTPServerAPI executeHttpPost
SEVERE: Not Found
httpost = <POST http://192.***.***.***:8080/app/serverAPI/org.bonitasoft.engine.api.LoginAPI/toString HTTP/1.1>
Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
        at com.sun.proxy.$Proxy0.toString(Unknown Source)
        at org.gubernare.app.app.main(app.java:110)
Caused by: org.apache.http.client.HttpResponseException: Not Found
        at org.bonitasoft.engine.api.HTTPServerAPI.invokeMethod(HTTPServerAPI.java:143)
        at org.bonitasoft.engine.api.impl.ClientInterceptor.invoke(ClientInterceptor.java:88)
        at com.sun.proxy.$Proxy0.toString(Unknown Source)
        at org.gubernare.app.app.main(app.java:110)
        at      < ========== Beginning of the server stack trace ========== >. ( )
        at org.bonitasoft.engine.http.BonitaResponseHandler.handleResponse(BonitaResponseHandler.java:45)
        at org.bonitasoft.engine.http.BonitaResponseHandler.handleResponse(BonitaResponseHandler.java:30)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1142)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1076)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1050)
        at org.bonitasoft.engine.api.HTTPServerAPI.executeHttpPost(HTTPServerAPI.java:165)
        at org.bonitasoft.engine.api.HTTPServerAPI.invokeMethod(HTTPServerAPI.java:135)
        at org.bonitasoft.engine.api.impl.ClientInterceptor.invoke(ClientInterceptor.java:88)
        ... 2 more

When I use

String hostAPAddress = "192.***.***.***";
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("server.url", "http://"+hostIPAddress+":8080");
                        map.put("application.name", "app");

I get the following error:

Program started!
APITypeManager: In
APITypeManager: Out
Got a loginAPI: In
Exception in thread "main" org.bonitasoft.engine.exception.BonitaRuntimeException: session is null
        at org.bonitasoft.engine.api.HTTPServerAPI.invokeMethod(HTTPServerAPI.java:143)
        at org.bonitasoft.engine.api.impl.ClientInterceptor.invoke(ClientInterceptor.java:88)
        at com.sun.proxy.$Proxy0.toString(Unknown Source)
        at org.gubernare.app.app.main(app.java:110)
        at      < ========== Beginning of the server stack trace ========== >. ( )
        at org.bonitasoft.engine.api.impl.ServerAPIImpl.invokeAPIInTransaction(ServerAPIImpl.java:322)
        at org.bonitasoft.engine.api.impl.ServerAPIImpl.invokeAPI(ServerAPIImpl.java:274)
        at org.bonitasoft.engine.api.impl.ServerAPIImpl.invokeMethod(ServerAPIImpl.java:128)
        at org.bonitasoft.engine.api.internal.servlet.HttpAPIServletCall.doPost(HttpAPIServletCall.java:112)
        at org.bonitasoft.engine.api.internal.servlet.HttpAPIServlet.doPost(HttpAPIServlet.java:35)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.bonitasoft.console.security.SessionFixationValve.invoke(SessionFixationValve.java:77)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)

Comments

Submitted by Pierre-yves Monnet on Sat, 02/14/2015 - 01:50

Hello, You said : •Created a tomcat-portal •Copied tomcat/bonita to tomcat/bonitaBatch ==> WHY ? •Edited tomcat/bonitaBatch/conf/bonita-client.properties and commented out #Local while uncommented #HTTP ( Configuring Bonita Home for a client) ==> Why •and copied the code from Integrate a process (Login & Logout only) to my java program

•Opened the portal and verified the web pages are accessible ==> Is that working ?

What you use is the standard API. So, 1/ is your server run correctly ? Try to connect via a browser to connector to http://192...***:8080/app (>>>app because this is the name you gave in the application)

Log as walter.bates, pass bpm. You can access ? I think not because the client can't.

If the URL us http://....:8080/bonita, then set bonita in your application.

NB : the different step are not necessary. If you like to change the application name "bonita" to "app", you have to change the bonita.war to app.war and deploy again. After, you may have some extra configuration to perform (minimum the conf/catalina/bonita.xml shoud be rename to conf/catalina/app.xml

Submitted by Sean McP on Sat, 02/14/2015 - 09:25

Many thanks Pierre-yves,

In answer to your questions:

Copied tomcat/bonita to tomcat/bonitaBatch ==> WHY ?

According to configuring-bonita-home-client (the very first paragraph, line 2) Every client application needs its own Bonita home. and There can be multiple clients accessing the same Bonita BPM Engine. Each client application runs in its own JVM and needs its own bonita.home system property, directory tree, and bonita-client.properties file. (paragraph 3).

If my understanding of the word client is wrong then maybe the use of the word itself is wrong.

To me the engine is a service (server), the portal is a client and my batch program is a client...

So in this case I have the Portal, and a JAVA batch program client, if I am reading this wrong then please correct me.

Edited tomcat/bonitaBatch/conf/bonita-client.properties and commented out #Local while uncommented #HTTP ( Configuring Bonita Home for a client) ==> Why

This would be a result of the first WHY, my JAVA batch program needs to talk to the Portal (through http access) I cannot think of any other reason for doing this.

Here is what I'm trying to do, if my understanding is wrong, happy to learn:

I want to have the portal running and have a JAVA batch client program access the same engine. For example, my developers release new processes but these are only deployed once a week. So we have 10,20, even 100 processes to deploy to production a week.

We do not want to do this manually.

So we write a java batch program to upload the processes from a directory and run this once a week to upload all new processes.

I've tried the Maven example and now understand this creates a separate platform and engine meaning my processes are not shown in the portal.

I need to reference the same engine from java batch as the portal so we can make this work.

If I uncomment both the LOCAL and HTTP (as below) in bonita-client.properties then the portal hangs and never finishes startup.

# LOCAL
org.bonitasoft.engine.api-type = LOCAL

# HTTP
org.bonitasoft.engine.api-type = HTTP
server.url = http://localhost:8080
application.name = bonita

So my question really is what is the correct way to have the portal running and a java batch client access the same engine.

Many thanks and best regards Seán

Submitted by Pierre-yves Monnet on Sat, 02/14/2015 - 23:02

I see. In fact, this page is to explain how to configure it if you just call a LoginAPI. If you give parameter via APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, map); then you definitively does not need this client part !

For your information, BonitaPortal is a client, he have only the BonitaHome enviroment set and then it use this directory.

So, your Client will be simple if you use the setAPITypeAndParams() call ! So, keep it simple : * use the setAPITypeAndParams * do not bother with the Bonita Client file * Check the application in your map : it should be "bonita" and not "app". It should works.

Let's me know. PS : if you have this number of process (you call 100 process a week ? Not a case ? Which can of process could you deploy like this ? ), It's maybe time to have a look on the Subscription part : you have then a more powerfull engine (some class has different than the community), you can access Support for this kind of question (faster than the community, and you are sure to have an answer) and you have access to the cluster implementation. And you can access to some extra tool : for example, we have a Custom Page "automatic deployment" : this page check a path every 5 s and deploy in automatic all process found => you save time and speed up your deployment.

Let's me know if you can connect.

Submitted by Sean McP on Sun, 02/15/2015 - 06:01

Many thanks again Pierre-yves,

following your advice:

  • I have removed the "other client directory"
  • I have only the one line available in bonita-client.properties, specified as : org.bonitasoft.engine.api-type = LOCAL
  • I have made sure my java program executes against the same bonita.home
  • Tomcat was restarted and is running, I can login using my browser
  • My java program is (relevant lines only):
// check that Bonita Home is set
checkBonitaHome();
       
                Map<String, String> map = new HashMap<String, String>();
                        map.put("server.url", "http://localhost:8080");
                        map.put("application.name", "bonita");

                        System.out.println("APITypeManager: In");
                        APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, map);
                        System.out.println("APITypeManager: Out");

                        // get the LoginAPI using the TenantAPIAccessor
                        System.out.println("Got a loginAPI: In");
                        LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();  // <failing line
                        System.out.println("Got a loginAPI: Out : " + loginAPI.toString());

but it fails trying to get the LoginAPI, says session is null

I tried changing the localhost to the IP of my system (192.168.1.90) but the same result, and I do not have a proxy on this system

Program started!
bonitaHome = E:\Bonita 641\BonitaBPMCommunity-6.4.1-Tomcat-7.0.55\bonita
APITypeManager: In
APITypeManager: Out
Got a loginAPI: In
Exception in thread "main" org.bonitasoft.engine.exception.BonitaRuntimeException: session is null
        at org.bonitasoft.engine.api.HTTPServerAPI.invokeMethod(HTTPServerAPI.java:143)
        at org.bonitasoft.engine.api.impl.ClientInterceptor.invoke(ClientInterceptor.java:88)
        at com.sun.proxy.$Proxy0.toString(Unknown Source)
        at org.gubernare.app.app.main(app.java:110)
        at      < ========== Beginning of the server stack trace ========== >. ( )
        at org.bonitasoft.engine.api.impl.ServerAPIImpl.invokeAPIInTransaction(ServerAPIImpl.java:322)
        at org.bonitasoft.engine.api.impl.ServerAPIImpl.invokeAPI(ServerAPIImpl.java:274)
        at org.bonitasoft.engine.api.impl.ServerAPIImpl.invokeMethod(ServerAPIImpl.java:128)
        at org.bonitasoft.engine.api.internal.servlet.HttpAPIServletCall.doPost(HttpAPIServletCall.java:112)
        at org.bonitasoft.engine.api.internal.servlet.HttpAPIServlet.doPost(HttpAPIServlet.java:35)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.bonitasoft.console.security.SessionFixationValve.invoke(SessionFixationValve.java:77)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)

Regarding the batching of a number of processes, yes these are processes and not cases. Can't say to much at the minute. Suffice to say that should my processes need upgrading from v1.0 to v2.0 then it will happen in batch and not one or two at a time.

From my perspective I also have a requirement in that my "client" requires formal release management processes and procedures which means "batching" of updates/fixes, going through release teams, getting approvals and scheduling etc. Financial industries and other government bodies for example insist on good release management.

As for Subscription, yes, I understand but our business is built on lowest common denominator which means for now Community is ideal.

I'll give you more information as soon as I can.

regards Seán

No answers yet.
Notifications