aspose file tools*
The moose likes Servlets and the fly likes Servlet read file how to expose URL as https Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet read file how to expose URL as https" Watch "Servlet read file how to expose URL as https" New topic
Author

Servlet read file how to expose URL as https

Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I have a servlet that a client calls from a java application and send a file. I read a file sent and process it. How do I check inside a servlet if some data is really sent e.g. in this case if a client really send a file or not.

Also how do make the servlet URL available to a client as https. I want to use https protocol but don't know how to configure this. Any help is appreciated.

Thanks


MB<br />Sun Certified Programmer for Java2 Platform
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
For the answer to the first question , you need to know as how to upload file from browser to server.
See the following link.

File upload

You can use j2ee's security feature and transfer data securely.
See the following link for configuring the same in Tomcat.
Configuring SSL in Tomcat


Rahul Bhattacharjee
LinkedIn - Blog
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I am trying the following sample I got from net and am getting the following error. Any help what I am doing wrongs:


Here is the sample client code:



Here is the sample servlet code:




Any help on what is wrong.

Thanks
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Cant you just open an output stream and write the file to the servlet ? Its possible to do that. After you write to the output stream, read the response from the servlet.

How do I check inside a servlet if some data is really sent e.g. in this case if a client really send a file or not.


Well you could open the input stream and read some data. If the number of bytes read is 0 then no data was sent by your client.

I want to use https protocol but don't know how to configure this. Any help is appreciated.


Which web container / web server are you using ? That tomcat link should be of help if you are using tomcat to set these things up. How about asking the client application to login before any upload requests are sent ? Or is the data sensitive enough to warrant a HTTPS transaction ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42594
    
  65
It's not as simple as including the file contents as request body. Here is an example of how to do file upload with HttpClient.


Ping & DNS - my free Android networking tools app
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

It's not as simple as including the file contents as request body. Here is an example of how to do file upload with HttpClient.


Hey that looks pretty neat. You could go for the commons file upload API too.
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

HERE is the link for commons file upload.


which has lot of user friendly functions and easy to understand.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Thanks,

I don't know how the client will be uploading the files and writing a servlet using Apache commons libraries then when a client tries to upload any files they too have to use Apache commons. I am trying to have a generic servlet and no matter how the files are uploaded I should be able to handle that. Right now I have a version where I am using outputstream to write to a servlet and a version that uses Apache commons. Using Apache commons I can upload any file regardless of the type but using outputstrean I can't upload .doc, .pdf or any images etc. Any help on how I can make a ervlet generic to handle any files.

Thanks
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I am able to test a file upload using Apache HttpClient and as using outputstream only. Now on my end it's an https. Basically client makes a call using the following url

https://www.myco.com

on my end it comes to a proxy server that then redirects this to the actual location where servlet is deployed i.e.

http://server:host/urlcontext/servlet/FileUpload

While testing I keep getting ssl errors when using url

https://www.myco.com

It works fine when I access it directly using

http://server:host/urlcontext/servlet/FileUpload

Can someone please tell me how to resolve this. As the client only needs the https url that ends at the proxy server on our end and that then based on the ip address the request is coming redirects it to the exact location where the servlet is deployed.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet read file how to expose URL as https