`
jinli_dong
  • 浏览: 22327 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

转:JBPM4常用错误汇总

    博客分类:
  • jbpm
阅读更多
1.在tomcat6.0下布署错误
   基于JBPM4的web项目jsp页面发布出错
现象:
   javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/OnDuty/wfmanage_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature
       org.apache.jasper.servlet.JspServlet.service(JspServlet.java:275)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
。。。

原因:
   项目中WEB-INF\lib中的三个jar包(juel.jar, juel-engine.jar, juel-impl.jar)和tomcat6下lib中jar包(el-api.jar)冲突

解决方法:
   方法一:换成tomcat5.5 一点问题也没有了
   方法二:将juel.jar, juel-engine.jar, juel-impl.jar这三个包复制到tomcat6下lib中,并删除原来的el-api.jar,切记要把WEB-INF\lib中的juel.jar, juel-engine.jar, juel-impl.jar删除。不然还是要冲突。

2.无法保存(布署)含有中文的流程定义文件
现象:
保存流程定义文件
   <?xml version="1.0" encoding="GBK"?>
   <process name="leave" xmlns="http://jbpm.org/4.0/jpdl">
      <start g="201,14,48,48" name="开始">
         <transition g="-42,-10" name="请假" to="填写请假单"/>
      </start>
      ...
提示错误:
   MalformedByteSequenceException:Invalid byte 1 of 1-byte UTF-8 sequence

原因:
   XML字符串大概经过了下面一些方法才被解析为DOM:
org.jbpm.pvm.internal.repository.DeploymentImpl:
  public NewDeployment addResourceFromString(String resourceName, String text) { 
      addResourceFromStreamInput(resourceName, new StringStreamInput(text)); 
      return this; 
  } 
public NewDeployment addResourceFromString(String resourceName, String text) {
  addResourceFromStreamInput(resourceName, new StringStreamInput(text));
  return this;
}

org.jbpm.pvm.internal.stream.StringStreamInput:
   public class StringStreamInput extends StreamInput { 
      String string; 
      public StringStreamInput(String string) { 
        this.name = "string"; 
        this.string = string; 
      } 
     public InputStream openStream() { 
       byte[] bytes = string.getBytes(); 
       return new ByteArrayInputStream(bytes); 
     } 
   } 
public class StringStreamInput extends StreamInput {
  String string;
  public StringStreamInput(String string) {
    this.name = "string";
    this.string = string;
  }
  public InputStream openStream() {
    byte[] bytes = string.getBytes();
    return new ByteArrayInputStream(bytes);
  }
}

org.jbpm.pvm.internal.xml.Parse:
    protected InputSource getInputSource() { 
      if (inputSource!=null) { 
        return inputSource; 
      } 
      if (streamInput!=null) { 
        inputStream = streamInput.openStream(); 
        return new InputSource(inputStream); 
      } 
     addProblem("no source specified to parse"); 
     return null; 
   } 
protected InputSource getInputSource() {
  if (inputSource!=null) {
    return inputSource;
  }
  if (streamInput!=null) {
    inputStream = streamInput.openStream();
    return new InputSource(inputStream);
  }
  addProblem("no source specified to parse");
  return null;
}

org.jbpm.pvm.internal.xml.Parser:
    protected Document buildDom(Parse parse) { 
      Document document = null; 
      try { 
        SAXParser saxParser = saxParserFactory.newSAXParser(); 
        XMLReader xmlReader = saxParser.getXMLReader(); 
        // ... 
         
       InputSource inputSource = parse.getInputSource();  
       xmlReader.parse(inputSource); 
    
     } catch (Exception e) { 
       parse.addProblem("couldn't parse xml document", e); 
     } 
    
     return document; 
   } 
   经过层层包装、拆包、再包装再拆包,可怜的字符串终于来到SAX解析器的手上。问题是jBPM在中间调用了String.getBytes():这个方法会把Java字符串(Unicode)转换为系统默认编码并返回对应的byte[],但当InputSource中没有设置编码信息时,SAXParser默认是以UTF-8编码来读取输入流的。我的开发机的系统默认编码是GBK,于是就出问题了。

解决方法:
   String xmlStr = "<?xml version=\"1.0\" encoding=\"" + System.getProperty("file.encoding") + "\"?><test name=\"名称\"></test>";
   这里就用System.getProperty("file.encoding")去获取系统默认编码,以便于String.getBytes()匹配。
   如果你能确保你的WEB服务器上运行的字符集是GBK,也可以写成
<?xml version="1.0" encoding="GBK"?>
<process name="leave" xmlns="http://jbpm.org/4.0/jpdl">
   <start g="201,14,48,48" name="开始">
      <transition g="-42,-10" name="请假" to="填写请假单"/>
   </start>
   ...

3.无法保存(布署)含有中文的流程定义文件
现象:
   流程定义已经成功保存到数据库中,但无法执行,
   数据库表jbpm4_execution中的任务名称为乱码

原因:
   数据库中任务名称为乱码的根本原因不是hiberate保存到jbpm4_lob中的字段BLOB_VALUE造成的。而是JSP页面传递给servlet流程定义文本时,中文转码错误造成的。即servlet接收的即乱码。

解决方法
  1)JSP页面中显示中文乱码
     在JSP文件中使用page命令指定响应结果的MIME类型,如<%@ page language="java" contentType="text/html;charset=gbk" %>
  2)表单提交乱码  
    表单提交时(post和Get方法),使用request.getParameter方法得到乱码,这是因为tomcat处理提交的参数时默认的是iso-8859-1,表单提交get和post处理乱码问题不同,下面分别说明。
    (1)POST处理
    对post提交的表单通过编写一个过滤器的方法来解决,过滤器在用户提交的数据被处理之前被调用,可以在这里改变参数的编码方式,过滤器的代码如下:
Java代码
package example.util;
   
    import java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
   
    public class SetCharacterEncodingFilter implements Filter {
       protected String encoding = null;
       protected FilterConfig filterConfig = null;
       protected boolean ignore = true;
   
     public void destroy() {
      this.encoding = null;
      this.filterConfig = null;
     }
   
     public void doFilter(ServletRequest request, ServletResponse response,
       FilterChain chain) throws IOException, ServletException {
          if (ignore || (request.getCharacterEncoding() == null)) {
       String encoding = selectEncoding(request);
       if (encoding != null) {
        request.setCharacterEncoding(encoding);
       }
      }
   
      // Pass control on to the next filter
      chain.doFilter(request, response);
   
     }
    public void init(FilterConfig filterConfig) throws ServletException {
   
      this.filterConfig = filterConfig;
      this.encoding = filterConfig.getInitParameter("encoding");
      String value = filterConfig.getInitParameter("ignore");
      if (value == null) {
       this.ignore = true;
      } else if (value.equalsIgnoreCase("true")) {
       this.ignore = true;
      } else if (value.equalsIgnoreCase("yes")) {
       this.ignore = true;
      } else {
       this.ignore = false;
      }
   
     }
   
     protected String selectEncoding(ServletRequest request) {
   
      return (this.encoding);
   
     }
   
    }

web.xml文件加入过滤器
<filter>
    <filter-name>Encoding</filter-name>
    <filter-class>
            example.util.SetCharacterEncodingFilter
     </filter-class>
    <init-param>
   <param-name>encoding</param-name>
   <param-value>gbk</param-value>
   <!--gbk或者gb2312或者utf-8-->
  </init-param>
  <init-param>
   <param-name>ignore</param-name>
   <param-value>true</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>Encoding</filter-name>
  <servlet-name>/*</servlet-name>
</filter-mapping>

(2) Get方法的处理
tomcat对post和get的处理方法不一样,所以过滤器不能解决get的乱码问题,它需要在其他地方设置。
打开<tomcat_home>\conf目录下server.xml文件,找到对8080端口进行服务的Connector组件的设置部分,给这个组件添加一个属性:URIEncoding="GBK"。修改后的Connector设置为:
 
<Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK" />
  * 注意修改后重新启动tomcat才能起作用。

4.运行出错时,数据库中的所有数据丢失
现象:
   运行出错后,数据库中的所有数据丢失,包括流程定义文件

原因:
   jbpm.hibernate.cfg.xml文件中有一个配置
   <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

   几个参数的意思,我解释一下:
   validate    加载hibernate时,验证创建数据库表结构
   create      每次加载hibernate,重新创建数据库表结构,这就是导致数据库表数据丢失的原因。
   create-drop 加载hibernate时创建,退出是删除表结构
   update      加载hibernate自动更新数据库结构
   none        不进行任何操作

   由于jbpm4的默认配置为create-drop,所以出现以上问题

解决方法:
   将jbpm.hibernate.cfg.xml文件中修改如下
   <property name="hibernate.hbm2ddl.auto" value="none"/>

5.在eclipse3.5流程设计器上设计流程时,中文出现乱码
现象:
   将流程设计好之后,点击保存,再查看代码,发现中文是乱码

原因:
   不清楚,应该是插件的bug

解决方法:
   将流程设计好之后,不要点保存,先将界面切换到代码窗口,这时可以看到中文,再点击保存

6.无法布署zip流程定义文件
现象:
   提示以下错误
   streams type cannot be used in batching
   2009-11-26 15:58:07 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
   严重: Could not synchronize database state with session
   org.hibernate.exception.GenericJDBCException: could not insert: [org.jbpm.pvm.internal.lob.Lob]

原因:
   当把数据值增加超过100时,hiberate就出现了这个异常--这意味着Oracle JDBC不允许流操作以批量方式执行

解决方法:
   在jbpm.hibernate.cfg.xml文件的<session-factory>下,添加
     <property name="hibernate.jdbc.batch_size">0</property>
   即可

7.无法布署zip流程定义文件
现象:
   提示错误
   Could not synchronize database state with session
   org.hibernate.exception.GenericJDBCException: could not insert: [org.jbpm.pvm.internal.lob.Lob]

原因:
   布署ZIP流程定义文件时hiberate无法插入blob
   用网络上提议的方法,添加以下配置
     <property name="hibernate.jdbc.batch_size">0</property>
     <property name="hibernate.jdbc.use_streams_for_binary">true</property>
   也不行

解决方法:
   采用以上方法,还是无法通过,最后重启操作系统,就解决了,奶奶的。

8.布署zip流程定义文件成功,但是数据库中中文为乱码
现象:
   <?xml version="1.0" encoding="GBK"?>
   <process name="leave" xmlns="http://jbpm.org/4.0/jpdl">
      <start g="201,14,48,48" name="开始">
         <transition g="-42,-10" name="请假" to="填写请假单"/>
      </start>
      ...
   由于我的oracle9数据库格式为GBK,所以XML文件头为<?xml version="1.0" encoding="GBK"?>
   含有中文的流程定义zip文件已经成功保存到了blob字段内,但是中文名为乱码
   或者提示XML parse error,无法保存到数据库

原因:
   repositoryService.createDeployment().addResourcesFromZipInputStream(new ZipInputStream(item.getInputStream())).deploy();
   仅上面一句话,就不知道转了多少次编码,经过测试发现,还是编码方式的问题,最后决定将jbpm4.2的源代码复制到项目中来调试。

解决方法:
   在网上发现了这篇文章《Java中压缩与解压--中文文件名乱码解决办法》
   结果问题还是没有解决
   最后经过测试,将org.jbpm.pvm.internal.repository.DeploymentImpl类中的方法进行修改
   public NewDeployment addResourcesFromZipInputStream(CnZipInputStream zipInputStream) {
        try {
          ZipEntry zipEntry = zipInputStream.getNextEntry();
          while(zipEntry!=null) {
            String entryName = zipEntry.getName();
            byte[] bytes = IoUtil.readBytes(zipInputStream);
           
            //如果是流程定义文件(不是图片),则重新编码,再生成字节数组
            if(entryName.endsWith(".xml")){
                String s=new String(bytes,"utf-8");
                bytes=s.getBytes();
            }
                
            if (bytes!=null) {
              addResourceFromStreamInput(entryName, new ByteArrayStreamInput(bytes));
            }
            zipEntry = zipInputStream.getNextEntry();
          }
        } catch (Exception e) {
          throw new JbpmException("couldn't read zip archive", e);
        }
        return this;
      }
   问题解决,肯定是开始有一步编码方式是用UTF-8,中间你就是再怎么用GBK转码,都不会成功,这里先用UTF-8编码生成字符串,再转一次编码就成功了。

参考文献
1.dzq2008. JBPM4项目和tomcat6.0的兼容问题. http://dzq0371.iteye.com/blog/509632
2.碰到jBPM的编码问题了. http://rednaxelafx.iteye.com/blog/522436
3.如何解决Tomcat下中文乱码问题. http://www.iteye.com/topic/251743?page=1
4.关于Hibernate一个配置参数hibernate.hbm2ddl.auto. http://linshiquan.iteye.com/blog/263170
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics