Hi I am a newbie and was wondering if some gracious soul could help out.
What I am trying to do, is post some data to a form, if the form sees
the key "secure_payload' in the query string it needs to perform an auto
login into the site vs a traditional login. It then redirects me to a
new page which I need to get the response and display
Rather when I try to follow the redirect url by doing a get
I get a
Method failed : HTTP/1.1 320 Found , when I do a post . Which is what
I expect as I need to follow this to the new resource.
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/AWD/login.aspx">here</a>.</h2>
</body></html>
Then it throws
java.lang.IllegalArgumentException: host parameter is null
I get no host ? I am confused? do I need to set some thing how does the
new url get know the host information ?
Appreciate your help
Thank you
Reeve
########################################################################
################################################################
This is what I have in my code
########################################################################
###############################################################
package com.gmacb.blt.whlstruts.assetwisedirect.utility;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.log4j.Logger;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
public class CopyOfAwdSSOPost3 {
final private static Logger log =
Logger.getLogger(CopyOfAwdSSOPost3.class);
public CopyOfAwdSSOPost3(){}
public void sendToAwdServer(String url,String params) throws
IOException{
String response= null;
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
post.setFollowRedirects(true);
post.addParameter("secure_payload",params);
try {
// execute the post
int statusCode = client.executeMethod( post );
//check the response code
// 200 status ok
if (statusCode != HttpStatus.SC_OK) {
System.out.println("Method failed: " +
post.getStatusLine());
}
// Read the response body.
InputStreamReader is = new
InputStreamReader(post.getResponseBodyAsStream() );
BufferedReader in = new BufferedReader( is );
// Use caution: ensure correct character encoding and
is not binary data
for ( String s; ( s = in.readLine() ) != null; )
System.out.println( s );
System.out.println("status:" + post.getStatusLine());
//close connection
post.releaseConnection();
// Tell me about the redirect.
int statuscode = post.getStatusCode();
if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
Header header = post.getResponseHeader("location");
if (header != null) {
String newuri = header.getValue();
if ((newuri == null) || (newuri.equals(""))) {
newuri = "/";
}
//System.out.println("Redirect target: " +
newuri);
GetMethod redirect = new GetMethod(newuri);
//Execute the method.
statuscode =client.executeMethod(redirect);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed:
"+ redirect.getStatusLine());
}
// Read the response body.
is = new
InputStreamReader(redirect.getResponseBodyAsStream() );
in = new BufferedReader( is );
// Deal with the response.
// Use caution: ensure correct character
encoding and is not binary data
for ( String s; ( s = in.readLine() ) !=
null;)
System.out.println( s );
// release any connection resources used by the
method
redirect.releaseConnection();
} else {
//System.out.println("Invalid redirect");
System.exit(1);
}
}
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return response;
}
public static void main(String[] args) throws IOException {
/*
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
"true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.
wire.header", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.
commons.httpclient", "debug");
*/
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
"true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.
wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.
commons.httpclient", "debug");
String
url="https://secureshrtyukon.rfc.com/awd/AutoLogon/login.aspx";
System.out.println("url: "+url);
String msg = new
AssetWisePararmeterBuilder().buildParamters("reeve");
System.out.println("msg: "+msg);
ReadSSOXMLFile sSSOXmlFile = new
ReadSSOXMLFile("C:\\generic_sso_sample_app_password\\GenericTestHarness\
\generic_sso_publickey.xml");
String encodedMsg = new
RSAEncryptor().getBase64EncodedMessage(sSSOXmlFile.getbase64DecodedModul
us(), sSSOXmlFile.getbase64DecodedExponent(), msg);
System.out.println("encoded msg: "+encodedMsg);
CopyOfAwdSSOPost3 send = new CopyOfAwdSSOPost3();
send.sendToAwdServer(url,encodedMsg);
}
}
########################################################################
######################################
This is the wire trace
########################################################################
###############################
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -Java version: 1.4.2_13
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -Java vendor: Sun
Microsystems Inc.
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -Java class path:
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -Operating system name:
Windows XP
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -Operating system
architecture: x86
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -Operating system
version: 5.1
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -SUN 1.42: SUN (DSA
key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom;
X.509 certificates; JKS keystore; PKIX CertPathValidator; PKIX
CertPathBuilder; LDAP, Collection CertStores)
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -SunJSSE 1.42: Sun JSSE
provider(implements RSA Signatures, PKCS12, SunX509 key/trust factories,
SSLv3, TLSv1)
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -SunRsaSign 1.42: SUN's
provider for RSA signatures
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -SunJCE 1.42: SunJCE
Provider (implements DES, Triple DES, AES, Blowfish, PBE,
Diffie-Hellman, HMAC-MD5, HMAC-SHA1)
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -SunJGSS 1.0: Sun
(Kerberos v5)
2007/02/02 11:25:59:150 EST [DEBUG] HttpClient - -BC 1.35: BouncyCastle
Security Provider v1.35
2007/02/02 11:25:59:230 EST [DEBUG] HttpConnection -
-HttpConnection.setSoTimeout(0)
2007/02/02 11:25:59:401 EST [DEBUG] HttpMethodBase - -Execute loop try 1
2007/02/02 11:25:59:401 EST [DEBUG] wire - ->> "POST
/awd/AutoLogon/login.aspx HTTP/1.1[\r][\n]"
2007/02/02 11:25:59:411 EST [DEBUG] HttpMethodBase - -Adding Host
request header
2007/02/02 11:25:59:421 EST [DEBUG] HttpMethodBase - -Default charset
used: ISO-8859-1
2007/02/02 11:25:59:421 EST [DEBUG] wire - ->> "User-Agent: Jakarta
Commons-HttpClient/2.0rc2[\r][\n]"
2007/02/02 11:25:59:421 EST [DEBUG] wire - ->> "Host:
xyz.rfc.com[\r][\n]"
2007/02/02 11:25:59:421 EST [DEBUG] wire - ->> "Content-Length:
197[\r][\n]"
2007/02/02 11:25:59:421 EST [DEBUG] wire - ->> "Content-Type:
application/x-www-form-urlencoded[\r][\n]"
2007/02/02 11:25:59:651 EST [DEBUG] wire - ->> "[\r][\n]"
2007/02/02 11:25:59:651 EST [DEBUG] EntityEnclosingMethod - -Using
buffered request body
2007/02/02 11:25:59:661 EST [DEBUG] wire - ->>
"secure_payload=yfz4xvQDifUpE8ELN1Y4FItL1lSXDF%2F2pYvGc623gHGBwfYECwhjAD
5PYzTpsojlnDJjYf8%2BPuw5Zp7eZxV2J%2FOFzXjLKgHdEsk6P4ZUDhLhz9UIG3veYBx36j
p%2FMdppNrPq2OkUq9WDyJUxyzUHSonr7F5hvD0F8ajGIeOAzw0%3D"
2007/02/02 11:25:59:661 EST [DEBUG] EntityEnclosingMethod - -Request
body sent
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "HTTP/1.1 100
Continue[\r][\n]"
2007/02/02 11:25:59:791 EST [INFO] HttpMethodBase - -Discarding
unexpected response: HTTP/1.1 100 Continue
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "HTTP/1.1 302
Found[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "Set-Cookie:
secureshrtyukon_CKE=1849206976.20480.0000; path=/[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "Date: Fri, 02 Feb 2007
16:25:55 GMT[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "Server:
Microsoft-IIS/6.0[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "X-Powered-By:
ASP.NET[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "X-AspNet-Version:
2.0.50727[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "Location:
/AWD/login.aspx[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "Set-Cookie:
ASP.NET_SessionId=asq3eb55zsxpfwjwrzszgp45; path=/; HttpOnly[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "Cache-Control:
private[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "Content-Type: text/html;
charset=utf-8[\r][\n]"
2007/02/02 11:25:59:791 EST [DEBUG] wire - -<< "Content-Length:
132[\r][\n]"
2007/02/02 11:25:59:822 EST [DEBUG] HttpMethodBase - -Cookie accepted:
"$Version=0; secureshrtyukon_CKE=1849206976.20480.0000; $Path=/"
2007/02/02 11:25:59:832 EST [DEBUG] CookieSpec - -Unrecognized cookie
attribute: name=HttpOnly, value=null
2007/02/02 11:25:59:832 EST [DEBUG] HttpMethodBase - -Cookie accepted:
"$Version=0; ASP.NET_SessionId=asq3eb55zsxpfwjwrzszgp45; $Path=/"
2007/02/02 11:25:59:832 EST [DEBUG] HttpMethodBase - -Redirect required
2007/02/02 11:25:59:832 EST [INFO] HttpMethodBase - -Redirect requested
but followRedirects is disabled
Method failed: HTTP/1.1 302 Found
2007/02/02 11:25:59:832 EST [DEBUG] wire - -<<
"<html><head><title>Object moved</title></head><body>[\r][\n]"
2007/02/02 11:25:59:832 EST [DEBUG] wire - -<< "<h2>Object moved to <a
href="/AWD/login.aspx">here</a>.</h2>[\r][\n]"
2007/02/02 11:25:59:832 EST [DEBUG] wire - -<< "</body></html>[\r][\n]"
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/AWD/login.aspx">here</a>.</h2>
</body></html>
2007/02/02 11:25:59:832 EST [DEBUG] HttpMethodBase - -Resorting to
protocol version default close connection policy
2007/02/02 11:25:59:832 EST [DEBUG] HttpMethodBase - -Should NOT close
connection, using HTTP/1.1.
status:HTTP/1.1 302 Found
java.lang.IllegalArgumentException: host parameter is null
at
org.apache.commons.httpclient.HttpConnection.setHost(HttpConnection.java
:277)
at
org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnection(
SimpleHttpConnectionManager.java:149)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:6
45)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:5
29)
at
com.gmacb.blt.whlstruts.assetwisedirect.utility.CopyOfAwdSSOPost3.sendTo
AwdServer(CopyOfAwdSSOPost3.java:78)
at
com.gmacb.blt.whlstruts.assetwisedirect.utility.CopyOfAwdSSOPost3.main(C
opyOfAwdSSOPost3.java:152)
Exception in thread "main"