• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Servlet read file how to expose URL as https

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mike Boota
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HERE is the link for commons file upload.


which has lot of user friendly functions and easy to understand.
 
Mike Boota
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic