【发布时间】:2014-07-01 01:10:05
【问题描述】:
我找到了问题,在下面回答:
原问题: 菜鸟程序员在这里。 我正在开发一个 openfire 服务器项目,我们的团队正在尝试集成一个苹果推送通知服务插件。但是,我发现的插件代码有问题,jsp页面永远无法显示在openfire的管理控制台中。
经过数小时的手动调试(因为我完全烂透了,对 apache 的文件上传模块一无所知),我发现问题出在这行之间:
List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
如果我禁用整个 try 子句,页面会正常显示。当然,这意味着这个jsp页面将失去保存上传文件的能力。在又无数个小时的搜索这条线之后,我什么也没发现,所以我决定在这里问它并尝试一下。
我不太明白这一行出了什么问题,eclipse 给了我Type safety: The expression of type List needs unchecked conversion to conform to List<FileItem> 的警告,但是插件编译和构建都很好。语法对我来说也很合适(谷歌搜索了一段时间,看到人们也使用相同的语法)。 Openfire 在调试方面毫无用处,error.log 或 debug.log 中没有记录任何有价值的信息。
如果有帮助,这里是整个 jsp 文件。提前致谢。
apns.jsp:
<%@ page import="java.io.File,
java.util.List,
org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.util.*,
com.wecapslabs.openfire.plugin.apns.ApnsPlugin,
org.apache.commons.fileupload.FileItem,
org.apache.commons.fileupload.disk.DiskFileItemFactory,
org.apache.commons.fileupload.servlet.ServletFileUpload,
org.apache.commons.fileupload.FileUploadException"
errorPage="error.jsp"
%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%-- Define Administration Bean --%>
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager" />
<c:set var="admin" value="${admin.manager}" />
<% admin.init(request, response, session, application, out ); %>
<% // Get parameters
boolean save = request.getParameter("save") != null;
boolean success = request.getParameter("success") != null;
boolean error = request.getParameter("error") != null;
String password = ParamUtils.getParameter(request, "password");
String badge = ParamUtils.getParameter(request, "badge");
String sound = ParamUtils.getParameter(request, "sound");
String production = ParamUtils.getParameter(request, "production");
ApnsPlugin plugin = (ApnsPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("apns");
// Handle a save
if (save) {
plugin.setPassword(password);
plugin.setBadge(badge);
plugin.setSound(sound);
plugin.setProduction(production);
try {
List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : multiparts) {
if (!item.isFormField()) {
String filename = item.getName();
item.write(new File(ApnsPlugin.keystorePath()));
}
}
response.sendRedirect("apns.jsp?success=true");
return;
} catch (Exception e) {
response.sendRedirect("apns.jsp?error=true");
return;
}
}
password = plugin.getPassword();
badge = Integer.toString(plugin.getBadge());
sound = plugin.getSound();
production = plugin.getProduction() ? "true" : "false";
%>
<html>
<head>
<title>APNS Settings Properties</title>
<meta name="pageID" content="apns-settings"/>
</head>
<body>
<% if (success) { %>
<div class="jive-success">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0"></td>
<td class="jive-icon-label">
APNS certificate updated successfully.
</td></tr>
</tbody>
</table>
</div><br>
<% } %>
<form action="apns.jsp?save" method="post" enctype="multipart/form-data">
<div class="jive-contentBoxHeader">APNS certificate</div>
<div class="jive-contentBox">
<label for="file">p12 certificate:</label>
<input type="file" name="file" />
<br>
<label for="password">certificate password:</label>
<input type="password" name="password" value="<%= password %>" />
<br>
<label for="badge">payload badge</label>
<input type="badge" name="badge" value="<%= badge %>" />
<br>
<label for="sound">payload sound</label>
<input type="badge" name="sound" value="<%= sound %>" />
<br>
<label for="production">sandbox or production</label>
<input type="radio" name="production" value="false" <%= production.equals("true") ? "" : "checked" %>>Sandbox
<input type="radio" name="production" value="true" <%= production.equals("true") ? "checked" : "" %>>Production
</div>
<input type="submit" value="Save">
</form>
</body>
</html>
【问题讨论】:
标签: jsp openfire apache-commons-fileupload