# How can I log into bonita engine from external java application with APIClient?

**URL:** https://community.ofelia.com/t/how-can-i-log-into-bonita-engine-from-external-java-application-with-apiclient/10235
**Category:** Q&A
**Created:** [18 June 2020 10:30 UTC](https://community.ofelia.com/t/how-can-i-log-into-bonita-engine-from-external-java-application-with-apiclient/10235 "2020-06-18T10:30:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kurucsai.zoltan1988](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kurucsai.zoltan1988](https://community.ofelia.com/u/kurucsai.zoltan1988)
#### Post date: [18 June 2020 10:30 UTC](https://community.ofelia.com/t/how-can-i-log-into-bonita-engine-from-external-java-application-with-apiclient/10235/1 "2020-06-18T10:30:23Z")

</div>

I have a program in a different server but i need to acces some of the API-s of the bonita engine. How can i do that?

I already tried:&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; parameters.put("server.url", "http://URL:PORT");  
&nbsp; &nbsp; &nbsp; &nbsp; parameters.put("application.name", "bonita");  
&nbsp; &nbsp; &nbsp; &nbsp; APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, parameters);

&nbsp; &nbsp; &nbsp; &nbsp; org.bonitasoft.engine.api.APIClient apiClient = new APIClient();  
&nbsp; &nbsp; &nbsp; &nbsp; apiClient.login("user", "password");

&nbsp;

But I always get some error like:

[org.apache.juli.logging.DirectJDKLog] [http-nio-8888-exec-1] [175] [ERROR] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.reflect.UndeclaredThrowableException] with root cause  
org.apache.http.client.HttpResponseException: status code: 404  
&nbsp;&nbsp; &nbsp;at org.apache.http.impl.client.AbstractResponseHandler.handleResponse(AbstractResponseHandler.java:70)  
&nbsp;&nbsp; &nbsp;at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:66)  
&nbsp;&nbsp; &nbsp;at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:52)  
&nbsp;&nbsp; &nbsp;at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)  
&nbsp;&nbsp; &nbsp;at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)  
&nbsp;&nbsp; &nbsp;at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:140)  
&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.api.HTTPServerAPI.executeHttpPost(HTTPServerAPI.java:152)  
&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.api.HTTPServerAPI.invokeMethod(HTTPServerAPI.java:123)  
&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.api.impl.ClientInterceptor.invoke(ClientInterceptor.java:86)  
&nbsp;&nbsp; &nbsp;at com.sun.proxy.$Proxy144.login(Unknown Source)  
&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.api.APIClient.login(APIClient.java:149)  
&nbsp;&nbsp; &nbsp;at hu.rate.jarkon.generalas.generalasws.controllers.GeneralasController.runJovairas(GeneralasController.java:94)  
&nbsp;&nbsp; &nbsp;at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
&nbsp;&nbsp; &nbsp;at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)  
&nbsp;&nbsp; &nbsp;at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
&nbsp;&nbsp; &nbsp;at java.lang.reflect.Method.invoke(Unknown Source)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)  
&nbsp;&nbsp; &nbsp;at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)  
&nbsp;&nbsp; &nbsp;at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)  
&nbsp;&nbsp; &nbsp;at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)  
&nbsp;&nbsp; &nbsp;at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)  
&nbsp;&nbsp; &nbsp;at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)  
&nbsp;&nbsp; &nbsp;at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)  
&nbsp;&nbsp; &nbsp;at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)  
&nbsp;&nbsp; &nbsp;at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)  
&nbsp;&nbsp; &nbsp;at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598)  
&nbsp;&nbsp; &nbsp;at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)  
&nbsp;&nbsp; &nbsp;at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)  
&nbsp;&nbsp; &nbsp;at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)  
&nbsp;&nbsp; &nbsp;at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)  
&nbsp;&nbsp; &nbsp;at java.lang.Thread.run(Unknown Source)

&nbsp;

&nbsp;

&nbsp;

Is there something im missing?

&nbsp;

Thank you!

---

<div class="post-metadata">

### Author: ![kurucsai.zoltan1988](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kurucsai.zoltan1988](https://community.ofelia.com/u/kurucsai.zoltan1988)
#### Post date: [18 June 2020 11:13 UTC](https://community.ofelia.com/t/how-can-i-log-into-bonita-engine-from-external-java-application-with-apiclient/10235/2 "2020-06-18T11:13:40Z")

</div>

I already modified the code a little:

&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parameters.put("server.url", "http://localhost:1664");  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parameters.put("application.name", "bonita");  
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, parameters);  
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();  
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (loginAPI == null) System.err.println("A login null");  
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else System.err.println("van login api");  
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//System.err.println(loginAPI.);  
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;APISession apiSession = loginAPI.login("walter.bates", "bpm");  
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;org.bonitasoft.engine.api.APIClient apiClient = new APIClient(apiSession);  
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.err.println(apiClient.getIdentityAPI().getNumberOfUsers());

&nbsp;

This works fine, however if i try another (working bonita) url I get this error:

java.lang.reflect.UndeclaredThrowableException

---

<div class="post-metadata">

### Author: ![romain.bioteau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/romain.bioteau/32/720_2.png) [@romain.bioteau](https://community.ofelia.com/u/romain.bioteau)
#### Post date: [19 June 2020 09:34 UTC](https://community.ofelia.com/t/how-can-i-log-into-bonita-engine-from-external-java-application-with-apiclient/10235/3 "2020-06-19T09:34:57Z")

</div>

Are the client and the server using the same Bonita version ?

---

<div class="post-metadata">

### Author: ![kurucsai.zoltan1988](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kurucsai.zoltan1988](https://community.ofelia.com/u/kurucsai.zoltan1988)
#### Post date: [19 June 2020 21:03 UTC](https://community.ofelia.com/t/how-can-i-log-into-bonita-engine-from-external-java-application-with-apiclient/10235/4 "2020-06-19T21:03:42Z")

</div>

To be honest i didnt check the code that uses the API (my coworker wrote it) , but the installed bonita with the studio, that i can access&nbsp;with localhost has the same version as the one on the server.

In localhost i can access the APIs with the code, but if it is on a remote server, then i get the exception.&nbsp;

We are using version 7.9

&nbsp;

---

<div class="post-metadata">

### Author: ![romain.bioteau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/romain.bioteau/32/720_2.png) [@romain.bioteau](https://community.ofelia.com/u/romain.bioteau)
#### Post date: [20 June 2020 07:38 UTC](https://community.ofelia.com/t/how-can-i-log-into-bonita-engine-from-external-java-application-with-apiclient/10235/5 "2020-06-20T07:38:41Z")

</div>

Does the remote server has enabled the[HTTP servlet](https://documentation.bonitasoft.com/bonita/7.10/configure-client-of-bonita-bpm-engine#toc4) to use the Java API in HTTP ?

---

<div class="post-metadata">

### Author: ![kurucsai.zoltan1988](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kurucsai.zoltan1988](https://community.ofelia.com/u/kurucsai.zoltan1988)
#### Post date: [25 June 2020 05:51 UTC](https://community.ofelia.com/t/how-can-i-log-into-bonita-engine-from-external-java-application-with-apiclient/10235/6 "2020-06-25T05:51:22Z")

</div>

Well, if i remember correctly 2-3 days ago we tried to enable it, this was commented in web.xml in the bonita folder of the servers webapps:

\<servlet\>  
&nbsp; &nbsp; &nbsp; &nbsp; \<servlet-name\>HttpAPIServlet\</servlet-name\>  
&nbsp; &nbsp; &nbsp; &nbsp; \<servlet-class\>org.bonitasoft.engine.api.internal.servlet.HttpAPIServlet\</servlet-class\>  
\</servlet\>

&nbsp;

Now it is not but still get the error.

It is not that urgent, because we used a different aproach but it would be nice if this could work.
