[fileupload] Fileupload problem (with files larger than few KB)

2008-03-22 Thread blackbaron.b

Hello,

I have a following problem with the servlet code using 
commons.fileupload (see below).


If I try to upload a file (using form, method POST and 
enctype=multipart/form-data) larger than few KB, temporary file is 
created (size 10-40 KB, varies) but the destination file is not created. 
E.g. I've tried to upload 354 KB file, 40 KB temporary file was created 
on the server running and the iterator was empty (see below).


I have tested with several different files and uploaded from several 
different clients: results always vary and I was successful uploading 
only two 5 and 7 KB large files from one client (others have also failed 
with these files). On the local server files are uploaded correctly 
independent of their size, without any errors. Server is Tomcat 5.5.


//CODE BEGIN
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
...

DiskFileItemFactory factory = new DiskFileItemFactory();
File d = new File(somedir);
d.mkdir();
factory.setRepository(d);

ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(1000);

List fileItems = null;
try {
fileItems = upload.parseRequest(request);
} catch (FileUploadException e1) {
e1.printStackTrace();
}

Iterator i = fileItems.iterator(); //Line 87
FileItem fi = (FileItem) i.next();
String fileName = fi.getName();
File f = new File(somedir+/+fileName);

try {
fi.write(f);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

...
} //CODE END

//LOG BEGIN

Servlet.service() for servlet UploadModel threw exception

java.lang.NullPointerException

at jsp.servlets.UploadFile.doGet(UploadModel.java:87)

at jsp.servlets.UploadFile.doPost(UploadModel.java:128)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) 



at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) 



at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 



at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) 



at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 



at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) 



at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) 



at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)


at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)


at 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) 



at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) 



at 
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) 



at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) 



at java.lang.Thread.run(Thread.java:595)

//LOG END

(referring to the line 87 where Iterator is initialized).

Thanks in advance,
Regards

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[CLI] Usage Patterns Question

2008-03-22 Thread Mark Fortner
I've been using CLI 1 for a while and I noticed that there's been renewed
interest in developing CLI2.  I was wondering how people are currently using
CLI, and whether I'm using it properly?

Most of the command line apps that I've developed do more than one thing.
In order to make it easier to plugin more functionality I use a basic
Command pattern.  Each plugin interface looks something like this:

Command
+ isValid(options: Options):boolean
+ getDescription():String
+ execute(options:Options):void
+ getPrimaryOption():Option

Each command has a primaryOption which uniquely identifies the command from
the command line.  For example, if you have a command which scales images,
then it might be identified by the --scale option.

The main application is responsible for discovering and loading all plugins
at runtime (using the SPI mechanism), determining which plugin to execute,
and printing out help information.  It also invokes the command by first
invoking the command's isValid method to validate the input before invoking
its execute method.

I'm curious if other people are using CLI in a similar manner, or if people
create separate CLI applications for each piece of functionality?

Regards,


-- 
Mark Fortner

blog: http://www.jroller.com/phidias


Re: [beanutils] getPropertyType() on java.util.Map

2008-03-22 Thread Niall Pemberton
On Fri, Mar 21, 2008 at 2:43 PM, Doug Breaux
[EMAIL PROTECTED] wrote:
 The following property:

  myMap(myKey)

  with a bean property of:

  new java.util.HashMapString, Long()

  returns java.util.Map from PropertyUtils.getPropertyType()

  I was expecting Long.  Map seems like a bug.

Well it depends on the getters/setters you have defined. If you have

  public Map getMyMap()
  public void setMyMap(Map)
  public Long getMyMap(String)
  public void setMyMap(String, Long)

Then it should return a Long as the type.

Niall

  Note that getPropertyType() with a property name of simply myMap also
  returns java.util.Map, which is what I would expect.

  Doug

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]