Search code examples
httpservletsweblogicfilenamesput

Cannot find the original file name for HTTP PUT request with servlet running under weblogic


I have set up a simple servlet meant to be used as a file server. I am using Weblogic 10.3.2 as the containter.

I want to process PUT request, so I implemented the doPut method. Since it is a PUT request, I expect to find in the header the name of the file I pushed to the server.

I push a file named test.txt containing "Hello World".

curl -T test.txt http://xxxxxxx:71xxx

Using curl and netcat, here is the request.

PUT /test.txt HTTP/1.1
User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.21.2 OpenSSL/0.9.8h zlib/1.2.3
Host: xxxxxxxxx:71xx
Accept: */*
Content-Length: 12
Expect: 100-continue

Hello World

Using the servlet and weblogic 10.3.2, here is the HTTPServletRequest. This is what I get when I stopped in the doPut method printing the HTTPServletRequest java object, after sending the curl command.

weblogic.servlet.internal.ServletRequestImpl@17d11f0[
PUT /WebServer/FileServlet HTTP/1.1
User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.21.2 OpenSSL/0.9.8h zlib/1.2.3
Accept: */*
Content-Length: 12
Expect: 100-continue

]

If I process the inputstream of the HTTPServletRequest, I get the content of my file, but lose the filename.

Is there a way to get the original filename in the HTTPServletRequest? Could you explain me what happened?

EDIT: Actually what I do not understand is why the requestURL and requestURI changes and reflects the servlet mapping and not the original information?


Solution

  • The filename is not passed as a part of the file. (So, if you were uploading as a POST from a webpage with a file input named "bodyOnly" you would get the file name from the "bodyOnly" parameter)

    So you will have to find another way of passing the filename - perhaps the appropriate way is to have your server handles urls along the lines of

    http://xxxxxxx:71xxx/[filename]
    

    so you upload the file with

    curl -T test.txt http://xxxxxxx:71xxx/test.txt