Thanks Roland...
>> The file should contain the XML SOAP request you want to post.
I'm now attempting to combine the AlternateAuthentication sample and the
PostSOAP sample to send a SOAP request to a .NET server that requires DIGEST
authentication, however I get an error:
"credentials provider not available"
EXTRACT OF NEGOTIATION:
-----------------------
HttpConnection - Open connection to 10.11.42.25:8080
header - >> "POST /soap/status.asmx HTTP/1.1"
HttpMethodBase - Adding Host request header
header - >> "SOAPAction: http://schemas.ipmonitor.com/ipm70/GetGroups"
header - >> "User-Agent: Jakarta Commons-HttpClient/3.1-rc1"
header - >> "Host: 10.11.42.25:8080"
header - >> "Expect: 100-continue"
header - >> "Content-Length: 313"
header - >> "Content-Type: text/xml; charset=ISO-8859-1"
header - >> ""
HttpMethodBase - 100 (continue) read timeout. Resume sending the request
content - >> "<?xml version="1.0" encoding="utf-8"?>"
content - >> "<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">"
content - >> "[0x9]<soap:Body>"
content - >> "[0x9][0x9]<GetGroups xmlns="http://schemas.ipmonitor.com/ipm70/"
/>"
content - >> "[0x9]</soap:Body>"
content - >> "</soap:Envelope>"
EntityEnclosingMethod - Request body sent
header - << "HTTP/1.0 401 Access Denied"
header - << "Server: ipMonitor 8.0"
header - << "WWW-Authenticate: Digest realm="[EMAIL PROTECTED]",
nonce="37a0a06121ee34d54da7a72f9ff376e4", qop="auth""
header - << "Date: Wed, 11 Apr 2007 10:57:20 GMT"
header - << "Connection: close"
header - << "Content-Length: 0"
HttpMethodDirector - Authorization required
AuthChallengeProcessor - Supported authentication schemes in the order of
preference: [Digest, Basic, NTLM]
AuthChallengeProcessor - Digest authentication scheme selected
AuthChallengeProcessor - Using authentication scheme: digest
AuthChallengeProcessor - Authorization challenge processed
HttpMethodDirector - Authentication scope: DIGEST
'[EMAIL PROTECTED]'@10.11.42.25:8080
HttpMethodDirector - Credentials required
HttpMethodDirector - Credentials provider not available
HttpMethodDirector - No credentials available for DIGEST
'[EMAIL PROTECTED]'@10.11.42.25:8080
Response status code: 401
I include a dump of the working AlternateAuthentication negotiation:
--------------------------------------------------------------------
HttpConnection - Open connection to 10.11.42.25:8080
header - >> "GET /soap/status.asmx HTTP/1.1"
HttpMethodBase - Adding Host request header
header - >> "User-Agent: Jakarta Commons-HttpClient/3.1-rc1"
header - >> "Host: 10.11.42.25:8080"
header - >> "[\r][\n]"
header - << "HTTP/1.0 401 Access Denied"
header - << "Server: ipMonitor 8.0"
header - << "WWW-Authenticate: Digest realm="[EMAIL PROTECTED]",
nonce="5850638a638bb7111c57773b7994fc43", qop="auth""
header - << "Date: Wed, 11 Apr 2007 11:01:47 GMT"
header - << "Connection: close"
header - << "Content-Length: 0"
HttpMethodDirector - Authorization required
AuthChallengeProcessor - Supported authentication schemes in the order of
preference: [Digest, Basic, NTLM]
AuthChallengeProcessor - Digest authentication scheme selected
AuthChallengeProcessor - Using authentication scheme: digest
AuthChallengeProcessor - Authorization challenge processed
HttpMethodDirector - Authentication scope: DIGEST
'[EMAIL PROTECTED]'@10.11.42.25:8080
HttpMethodDirector - Retry authentication
HttpMethodBase - Should close connection in response to directive: close
HttpConnection - Connection is locked. Call to releaseConnection() ignored.
HttpMethodDirector - Authenticating with DIGEST
'[EMAIL PROTECTED]'@10.11.42.25:8080
HttpMethodParams - Credential charset not configured, using HTTP element charset
DigestScheme - Using qop method auth
HttpConnection - Open connection to 10.11.42.25:8080
header - >> "GET /soap/status.asmx HTTP/1.0"
HttpMethodBase - Adding Host request header
header - >> "User-Agent: Jakarta Commons-HttpClient/3.1-rc1"
header - >> "Authorization: Digest username="monitoradmin",
realm="[EMAIL PROTECTED]", nonce="5850638a638bb7111c57773b7994fc43",
uri="/soap/status.asmx", response="f7197528d823612631f3c31abd5718f2", qop=auth,
nc=00000001, cnonce="9560c4803a94575fd2a9da7602158c45""
header - >> "Host: 10.11.42.25:8080"
header - >> ""
header - << "HTTP/1.0 200 ok"
header - << "Server: ipMonitor 8.0"
header - << "Content-Type: text/html"
header - << "Cache-Control: no-cache"
header - << "Date: Wed, 11 Apr 2007 11:01:47 GMT"
header - << "Connection: close"
header - << "Content-Length: 2242"
HTTP/1.0 200 ok
And here's my dumb cut-and-paste between AlternateAuthentication and PostSOAP
classes:
-----------------------------------------------------------------------------
package com.justatest.test;
import java.io.File;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.FileRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthPolicy;
import org.apache.commons.httpclient.auth.AuthScope;
import java.util.ArrayList;
import java.util.List;
/**
*
* This is a sample application that demonstrates
* how to use the Jakarta HttpClient API.
*
* This application sends an XML document
* to a remote web server using HTTP POST
*
* @author Sean C. Sullivan
* @author Ortwin Glueck
* @author Oleg Kalnichevski
* @author Paul King
*/
public class PostSOAPAuthTest {
/**
*
* Usage:
* java PostSOAP http://mywebserver:80/ SOAPAction c:\foo.xml
*
* @param args command line arguments
* Argument 0 is a URL to a web server
* Argument 1 is the SOAP Action
* Argument 2 is a local filename
*
*/
public static void main(String[] args) throws Exception {
if (args.length != 3) {
System.out.println("Usage: java -classpath <classpath>
[-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>] PostSOAP <url>
<soapaction> <filename>]");
System.out.println("<classpath> - must contain the
commons-httpclient.jar and commons-logging.jar");
System.out.println("<loglevel> - one of error, warn, info, debug,
trace");
System.out.println("<url> - the URL to post the file to");
System.out.println("<soapaction> - the SOAP action header value");
System.out.println("<filename> - file to post to the URL");
System.out.println();
System.exit(1);
}
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");
// Get target URL
String strURL = args[0];
// Get SOAP action
String strSoapAction = args[1];
// Get file to be posted
String strXMLFilename = args[2];
File input = new File(strXMLFilename);
// Prepare HTTP post
PostMethod post = new PostMethod(strURL);
// Request content will be retrieved directly
// from the input stream
RequestEntity entity = new FileRequestEntity(input, "text/xml;
charset=ISO-8859-1");
post.setRequestEntity(entity);
// consult documentation for your web service
post.setRequestHeader("SOAPAction", strSoapAction);
// Get HTTP client
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("10.11.42.25", 8080, "AuthScope.ANY_REALM"),
new UsernamePasswordCredentials("monitoradmin", "Monitoraggi0"));
List authPrefs = new ArrayList(3);
authPrefs.add(AuthPolicy.DIGEST);
authPrefs.add(AuthPolicy.BASIC);
authPrefs.add(AuthPolicy.NTLM);
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
client.getParams().setParameter("http.protocol.expect-continue", new
Boolean(true));
// Execute request
try {
int result = client.executeMethod(post);
// Display status code
System.out.println("Response status code: " + result);
// Display response
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
} finally {
// Release current connection to the connection pool once you are
done
post.releaseConnection();
}
}
}
Would anyone be patient enough to take a quick look and see if there's anything
obvious where I'm going wrong, and add a suggestion on how to get the
authentication and SOAP request to work?
Many thanks
/j-p.
-------------------------------------------------------------------
Open Invitation for Contemporary Artists http://www.artprocess.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]