Docker - Unable to contact EngineAPI



I'm trying to create multiple docker container with a docker-compose.
I have 3 containers:
- bonita
- postgres
- webapps

In my webapp i have one application that's use EngineAPI to do some actions, like launch a process.
When i'm tryin to connect to bonitaEngine, i've got this error:

        at com.sun.proxy.$Proxy395.login(Unknown Source)
Caused by: org.apache.http.client.HttpResponseException:
        at org.bonitasoft.engine.api.HTTPServerAPI.invokeMethod(
        at org.bonitasoft.engine.api.impl.ClientInterceptor.invoke(
        at com.sun.proxy.$Proxy395.login(Unknown Source)

That's caused because i've got a **404 **response from the method:

public APISession loginWithDefaultUser() throws LoginException {
        logger.debug("-- Login a bonita...");
        Map<String, String> settings = new HashMap<String, String>();
        settings.put("server.url", serveurUrl);
        settings.put("", appName);

        logger.debug("Connexion : "+serveurUrl+" - "+appName+" - "+user);
        APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, settings);
        // get the LoginAPI using the TenantAPIAccessor
        LoginAPI loginAPI;
        try {
            loginAPI = TenantAPIAccessor.getLoginAPI();
            // log in to the tenant to create a session
            **APISession apiSession = loginAPI.login(user, password);//<== This method**
            logger.debug("-- Login to bonita OK");
            return apiSession;
        } catch (BonitaHomeNotSetException | ServerAPIException | UnknownAPITypeException | LoginException ex) {
            logger.error("Unable to connect to bonita", ex);
            throw new LoginException(ex);
        }catch(Exception exception){
            logger.error("Unexpected error occurred", exception);
            throw new LoginException(exception);

My url is: http://cbonita:8080 (cbonita is my container's name)
my user = tech_user
my psw = secret

Furthermore I have try to use curl to the RestAPI from my webbapp like that:

curl -c cookie.txt -s -o /dev/null -d 'username=tech_user&password=secret&redirect=false' -w ''%{http_code}'' http://cbonita:8080/bonita/loginservice

That curl works perfectly. So, i don't know why my EngineAPI call doesn't work.

Someone have an issue about that? ^^


1 answer

This one is the BEST answer!


If you use the official image as described in the documentation in security section, the default behavior is to deactivate HTTP_API. For specific needs you can override this behavior by setting HTTP_API to true :

docker run  -e HTTP_API=true  --name bonita -d -p 8080:8080 bonita


Submitted by bastien.laurent... on Fri, 07/12/2019 - 15:53

I will test that soon, thanks

Submitted by bastien.laurent... on Fri, 07/12/2019 - 16:51

Thanks a lot ! It's working perfectly !