Hello,
I tried with this example to create and deploy process from my java client using API Rest
package tn.simac.common.utils.bonita5;/**
- Copyright (C) 2011 BonitaSoft S.A.
- BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
- This library is free software; you can redistribute it and/or modify it under the terms
- of the GNU Lesser General Public License as published by the Free Software Foundation
- version 2.1 of the License.
- This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with this
- program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- Floor, Boston, MA 02110-1301, USA.
**/
import java.util.Collection;
import javax.security.auth.login.LoginContext;
import org.ow2.bonita.facade.ManagementAPI;
import org.ow2.bonita.facade.QueryRuntimeAPI;
import org.ow2.bonita.facade.RuntimeAPI;
import org.ow2.bonita.facade.def.majorElement.ProcessDefinition;
import org.ow2.bonita.facade.runtime.ActivityState;
import org.ow2.bonita.facade.runtime.InstanceState;
import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID;
import org.ow2.bonita.facade.uuid.ProcessInstanceUUID;
import org.ow2.bonita.light.LightTaskInstance;
import org.ow2.bonita.util.AccessorUtil;
import org.ow2.bonita.util.BonitaConstants;
import org.ow2.bonita.util.BusinessArchiveFactory;
import org.ow2.bonita.util.ProcessBuilder;
import org.ow2.bonita.util.SimpleCallbackHandler;
/**
- @author Elias Ricken de Medeiros
*/
public class Client {
private static final String LOGIN = “john”;
private static final String PSSWD = “bpm”;
private static final String jaasFile = “D:\wf\jaas-standard.cfg”;
public static void main(String args) throws Exception {
//set system properties
System.setProperty(BonitaConstants.API_TYPE_PROPERTY, "REST");
System.setProperty(BonitaConstants.REST_SERVER_ADDRESS_PROPERTY, "http://localhost:8080/bonita-server-rest/");
System.setProperty(BonitaConstants.JAAS_PROPERTY, jaasFile);
//login
//verify the user exists
LoginContext loginContext = new LoginContext("BonitaAuth",
new SimpleCallbackHandler(LOGIN, PSSWD));
loginContext.login();
loginContext.logout();
//propagate the user credentials
loginContext = new LoginContext("BonitaStore",
new SimpleCallbackHandler(LOGIN, PSSWD));
loginContext.login();
//get he APIs
final ManagementAPI managementAPI = AccessorUtil.getManagementAPI();
final RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI();
final QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();
try {
//create a simple process with process builder:
// - one step with LOGIN as actor
// - a Global data of String Type
ProcessDefinition process = ProcessBuilder.createProcess("myProcess", "1.0")
.addStringData("globalVar", "defaultValue")
.addHuman(LOGIN)
.addHumanTask("step1", LOGIN)
.done();
//deploy process
process = managementAPI.deploy(BusinessArchiveFactory.getBusinessArchive(process));
System.out.println("----------------\nProcess deployed\n----------------");
final ProcessDefinitionUUID processUUID = process.getUUID();
//instantiate process
ProcessInstanceUUID instanceUUID = runtimeAPI.instantiateProcess(processUUID);
System.out.println("----------------\nNew process instance Created\n----------------");
final Collection<LightTaskInstance> taskList = queryRuntimeAPI.getLightTaskList(instanceUUID, ActivityState.READY);
if (taskList.size() != 1) {
throw new Exception("Incorrect list size. Actual size: " + taskList.size());
}
//execute task
final LightTaskInstance taskInstance = taskList.iterator().next();
runtimeAPI.executeTask(taskInstance.getUUID(), true);
System.out.println("----------------\nTask executed\n----------------");
final InstanceState state = queryRuntimeAPI.getProcessInstance(instanceUUID).getInstanceState();
if(!state.equals(InstanceState.FINISHED)){
throw new Exception("Incorrect state. Actual state: " + state);
}
System.out.println("----------------\nApplication executed sucessfully\n----------------");
} finally {
//delete all deployed processes
managementAPI.deleteAllProcesses();
loginContext.logout();
}
}
}
But I got this error
Exception breakpoint: Client.java:111, org.jboss.resteasy.client.ClientResponseFailure, Error status 401 Unauthorized returned
Exception in thread "main" org.jboss.resteasy.client.ClientResponseFailure: Error status 401 Unauthorized returned
When I use the debugger, this error occures when I arrive to deploy the process created
process = managementAPI.deploy(BusinessArchiveFactory.getBusinessArchive(process));Is that means, that the problem is with REST API authentification or Bonita ?