Re: how to create a file uploader that is not html-based or jsp-based

2010-03-31 Thread maikeru8

Thanks for replying.

I have just implemented it successfully without the use of any plugin. I
studied a few functions (that seemed necessary for me) from
apache.commons.httpclient and com.oreilly.servlet and a few examples using
both packages as well :)
-- 
View this message in context: 
http://n4.nabble.com/how-to-create-a-file-uploader-that-is-not-html-based-or-jsp-based-tp1693181p1747082.html
Sent from the Commons - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



how to implement login using httpclient?

2010-03-31 Thread maikeru8

I'm still a beginner with regards to Apache Commons, and I wish to implement
the login for a plugin in Eclipse. The user does not log in via the browser
but rather Eclipse instead. And I found out about httpclient and I was
wondering if I could use it to implement the client-side, and then I decided
to use Java Servlets to implement the server-side.

Any suggestions on how to use it? Just giving simple examples is good enough
for me :)

Thanks for those who will reply. :)
-- 
View this message in context: 
http://n4.nabble.com/how-to-implement-login-using-httpclient-tp1747091p1747091.html
Sent from the Commons - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



RE: how to implement login using httpclient?

2010-03-31 Thread Steve Cole
Here's some snippet code how we implemented HttpClient using the
MultiThreadedHttpConnectionManager...

import java.io.*;
import java.util.*;
import java.text.*;
import java.security.Security;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.*;
import org.apache.commons.httpclient.cookie.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.*;
import org.apache.commons.httpclient.protocol.*;

public class MyHttpclientExample{
  public String protocol  = http;
  public String host  = localhost;
  public int port = 80;
  
  public String httpAuthRealm = null;
  public String httpAuthUsername  = null;
  public String httpAuthPassword  = null;

  public String trustStore= null;
  public String trustStoreType= jks;
  public String trustStorePassword= null;
  public String trustStoreProvider= SUN;
  public String trustStoreAlgorithm   = SunX509;

  public String keyStore  = null;
  public String keyStoreType  = jks;
  public String keyStorePassword  = null;
  public String keyStoreProvider  = SUN;
  public String keyStoreAlgorithm = SunX509;

  public String path  = null;

  public ByteArrayOutputStream responseAsStream = null;
  public String saveAsFilename= null;

  private Hashtable parameters= null;
  private Hashtable cookies   = null;

  public HttpClient httpClient = null;
  Protocol myProtocol= null;
  AuthSSLProtocolSocketFactory authSSLProtocolSocketFactory = null;
  Cookie cookie  = null;
  NameValuePair[] nameValuePairs = null;

  String s1 = null;
  String s2 = null;
  String s3 = null;
  int i1 = 0;
  int i2 = 0;
  int i3 = 0;

//
  String url= null;

/*
  HTTPConnection httpConnection = null;
  HTTPResponse resp = null;
*/

  BufferedReader reader = null;
  StringBuffer returnData   = null;


  public void resetParameters()throws Throwable{
parameters = null;
  }
  public void addParameter(String name, String value)throws Throwable{
if (parameters == null){
  parameters = new Hashtable();
}
parameters.put(name,value);
  }

  public void resetCookies()throws Throwable{
cookies = null;
  }
  public void addCookie(String name, String value)throws Throwable{
if (cookies == null){
  cookies = new Hashtable();
}
cookies.put(name,value);
  }

  public void connect()throws Throwable{
httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

if (protocol.equals(https)){
  authSSLProtocolSocketFactory = new AuthSSLProtocolSocketFactory();
  authSSLProtocolSocketFactory.keyStoreName   = keyStore;
  authSSLProtocolSocketFactory.keyStorePassword   = keyStorePassword;
  authSSLProtocolSocketFactory.trustStoreName = trustStore;
  authSSLProtocolSocketFactory.trustStorePassword = trustStorePassword;
  myProtocol = new Protocol(protocol, authSSLProtocolSocketFactory,
port);
  httpClient.getHostConfiguration().setHost(host, port, myProtocol);
}else{
  httpClient.getHostConfiguration().setHost(host, port, protocol);
}

HttpState initialState = new HttpState();

if (cookies != null){
  for (Enumeration e = cookies.keys(); e.hasMoreElements();){
s1 = (String) e.nextElement();
cookie = new Cookie(host, s1, (String) cookies.get(s1), /, -1,
false);
initialState.addCookie(cookie);
  }
}

if (httpAuthUsername != null){
  httpClient.getParams().setAuthenticationPreemptive(true);
  Credentials defaultcreds = new
UsernamePasswordCredentials(httpAuthUsername, httpAuthPassword);
  initialState.setCredentials(new AuthScope(host, port, httpAuthRealm),
defaultcreds);
}

httpClient.setState(initialState);
  }

  public void get()throws Throwable{
get(path);
  }
  
  public void get(String path)throws Throwable{
if (parameters == null){
  nameValuePairs = null;
 }else{
  nameValuePairs = new NameValuePair[parameters.size()];
  i1 = -1;
  for (Enumeration e = parameters.keys(); e.hasMoreElements();){
i1 ++;
s1 = (String) e.nextElement();
nameValuePairs[i1] = new NameValuePair(s1,(String)
parameters.get(s1));
  }
}
get(path,nameValuePairs);

  }

  public int get(String path, NameValuePair[] nameValuePairs)throws
Throwable{
int i = 0;
url = / + path;
GetMethod method = new GetMethod(url);
method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
if (nameValuePairs != null){
  method.setQueryString(nameValuePairs);
}
// Execute the method.
responseAsStream = new ByteArrayOutputStream();
int statusCode = httpClient.executeMethod(method);
if (statusCode == HttpStatus.SC_OK) {
  byte[] buffer 

Re: how to implement login using httpclient?

2010-03-31 Thread Niall Pemberton
On Wed, Mar 31, 2010 at 6:37 PM, maikeru8 msantos.my...@gmail.com wrote:

 I'm still a beginner with regards to Apache Commons, and I wish to implement
 the login for a plugin in Eclipse. The user does not log in via the browser
 but rather Eclipse instead. And I found out about httpclient and I was
 wondering if I could use it to implement the client-side, and then I decided
 to use Java Servlets to implement the server-side.

 Any suggestions on how to use it? Just giving simple examples is good enough
 for me :)

 Thanks for those who will reply. :)

HttpClient left Commons and became a separate project - their mailing
list is here:

http://hc.apache.org/mail.html

Niall

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org