hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marki <puto.c...@gmail.com>
Subject Re: FileUpload Example + SSL
Date Wed, 21 May 2008 06:50:39 GMT
definetly my fault.
What i want to do is a https call. A little deeper, from a standalone app in
a computer, upload files to a servlet on anothers web serverĀ“s maquine.

I have succeded doing that this way:

System.setProperty("javax.net.ssl.trustStore", "C:\\Documents and
Settings\\marcos.villalba\\.keystore");
System.setProperty("javax.net.ssl.trustStorePassword",  "changeit");
HttpClient httpclient = new HttpClient();
        PostMethod filePost = new PostMethod("
https://localhost:8443/WebEFX/hello");
        filePost.setDoAuthentication(true);

        File file = new File("c:\\mypdf.pdf");
        Part[] parts = {new FilePart(file.getName(), file)};
        filePost.setRequestEntity(new MultipartRequestEntity(parts,
filePost.getParams()));

httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        int status = httpclient.executeMethod(filePost);

do you thing is the way to do it, can me optimized? the files will be small
-40k- maaaany of them :D
Thank you Oleg, you R great!!

On Tue, May 20, 2008 at 11:20 PM, Oleg Kalnichevski <olegk@apache.org>
wrote:

> On Tue, 2008-05-20 at 13:51 +0200, Marki wrote:
> > Hi there,newbie here!
> > This is my first mail the list.
> >
> > Im working on a httpCliente capable to send files to a servlets.
> >
> > Thanks to the FileUpload Example what i found in:
> > http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/
> > -100 %recommended-
> >  I success sending files to the servlet.
> >
> > The problem i actually hace is that, the file sending must be done over
> SSH.
> >
> > My server is apache Tomcat and i configure it to accept https calls.
> > Following apache instrucctions I create a .ketStore file,
> >
> > Then I make a test program to assure I reach the server throght SSH:
> >
> >     private static int port = 8443;             // The HTTPS Port
> (usually
> > 443)
> >     private static String host = "localhost";   // The server to connect
> to
> >     private static String path = "/WebEFX/hello";// The file/path to
> > retrieve
> >
> > System.setProperty("javax.net.ssl.trustStore", "C:\\Documents and
> > Settings\\myUser\\.keystore");
> > System.setProperty("javax.net.ssl.trustStorePassword",  "changeit");
> >
> > Security.addProvider(new
> > com.sun.net.ssl.internal.ssl.Provider());
> > // Connect to the server using an SSL socket
> > SSLSocketFactory factory = (SSLSocketFactory)
> SSLSocketFactory.getDefault();
> > SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
> >
> > // Send HTTP GET message
> >             PrintWriter out = new PrintWriter(new
> > BufferedOutputStream(socket.getOutputStream()));
> >             out.println("GET "+path+" HTTP/1.1");
> >             out.println("Host: "+host);
> >             out.println("Connection: close");
> >             out.println("User-Agent: Java HTTPS Client");
> >             out.println("");
> >             out.flush();
> >
> >             // Now dump server reply to console
> >             BufferedReader in = new BufferedReader(new
> > InputStreamReader(socket.getInputStream()));
> >             int c;
> >             while ((c = in.read()) != -1)
> >             {
> >                 System.out.write(c);
> >             }
> >
> >             // All done, close io streams and socket
> >             out.close();
> >             in.close();
> >             socket.close();
> >
> > It works fine.
> > what i want to do is, add SSH support to the FileUpload example basicly.
> > I have checket out the SSL Guide in httpClient's Web but I dont know hoy
> to
> > deal with my actual ".keyStore" and my "changeit" password.
> > How can I merge these two things??
> >
>
> I am confused. Do you want to support SSL (Secure Sockets Layer
> protocol) or SSH (Secure Shell protocol)? These are not the same thing.
> SSH basically utilizes SSL for transport security.
>
> Oleg
>
>
> > Thanks in advance for the advice!!!
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
Regards

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message