[Resolved] Java Bonita client accessing the Bonita API in the HTTP mode

Flip0's picture
Post submitted by Flip0 Sat, 04/20/2013 - 17:39

Hi guys,



I got a strange problem. I want to access the Bonita API (e.g. queryRuntimeAPI.getLightProcessInstances...) using REST. Therefore I deployed bonita-server-rest.war (BOS 5.9) on my JBoss. I also updated the JBoss start parameters (BonitaHome, API-Type=REST, REST-URL...) and updated the login-context.



Then I tried to access the server using a Rest Client (as described at the end of this page: http://www.bonitasoft.org/blog/tutorial/how-to-use-the-bonita-http-api/ ). Everything worked fine! As I can access all methods via calling the REST url directly, I assume that my server setup is correct.



Now, I want to access the Bonita API from a different JVM using REST HTTP mode. I used the example as described on the above page (by the way: good explanation and sample page!), using an matching jaas config. But when I try to access a restricted method, the following error happens:


  1. <br>
  2. 20.04.2013 17:16:59 org.ow2.bonita.util.AccessorUtil resetContext<br>
  3. INFO: API-Type: REST has been specified through property: org.ow2.bonita.api-type<br>
  4. 20.04.2013 17:16:59 org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme<br>
  5. INFO: basic authentication scheme selected<br>
  6. 20.04.2013 17:16:59 org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallenge<br>
  7. INFO: No credentials available for BASIC 'BonitaRESTServer'@localhost:8180<br>
  8. 20.04.2013 17:16:59 org.ow2.bonita.facade.rest.provider.GenericObjectProvider readFrom<br>
  9. SCHWERWIEGEND: Error while decoding [geshifilter-html]<head><title>JBoss Web/7.0.13.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication ().</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.13.Final</h3></body>[/geshifilter-html]: com.thoughtworks.xstream.mapper.CannotResolveClassException: html<br>
  10. at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56)<br>
  11. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  12. at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)<br>
  13. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  14. at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88)<br>
  15. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  16. at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:79)<br>
  17. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  18. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  19. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  20. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  21. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  22. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  23. at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:74)<br>
  24. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  25. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  26. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  27. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  28. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  29. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  30. at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)<br>
  31. at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:45)<br>
  32. at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29)<br>
  33. at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:133)<br>
  34. at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)<br>
  35. at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1052)<br>
  36. at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1036)<br>
  37. at com.thoughtworks.xstream.XStream.fromXML(XStream.java:912)<br>
  38. at com.thoughtworks.xstream.XStream.fromXML(XStream.java:903)<br>
  39. at org.ow2.bonita.facade.rest.provider.GenericObjectProvider.readFrom(GenericObjectProvider.java:92)<br>
  40. at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105)<br>
  41. at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:46)<br>
  42. at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108)<br>
  43. at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:111)<br>
  44. at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:246)<br>
  45. at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:210)<br>
  46. at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:183)<br>
  47. at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:177)<br>
  48. at org.ow2.bonita.facade.rest.interceptor.BonitaClientErrorInterceptor.handle(BonitaClientErrorInterceptor.java:39)<br>
  49. at org.jboss.resteasy.client.core.ClientInvoker.extractEntity(ClientInvoker.java:192)<br>
  50. at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:112)<br>
  51. at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:59)<br>
  52. at $Proxy22.getLightProcessInstances(Unknown Source)<br>
  53. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
  54. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>
  55. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>
  56. at java.lang.reflect.Method.invoke(Unknown Source)<br>
  57. at org.ow2.bonita.facade.interceptor.ClientRemoteAPIInterceptor.invoke(ClientRemoteAPIInterceptor.java:143)<br>
  58. at $Proxy23.getLightProcessInstances(Unknown Source)<br>
  59. at org.bonitasoft.examples.BonitaClient.main(BonitaClient.java:65)<br>
  60. <br>
  61. Exception in thread "main" org.jboss.resteasy.client.ClientResponseFailure: Error status 401 Unauthorized returned<br>
  62. at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:306)<br>
  63. at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:297)<br>
  64. at org.jboss.resteasy.client.core.BaseClientResponse.checkFailureStatus(BaseClientResponse.java:291)<br>
  65. at org.jboss.resteasy.client.core.ClientInvoker.extractEntity(ClientInvoker.java:159)<br>
  66. at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:112)<br>
  67. at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:59)<br>
  68. at $Proxy22.getLightProcessInstances(Unknown Source)<br>
  69. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
  70. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>
  71. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>
  72. at java.lang.reflect.Method.invoke(Unknown Source)<br>
  73. at org.ow2.bonita.facade.interceptor.ClientRemoteAPIInterceptor.invoke(ClientRemoteAPIInterceptor.java:143)<br>
  74. at $Proxy23.getLightProcessInstances(Unknown Source)<br>
  75. at org.bonitasoft.examples.BonitaClient.main(BonitaClient.java:65)<br>





I've searched the forum for this message "No credentials available for BASIC 'BonitaRESTServer'" and found this entry: http://www.bonitasoft.org/forum/viewtopic.php?id=9843

The guy told in the fifth post:

[quote=galrub]Solved, the problem was not in the code, there was a mixed up in the library version and we had to add firewall exceptions for Java in windows,



Many thanks,

G[/quote]



I've tried to disable my firewall (Win 8 64bit) completely, but it doesn't get better. I do not know where libary version problems could be.



Some additional interesting facts:

- BonitaAuth works correctly (LoginFailure exception when credentials are wrong).

- Unrestricted methods like managementAPI.checkUserCredentials(LOGIN, PASSWORD) also work without error.



Any ideas on that topic?



Best regards,

FlipO

Comments

Submitted by elias.ricken Tue, 04/23/2013 - 16:22

Hi,



Did you try to configure the User XP to run in HTTP mode (in the same JBoss you have configured the REST server)?

Does your client have other dependencies then bonita-client?

For library conflicts take look at commons-httpclient, commons-codec, httclient and httpcore.



Regards,

Submitted by alagna Tue, 05/14/2013 - 16:58

Flip0 were you able to solve the problem?

I followed your steps and have the same issue on a BOS-5.9.1-JBoss-5.1.0.GA bundle.



On the jboss server side I see the following error:



16:49:21,941 ERROR [UsersRolesLoginModule] Failed to load users/passwords/role files

java.io.IOException: No properties file: users.properties or defaults: defaultUsers.properties found

...

16:49:21,942 WARN [JAASRealm] Cannot find message associated with key jaasRealm.loginException

javax.security.auth.login.LoginException: Missing users.properties file.

...



any ideas?

thanks

Alberto

Submitted by elias.ricken Fri, 05/17/2013 - 13:47

Alberto, did you modify the file login-config.xml to add the login context BonitaRESTServer? See here



Regards,

Submitted by alagna Fri, 05/17/2013 - 14:10

I didn't have it.



now I put in my login-config.xml









restuser

restbpm

restuser









and I get a different error:



17-mag-2013 14.08.30 org.ow2.bonita.facade.rest.provider.GenericObjectProvider readFrom

GRAVE: Error while decoding <head><title>JBoss Web/2.1.3.GA - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication ().</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/2.1.3.GA</h3></body>: com.thoughtworks.xstream.mapper.CannotResolveClassException: html

at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56)

.....



17-mag-2013 14.08.30 org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme

INFO: basic authentication scheme selected

17-mag-2013 14.08.30 org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallenge

INFO: No credentials available for BASIC 'BonitaRESTServer'@localhost:8080

17-mag-2013 14.08.30 org.ow2.bonita.facade.rest.provider.GenericObjectProvider readFrom

GRAVE: Error while decoding <head><title>JBoss Web/2.1.3.GA - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication ().</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/2.1.3.GA</h3></body>: com.thoughtworks.xstream.mapper.CannotResolveClassException: html

.....



Exception in thread "main" org.jboss.resteasy.client.ClientResponseFailure: Error status 401 Unauthorized returned

.......

Submitted by alagna Mon, 05/20/2013 - 10:05

I had to add not only the login context configuration but also the context configuration and now the example I found in http://www.bonitasoft.org/blog/tutorial/how-to-use-the-bonita-http-api/ is working.



Thanks

Alberto

Submitted by ttoine Tue, 05/21/2013 - 11:49

Is it solved ?

Submitted by alagna Tue, 05/21/2013 - 12:11

I tought it was. Now I have a different problem.



My complete env is a jboss 6 eap webapp that tries to talk to a bonita 5.9.1 bundle on jboss 5.1.0.



If I call the bonita server from a standalone client (within eclipse) it works fine as I wrote.

But if I put the bonita client inside the webapp I get the following error



16:52:26,297 ERROR [acme.integration.bpm.BpmServiceImpl] (http-/127.0.0.1:8180-2) problema sull'autenticazione:: javax.security.auth.login.FailedLoginException: Password Incorrect/Password Required

at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:293) [picketbox-4.0.9.Final-redhat-1.jar:4.0.9.Final-redhat-1]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [classes.jar:1.6.0_45]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [classes.jar:1.6.0_45]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [classes.jar:1.6.0_45]

at java.lang.reflect.Method.invoke(Method.java:597) [classes.jar:1.6.0_45]

at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769) [classes.jar:1.6.0_45]

at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186) [classes.jar:1.6.0_45]

at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683) [classes.jar:1.6.0_45]

at java.security.AccessController.doPrivileged(Native Method) [classes.jar:1.6.0_45]

at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680) [classes.jar:1.6.0_45]

at javax.security.auth.login.LoginContext.login(LoginContext.java:579) [classes.jar:1.6.0_45]

at acme.integration.bpm.BpmServiceImpl.init(BpmServiceImpl.java:90) [classes:]

at acme.integration.bpm.BpmServiceImpl.ricercaAttivitaPendenti(BpmServiceImpl.java:50) [classes:]

at acme.frontend.webservice.CoreServiceImpl.updateGruppiAttivitaPendenti(CoreServiceImpl.java:347) [classes:]

at acme.frontend.webservice.CoreServiceImpl.setupCruscotto(CoreServiceImpl.java:168) [classes:]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [classes.jar:1.6.0



and acme.integration.bpm.BpmServiceImpl.init is

......

LoginContext loginContext = new LoginContext("BonitaStore", new SimpleCallbackHandler(LOGIN, PSSWD));

loginContext.login(); // the exception is thrown here

logger.debug("autenticazione ottenuta con successo");