Bonita Client.jar提供的rest 访问方法

Bonita studio提供导出bonita-server-rest.war 的方法,然后你的客户端程序完全可以通过rest来访问bonita服务器提供的引擎服务

具体方法如下

 

 

1. 读取参数 ,设置启动时读取参数文件

 

     1>web.xml的设置

             <servlet>
              <servlet-name>InitBonitaClientUtil</servlet-name>
              <servlet-class>com.company.bonita.admin.web.InitBonitaClientUtil</servlet-class>
            <load-on-startup>3</load-on-startup>
        </servlet>

   2> InitBonitaClientUtil.java

       
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ow2.bonita.util.BonitaConstants;

import com.sanminasci.bonita.admin.common.InitData;

/**
 * Servlet implementation class InitBonitaClientUtil
 */
public class InitBonitaClientUtil extends HttpServlet {
    private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InitBonitaClientUtil() {
        super();
    }

   
    /**
     * Initial context in using spring's IoC container.
     * @throws ServletException - ServletException.
     */
    public void init() throws ServletException {
        super.init();       
        initBonitaClientRestParameter();
    }
   
    private void initBonitaClientRestParameter(){
         String ip = "";
         String port = "";
         String jasstomcat = "jaas-tomcat.cfg";
         String bonitaInfo = "bonitaInfo.properties";
         String dir = this.getServletConfig().getServletContext().getRealPath("/")+"WEB-INF/";
         String jasstomcatPath = dir+ jasstomcat ;
         String bonitaInfoPath = dir +  bonitaInfo ;
         
         Properties pros = new Properties();
         try {
            pros.load( new FileInputStream( new File ( bonitaInfoPath )));
        } catch (Exception e) {
            e.printStackTrace();
        }
         ip= pros.getProperty("hostname");
         port= pros.getProperty("hostport");
         
         System.setProperty(BonitaConstants.API_TYPE_PROPERTY, "REST");
         System.setProperty(BonitaConstants.JAAS_PROPERTY, jasstomcatPath );
         System.setProperty(BonitaConstants.REST_SERVER_ADDRESS_PROPERTY, "http://"+ip+":"+port+"/bonita-server-rest/");
         
         InitData.setJaasProperty(jasstomcatPath);
         InitData.setRestServerAddressProperty("http://"+ip+":"+port+"/bonita-server-rest/");

    }
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

}

 

   3>WEB-INF/bonitaInfo.properties

        hostname=172.25.165.66
         hostport=8080

    4>WEB-INF/jaas-tomcat.cfg

        /**
* Performs the authentication of the users using the authentication
* service configured in Bonita environment configuration file
*/
BonitaAuth {
  org.ow2.bonita.identity.auth.BonitaIdentityLoginModule required;
};

/**
* Used to retrieve the credentials of the user and save them in the
* context shared between the LoginModules stacked in the LoginContext
*/
BonitaStore {
  org.ow2.bonita.identity.auth.BonitaRESTLoginModule required restUser="restuser" restPassword="restbpm";
};

/**
 * Used by the REST server
 */
BonitaRESTServer {
  org.ow2.bonita.identity.auth.BonitaRESTServerLoginModule required logins="restuser" passwords="restbpm" roles="restuser";
};

5>InitData.java

public class InitData {
    public static String restServerAddressProperty;
    public static String jaasProperty ;
 
    public static String getRestServerAddressProperty() {
        return restServerAddressProperty;
    }
    public static void setRestServerAddressProperty(String restServerAddressProperty) {
        InitData.restServerAddressProperty = restServerAddressProperty;
    }
    public static String getJaasProperty() {
        return jaasProperty;
    }
    public static void setJaasProperty(String jaasProperty) {
        InitData.jaasProperty = jaasProperty;
    }
   
    public static void demo2(){
        System.setProperty(org.ow2.bonita.util.BonitaConstants.API_TYPE_PROPERTY, "REST");
        System.setProperty(org.ow2.bonita.util.BonitaConstants.JAAS_PROPERTY, com.sanminasci.bonita.admin.common.InitData.getJaasProperty() );
        System.setProperty(org.ow2.bonita.util.BonitaConstants.REST_SERVER_ADDRESS_PROPERTY, com.sanminasci.bonita.admin.common.InitData.getRestServerAddressProperty());
        try {
            javax.security.auth.login.LoginContext loginContext = new javax.security.auth.login.LoginContext("BonitaStore", new org.ow2.bonita.util.SimpleCallbackHandler("", ""));
            loginContext.login();
            java.util.List<org.ow2.bonita.facade.identity.User> users2 = org.ow2.bonita.util.AccessorUtil.getIdentityAPI().getAllUsers();
            for(int i=0;i<users2.size();i++){
                System.out.println(users2.get(i).getUsername());
            }
            loginContext.logout();   
        } catch (LoginException e) {
            e.printStackTrace();
        }
    }

}

你可能感兴趣的:(String,properties,REST,Authentication,credentials,passwords)