FileUpload.jsp revision e8721886dbfd32e88cc7077cbee4b6bb1b44b443
200N/A<%--
200N/A DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
200N/A
200N/A Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
200N/A
200N/A The contents of this file are subject to the terms
200N/A of the Common Development and Distribution License
200N/A (the License). You may not use this file except in
200N/A compliance with the License.
200N/A
200N/A You can obtain a copy of the License at
200N/A https://opensso.dev.java.net/public/CDDLv1.0.html or
200N/A opensso/legal/CDDLv1.0.txt
200N/A See the License for the specific language governing
200N/A permission and limitations under the License.
200N/A
200N/A When distributing Covered Code, include this CDDL
200N/A Header Notice in each file and include the License file
200N/A at opensso/legal/CDDLv1.0.txt.
200N/A If applicable, add the following below the CDDL Header,
200N/A with the fields enclosed by brackets [] replaced by
200N/A your own identifying information:
200N/A "Portions Copyrighted [year] [name of copyright owner]"
200N/A
200N/A $Id: FileUpload.jsp,v 1.4 2009/08/07 23:39:08 asyhuang Exp $
200N/A
200N/A--%>
200N/A<%--
200N/A Portions Copyrighted 2012 ForgeRock Inc
200N/A Portions Copyrighted 2012 Open Source Solution Technology Corporation
200N/A--%>
200N/A
200N/A<%@page import="com.iplanet.sso.SSOException"%>
200N/A<%@page import="com.iplanet.sso.SSOToken"%>
200N/A<%@page import="com.iplanet.sso.SSOTokenManager"%>
200N/A<%@page import="java.io.*" %>
200N/A<%@page import="java.net.*" %>
200N/A<%@page import="java.util.*" %>
200N/A
200N/A<%
200N/A request.setCharacterEncoding("UTF-8");
200N/A response.setContentType("text/html; charset=UTF-8");
200N/A Locale resLocale = request.getLocale();
200N/A if (resLocale == null) {
200N/A resLocale = Locale.US;
200N/A }
200N/A try {
200N/A SSOTokenManager manager = SSOTokenManager.getInstance();
200N/A SSOToken ssoToken = manager.createSSOToken(request);
200N/A
200N/A if (!manager.isValidToken(ssoToken)) {
200N/A return;
200N/A }
200N/A } catch (SSOException ssoe) {
200N/A String redirectUrl = request.getScheme() + "://" +
200N/A request.getServerName() + ":" +
200N/A request.getServerPort() +
200N/A request.getContextPath();
response.sendRedirect(redirectUrl);
return;
}
InputStream is = null;
BufferedReader bos = null;
try {
boolean limitExceeded = false;
StringBuffer buff = new StringBuffer();
is = request.getInputStream();
bos = new BufferedReader(new InputStreamReader(is));
String line = bos.readLine();
while (line != null) {
buff.append(line).append("\n");
line = bos.readLine();
if (buff.length() > (1024 * 50)) {
limitExceeded = true;
break;
}
}
if (limitExceeded) {
ResourceBundle rb = null;
String RB_NAME = "workflowMessages";
com.sun.identity.shared.debug.Debug debug =
com.sun.identity.shared.debug.Debug.getInstance("workflowMessages");
rb = ResourceBundle.getBundle(RB_NAME, resLocale);
String data = com.sun.identity.shared.locale.Locale.getString(
rb, "file.upload.size.limit.exceeded", debug);
out.println("<div id=\"data\">" + "Error: " + data + "</div>");
} else {
// Parses a content-type String for the boundary.
String contentType = request.getContentType();
if (contentType == null) {
contentType = request.getHeader("Content-Type");
}
String boundary = "";
if (contentType != null && contentType.lastIndexOf("boundary=") != -1) {
boundary = contentType.substring(contentType.lastIndexOf("boundary=") + 9);
if (boundary.endsWith("\n")) {
boundary = boundary.substring(0, boundary.length()-1);
}
}
String data = buff.toString();
int idx = data.indexOf("filename=\"");
idx = data.indexOf("\n\n", idx);
data = data.substring(idx + 2);
idx = data.lastIndexOf("\n--" + boundary);
data = data.substring(0, idx);
data = data.replace("<", "&lt;");
data = data.replace(">", "&gt;");
out.println("<div id=\"data\">" + data + "</div>");
}
} catch (IOException e) {
} finally {
try {
if (bos != null) {
bos.close();
}
} catch (IOException e) {
//ignore
}
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
//ignore
}
}
%>