AAS 7.0下一个Error content type错误的处理
来源:互联网 发布:java classloader使用 编辑:程序博客网 时间:2024/06/07 02:05
近日,合作伙伴在使用AAS 7.0的时候,碰到一个后台抛异常,前端没问题的现象:一点击应用中的“导出Excel”,后台即抛出如下异常:
2011-12-07 09:55:06 错误 [apusic.web.response] Error content type: application/x-msdownload;java.lang.StringIndexOutOfBoundsException: String index out of range: 1at java.lang.String.charAt(String.java:558)at com.apusic.web.http.ParameterList.parse(Unknown Source)at com.apusic.web.http.ParameterList.<init>(Unknown Source)at com.apusic.web.http.ContentType.parse(Unknown Source)at com.apusic.web.http.HttpProtocol.setResponseType(Unknown Source)at com.apusic.web.container.Response.setContentType(Unknown Source)at com.neusoft.framework.util.ExcelUtil.outputAll(ExcelUtil.java:128)at com.neusoft.common.action.PubAttachmentAction.exportData(PubAttachmentAction.java:1454)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:585)at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:196)at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)at com.apusic.web.container.ServletComponent.service(Unknown Source)at com.apusic.web.container.ServletFilterWrapper.doFilter(Unknown Source)at com.apusic.web.container.FilterChainImpl.doFilter(Unknown Source)at com.neusoft.framework.plugin.EncodeFilter.doFilter(EncodeFilter.java:114)at com.apusic.web.container.FilterComponent.doFilter(Unknown Source)at com.apusic.web.container.FilterChainImpl.performFilter(Unknown Source)at com.apusic.web.container.WebContainer.invoke(Unknown Source)at com.apusic.web.container.WebContainer.processRequest(Unknown Source)at com.apusic.web.http.VirtualHost.processRequest(Unknown Source)at com.apusic.web.http.HttpServer.processRequest(Unknown Source)at com.apusic.web.http.HttpConnectionHandler.service(Unknown Source)at com.apusic.web.http.ConnectionHandler.processRequest(Unknown Source)at com.apusic.web.http.ConnectionHandler.processConnection(Unknown Source)at com.apusic.web.http.ConnectionHandler.run(Unknown Source)at com.apusic.util.ThreadPoolImpl$WorkerThread.run(Unknown Source)但是,前端使用IE浏览器打开、下载均没有问题。
从错误的字面意思来看,貌似是ConteneType不正确,但是“application/x-msdownload”这种MIME type确实存在着。只不过从W3C提供的参考资料来看,application/x-msdownload貌似应该是dll文件的MIME type,不知是不是合作伙伴在处理Excel导出的时候的笔误?由于相关研发人员不在现场,此问题不变追究。
以下是发生异常部分的应用源码片段:
response.setHeader("content-disposition","attachment;filename="+java.net.URLEncoder.encode(fileName, "UTF-8") + ".xls");response.setContentType("application/x-msdownload;");response.setCharacterEncoding("GBK");os = response.getOutputStream();os.write((getHeaderStr()+getBodyStrAll(doc)+getTailStr()).getBytes("GBK"));依稀想起AAS的web.xml文件中,有默认支持的MIME type列表配置信息,也许是默认支持的列表中不存在application/x-msdownload这种类型,而AAS对此又有一些严格的验证处理机制(虽然MIME type主要是告诉浏览器需要使用哪种程序来打开指定扩展名的文件),最终导致在解析此Content Type时,无法找到匹配资源,从而抛出异常。
找到%AAS_DOMAIN_HOME%\config\web.xml文件,搜索文件中指定的默认MIME列表,发现其中确实没有application/x-msdownload这种类型,于是在此文件中加入相应的内容,重启AAS,OK!一切正常!
总结
- AAS对于运行于其中的应用有非常严格的验证机制,比如:曾经碰到一个在配置文件中设置了某个class,但是实际上应用中此class却不存在的情况,AAS会在启动时抛出相应的class不存在的错误提示,当然,这样严格的验证机制,最终目的是为了防止由于不必要的笔误等原因造成的内存泄漏等其他错误。虽然有的伙伴不承认,但是tomcat在这方面做的确实非常欠缺。
- AAS默认的MIME type是可以根据实际需要进行扩展的。
- 必要的时候,查看应用的源码,对于解决问题是非常必要的。
- AAS 7.0下一个Error content type错误的处理
- error C2011: 'fd_set' : 'struct' type redefinition的错误处理
- content-type引发的CDN错误
- IE处理content-type的方式(片段)
- 各浏览器对常用或者错误的 Content-Type 类型处理方式不一致
- javax.mail 处理邮件时由于content-type内容不合标准引起的错误
- Content-type 的说明
- Content-type 的说明
- 各类的Content-type
- Content-type 的说明
- Content-Type的类型
- MIME的content-type
- content-type的作用
- 常见的content-type
- content-type的几种取值
- Content-Type的类型
- SQL Redist content: Command line option syntax error. Type Command /? for Help. 错误!!!
- Content-Encoding与Content-Type的区别
- 农民打工供儿上大学 儿子毕业后工资不如自己
- Linux文本处理常用命令
- Yii框架开发安全考虑
- 安装CentOs,并用SecureCRT来登录本地的CentOs
- PC机串口通信的工作原理
- AAS 7.0下一个Error content type错误的处理
- 如何学习编程
- 关于使用hunt进行会话劫持的实践
- oracle instance 迁移 (window - linux)
- 两个有趣的面试题
- x264编解码
- spring security验证流程
- 使用CAction类的事件
- oracle11G新特性 --审计