[ https://issues.apache.org/jira/browse/FILEUPLOAD-166?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jochen Wiedmann resolved FILEUPLOAD-166. ---------------------------------------- Resolution: Invalid Assignee: Jochen Wiedmann According to the stack trace, this is most likely an issue in your code and not in the fileupload library. Please use a users mailing list or something similar to resolve such issues. The Jira issue tracking system is for tracking problems in the libraries, not in the user code. > Outputting a file problems to the Server > ---------------------------------------- > > Key: FILEUPLOAD-166 > URL: https://issues.apache.org/jira/browse/FILEUPLOAD-166 > Project: Commons FileUpload > Issue Type: Task > Affects Versions: 1.2 > Environment: Windows XP > Reporter: Barry Barrios > Assignee: Jochen Wiedmann > Original Estimate: 1h > Remaining Estimate: 1h > > My code ran smoothly when it was just outputting just the input text file. > I made further changes such that my input text file gets process and make an > output file of the results. I use F5 to debug in Eclipse, and the problem > lied in the CVRP class on the server side. > ERROR FROM SERVER: > <H1>HTTP Status 500 - </H1> > <HR noShade SIZE=1> > <P><B>type</B> Exception report</P> > <P><B>message</B> <U></U></P> > <P><B>description</B> <U>The server encountered an internal error () that > prevented it from fulfilling this request.</U></P> > <P><B>exception</B> <PRE>java.lang.NumberFormatException: For input string: " > 1" > java.lang.NumberFormatException.forInputString(Unknown Source) > java.lang.Integer.parseInt(Unknown Source) > java.lang.Integer.parseInt(Unknown Source) > de.herbstcampus.server.CVRPOutputs.DistanceMatrix(CVRPOutputs.java:53) > de.herbstcampus.server.CVRPOutputs.<init>(CVRPOutputs.java:112) > > de.herbstcampus.server.FileUploadServlet.getStringOutput(FileUploadServlet.java:67) > de.herbstcampus.server.FileUploadServlet.doPost(FileUploadServlet.java:28) > javax.servlet.http.HttpServlet.service(HttpServlet.java:709) > javax.servlet.http.HttpServlet.service(HttpServlet.java:802) > com.google.gwt.dev.shell.GWTShellServlet.service(GWTShellServlet.java:290) > javax.servlet.http.HttpServlet.service(HttpServlet.java:802) > </PRE> > <P></P> > <P><B>note</B> <U>The full stack trace of the root cause is available in the > Apache Tomcat/5.0.28 logs.</U></P> > <HR noShade SIZE=1> > <H3>Apache Tomcat/5.0.28</H3> > Fragment where error lied: > public ArrayList<Waypoint[]> DistanceMatrix(String DM) { > lines= DM.split("\n"); > for(int i=0; i<lines.length;i++) > { > if(lines[i].length()>1) > { > //Using F5 parts was read perfectly > parts = lines[i].split(","); > //NodeId was changed correctly to 1 as the uploaded file > was read correctly > NodeId = Integer.parseInt(parts[0]); > //Major problems: When Debugging I get > ErrorReportValue.invoke(Request, ValveCOntext) > CustomerId = Integer.parseInt(parts[1]); > Name = parts[2]; > Address = parts[3]; > Postal_Code = parts[4]; > x_coord = Double.parseDouble(parts[5]); > y_coord = Double.parseDouble(parts[6]); > Demand = Double.parseDouble(parts[7]); > Node aNode = new > Node(NodeId,CustomerId,Name,Address,Postal_Code, x_coord, y_coord, Demand); > nodesList.add(aNode); > > } > } > ------------------------------- > package de.herbstcampus.server; > import java.io.IOException; > import java.util.List; > import javax.servlet.ServletException; > import javax.servlet.http.HttpServlet; > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > import org.apache.commons.fileupload.FileItem; > import org.apache.commons.fileupload.FileItemFactory; > import org.apache.commons.fileupload.FileUploadException; > import org.apache.commons.fileupload.disk.DiskFileItemFactory; > import org.apache.commons.fileupload.servlet.ServletFileUpload; > public class FileUploadServlet extends HttpServlet { > private static final long serialVersionUID = 1156467149259077140L; > protected void doPost(HttpServletRequest request, > HttpServletResponse response) throws ServletException, > IOException { > > > FileItem uploadItem = getFileItem(request); > String output = getStringOutput(new String(uploadItem.get())); > /* > * Note this must be 'text/html', otherwise the > onSubmitComplete(...) > * won't work properly and the browser may open a save dialog. > */ > response.setContentType("text/html"); > > if (uploadItem == null) { > response.getWriter().write("No data"); > return; > } else { > response.getOutputStream().println(output); > } > } > @SuppressWarnings("unchecked") > private FileItem getFileItem(HttpServletRequest request) { > FileItemFactory factory = new DiskFileItemFactory(); > ServletFileUpload upload = new ServletFileUpload(factory); > try { > List<FileItem> items = upload.parseRequest(request); > > for (FileItem item: items) { > if (!item.isFormField() > && > "uploadFormElement".equals(item.getFieldName())) { > return item; > } > } > } catch (FileUploadException e) { > return null; > } > > return null; > } > private String getStringOutput(String input){ > String outputFileName="output.txt"; > CVRPOutputs outputs; // this object manages the outputs file > outputs = new CVRPOutputs(outputFileName,input); > outputs.printOutputFile(); > return outputFileName; > > } > } > -------------------------------------- > //THIS IS THE CODE WHERE THE ERROR OF the SErVER STARTS TO HAPPEN > package de.herbstcampus.server; > import java.io.IOException; > import java.io.PrintWriter; > import java.util.ArrayList; > import com.google.gwt.core.client.GWT; > import com.google.gwt.maps.client.MapWidget; > import com.google.gwt.maps.client.geocode.DirectionQueryOptions; > import com.google.gwt.maps.client.geocode.DirectionResults; > import com.google.gwt.maps.client.geocode.Directions; > import com.google.gwt.maps.client.geocode.DirectionsCallback; > import com.google.gwt.maps.client.geocode.DirectionsPanel; > import com.google.gwt.maps.client.geocode.StatusCodes; > import com.google.gwt.maps.client.geocode.Waypoint; > import com.google.gwt.user.client.Window; > public class CVRPOutputs > { > > /* Instance fields */ > > private String outFile; > private ArrayList<Waypoint[]> costsMatrix; > private double[][] Distance1; > private int ii; > private int jj; > private int iii; > private int jjj; > String[] parts ; > String[] lines; > int NodeId; > int CustomerId; > String Name; > String Address; > String Postal_Code; > double x_coord; > double y_coord; > double Demand; > ArrayList<Node> nodesList = new ArrayList<Node>(); > ArrayList<Edge> edgesList = new ArrayList<Edge>(); > ArrayList<Waypoint[]> Distance = null; > > /* Class constructor */ > > public ArrayList<Waypoint[]> DistanceMatrix(String DM) { > lines= DM.split("\n"); > for(int i=0; i<lines.length;i++) > { > if(lines[i].length()>1) > { > parts = lines[i].split(","); > NodeId = Integer.parseInt(parts[0]); > CustomerId = Integer.parseInt(parts[1]); > Name = parts[2]; > Address = parts[3]; > Postal_Code = parts[4]; > x_coord = Double.parseDouble(parts[5]); > y_coord = Double.parseDouble(parts[6]); > Demand = Double.parseDouble(parts[7]); > Node aNode = new > Node(NodeId,CustomerId,Name,Address,Postal_Code, x_coord, y_coord, Demand); > nodesList.add(aNode); > > } > } > > > for(int i=0; i<nodesList.size(); i++) > { Node first= nodesList.get(i); > for(int j=1+i; j<nodesList.size(); j++) > { Node last = nodesList.get(j); > Waypoint from = new Waypoint(first.getAddress()); > Waypoint to = new Waypoint(last.getAddress()); > Waypoint[] query= {from, to}; > > Edge waypoint = new Edge(first,last,query); > > edgesList.add(waypoint); > > } > > } > > for(int i= 0; i<nodesList.size();i++) > { Node first= nodesList.get(i); > for(int j=1+i; j<nodesList.size();j++) > {Node last = nodesList.get(j); > Waypoint from = new Waypoint(first.getAddress()); > Waypoint to = new Waypoint(last.getAddress()); > > Waypoint[] yreuq={to,from}; > Edge tniopyaw = new Edge(last,first,yreuq); > edgesList.add(tniopyaw); > } > } > int dim =edgesList.size(); > > Distance= new ArrayList<Waypoint[]>(); > for(int i=0; i<dim;i++) > { > Distance.set(i, edgesList.get(i).getquery()); > } > return Distance; > } > > > > > > CVRPOutputs(String outputFileName,String DM) > { > outFile = outputFileName; > costsMatrix = DistanceMatrix(DM); > Distance1 = costsMatrix(costsMatrix); > > } > @SuppressWarnings("null") > public double[][] costsMatrix( ArrayList<Waypoint[]> costsMatrix){ > int index=0; > > int > indey=(nodesList.size()*nodesList.size()-nodesList.size())/2; > Waypoint[][][] distmat = null; > MapWidget map= null; > DirectionsPanel directionsPanel=null; > DirectionQueryOptions opts = new DirectionQueryOptions(map, > directionsPanel); > > for(int i=0; i<nodesList.size();i++) > {for(int j=1+i; j<nodesList.size();j++) > { > distmat[i][j]=costsMatrix.get(index); > index ++; > } > } > for(int i=0; i<nodesList.size();i++) > { > for(int j=1+i;j<nodesList.size();j++) > { > distmat[j][i]=costsMatrix.get(indey); > indey++; > } > } > for(ii=0; ii<nodesList.size();ii++) > { > for(jj=0;jj<nodesList.size();jj++) > { > final int iiIndex = ii; > final int jjIndex = jj; > Directions.loadFromWaypoints(distmat[ii][jj], > opts, new DirectionsCallback() { > public void onFailure(int statusCode) { > Window.alert("Failed to load > directions: Status " > + StatusCodes.getName(statusCode) + > " " + statusCode); > } > public void onSuccess(DirectionResults > result) { > GWT.log("Successfully loaded > directions.", null); > > Distance1[iiIndex][jjIndex]=result.getDistance().inMeters(); > } > > > > }); > > } > } > > for(iii=0; iii<nodesList.size();iii++) > { > for(jjj=0;jjj<nodesList.size();jjj++) > { > final int iiiIndex = iii; > final int jjjIndex = jjj; > Directions.loadFromWaypoints(distmat[jjj][iii], > opts, new DirectionsCallback() { > public void onFailure(int statusCode) { > Window.alert("Failed to load > directions: Status " > + StatusCodes.getName(statusCode) + > " " + statusCode); > } > public void onSuccess(DirectionResults > result) { > GWT.log("Successfully loaded > directions.", null); > > Distance1[jjjIndex][iiiIndex]=result.getDistance().inMeters(); > } > > > > }); > > } > } > return Distance1; > } > > public void printOutputFile() > { > try > { > PrintWriter out = new PrintWriter(System.currentTimeMillis() + > outFile); > > out.println("***************************************************"); > out.println("* > *"); > out.println("* RESULTS FROM SIMUROUTE PROJECT > *"); > out.println("* > *"); > > out.println("***************************************************"); > > out.println("\r\n"); > > out.println("***************************************************"); > out.println("* COSTS MATRIX > *"); > > out.println("***************************************************"); > out.println("\r\nCOSTS MATRIX:\n"); > for (int i = 0; i < nodesList.size(); i++) > for (int j = 0; j <= i; j++) > out.println(i + " " + j + " " + Distance1[i][j]); > > out.close(); > } > catch (IOException exception) > { > System.out.println("Error processing output file: " + > exception); > } > > } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.