Hi Richard,
you'll see in the php examples that the digest authentication is handled by the 'soapclient' object - not anything built by us. It is the same with Java, you won't find a setName() or setPassword() method in any of the NBN proxy classes. You need to use a relevant Java api for doing the authentication.
Obviously you just want an example you can copy, well so do I. I don't know of such an example and I haven't yet successfully achieved digest authenticated from a Java client. I've attached my experiments, which have got very close. They're not particularly well annotated, just because they show where I'd got to when I had to stop.
If you were able to get it working I'd be very interested. I don't know when I'll next have chance to have another go - probably not until October! If I have any success I'll let you know.
Regards, Jon
/*
* This code shows a load of experiments to try to get digest authentication working
* on the NBN Gateway web services for a Java client. Most of it is commented out,
* but may be useful.
*
* AuthTestApp.java
*
* Created on 13 April 2007, 16:26
*
*/
package wsClients.GoogleEarth;
import java.net.URL;
import net.searchnbn.webservices.query.*;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
/**
*
* @author JCOOP
*/
public class AuthTestApp {
/** Creates a new instance of AuthTestApp */
public AuthTestApp() {
}
public static void main(String[] args){
System.out.println("running\n\n");
doIt();
}
private static void doIt(){
try{
//Set up a simple query
OneSpeciesDataRequest osdr = new OneSpeciesDataRequest();
osdr.setTaxonVersionKey("NBNSYS0000005623");
DatasetFilter df = new DatasetFilter();
df.setDatasetKey("GA000012");
osdr.setDatasetList(df);
////////// //This seems to work!!!!!!!
////////// HttpClient client = new HttpClient();
////////// Credentials cred = new UsernamePasswordCredentials("username","password");
////////// client.getState().setCredentials(AuthScope.ANY,cred);//Use for debugging only
////////// GetMethod get = new GetMethod("http://212.219.37.104:8080/NBNWebServices/ws/secure/protected.jsp");
////////// get.setDoAuthentication(true);
////////// int statusCode = client.executeMethod(get);
////////// System.out.println("Here is the HttpStatus: " + statusCode);
////////// if(statusCode != HttpStatus.SC_OK)
////////// System.out.println("Method failed: " + get.getStatusLine());
////////// byte[] responseBody = get.getResponseBody();
////////// System.out.println(new String(responseBody));
////////// System.out.println("response: " + new String(responseBody));
//////////////HttpClient client = new HttpClient();
//////////////List authPrefs = new ArrayList(1);
//////////////authPrefs.add(AuthPolicy.DIGEST);
//////////////client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,authPrefs);
//////////////
////This is an example I grabbed off the web that may help
////URL url = new URL("http://test.musicbrainz.org/ws/1/track/");
////HttpClient httpClient = new HttpClient();
////List authPrefs = new ArrayList(1);
////authPrefs.add(AuthPolicy.DIGEST);
////httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
////authPrefs);
////final String username = "testuser100";
////final String password = "testuser100";
////Credentials credentials = new UsernamePasswordCredentials(username,
////password);
////AuthScope authScope = new AuthScope(url.getHost(),
////url.getPort(),"musicbrainz.org");
////httpClient.getState().setCredentials(authScope, credentials);
////
////PostMethod postMethod = new PostMethod(url.toExternalForm());
////postMethod.setDoAuthentication(true);
////postMethod.addParameter("client","TestProg1");
////postMethod.addParameter("puid","4d8cad37-054d-4421-855e-60f111cf574a
////B2660da86-081f-eca6-12c7-739b37228326");
String testQuery = "<soapenv:Body xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><OneSiteDataRequestxmlns=\"http://webservices.searchnbn.net/query\"xmlns:nbn=\"http://webservices.searchnbn.net/data\"xmlns:xlink=\"http://www.w3.org/1999/xlink\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><GeographicalFilter><nbn:GridSquare key=\"TQ16\" /><MapSettingsheight=\"300\"width=\"300\"outlineBoundary=\"1\"outlineColour=\"#ffff00\"fillColour=\"#00ff00\"fillTransparency=\"0.0\" /><MinimumResolution>Any</MinimumResolution></GeographicalFilter><TaxonVersionKey>NHMSYS0000080205</TaxonVersionKey><DatasetList>\"GA000428\"</DatasetList></OneSiteDataRequest></soapenv:Body>";
//Get some data and output
HttpClient client = new HttpClient();
Credentials cred = new UsernamePasswordCredentials("username","password");
client.getState().setCredentials(AuthScope.ANY,cred);//Use for debugging only
URL url = new URL("http://212.219.37.104:8080/NBNWebServices/ws/secure/webservice");
PostMethod postMethod = new PostMethod(url.toExternalForm());
postMethod.setDoAuthentication(true);
postMethod.addParameter("request",testQuery);
postMethod.setDoAuthentication(true);
System.out.println(client.executeMethod(postMethod));
////// GatewayWebServiceLocator gwsl = new GatewayWebServiceLocator();
////// gwsl.setGatewaySoapPortEndpointAddress("http://212.219.37.104:8080/NBNWebServices/ws/secure/webservice");
////// ((GatewaySoapBindingStub) gwsl.getGatewaySoapPort()).setUsername("andyb");
////// ((GatewaySoapBindingStub) gwsl.getGatewaySoapPort()).setPassword("hwsiasts");
////// GatewayData gd = gwsl.getGatewaySoapPort().getSpeciesData(osdr);
//Now how do I get the above into the GetMethod object below
////////////// HttpClient client = new HttpClient();
////////////// Credentials cred = new UsernamePasswordCredentials("username","password");
////////////// client.getState().setCredentials(AuthScope.ANY,cred);//Use for debugging only
//////////////// GetMethod get = new GetMethod("http://212.219.37.104:8080/NBNWebServices/ws/secure/webservice?" + testQuery); //-Ha - you'll be lucky!!
////////////// GetMethod get = new GetMethod("http://212.219.37.104:8080/NBNWebServices/ws/secure/webservice");
//////////////// GetMethod get = new GetMethod("http://212.219.37.104:8080/NBNWebServices/ws/secure/protected.jsp");
////////////// get.setDoAuthentication(true);
////////////// int statusCode = client.executeMethod(get);
////////////// System.out.println("Here is the HttpStatus: " + statusCode);
////////////// if(statusCode != HttpStatus.SC_OK)
////////////// System.out.println("Method failed: " + get.getStatusLine());
////////////// byte[] responseBody = get.getResponseBody();
////////////// System.out.println(new String(responseBody));
////////////// System.out.println("response: " + new String(responseBody));
// GatewayWebService gws = new GatewayWebServiceLocator();
// GatewaySoapBindingStub gsbs = (GatewaySoapBindingStub) gws.getGatewaySoapPort();
// gsbs.setUsername(userName);
// gsbs.setPassword(pwd);
//CustomerDataServiceSoap uploadService = new
//CustomerDataServiceLocator().getCustomerDataServiceSoap(new URL(cssURL));
//((CustomerDataServiceSoapStub) uploadService).setUsername(user);
//((CustomerDataServiceSoapStub) uploadService).setPassword(pwd);
//////////// Data d = gd.getData();
//////////// Dataset[] ds = d.getDataset();
//////////// for(int i=0; i<ds.length; i++ ){
//////////// Dataset dt = ds[i];
//////////// System.out.println("\n" + dt.getProviderMetadata().getDatasetTitle() + ". Access constraints: " + dt.getProviderMetadata().getAccessConstraints());
//////////// }
//////////// System.out.println("\nSites: \n");
//////////// Site[] sites = d.getSiteList();
//////////// for(int i=0; i<sites.length; i++){
//////////// Site site = sites[i];
//////////// System.out.println("\n" + site.getGridSquare().getKey());
//////////// }
//////////// System.out.println("\n");
////////////
////////////
}catch(Exception e){
System.out.println("Exception: " + e.getMessage() + ", " + e.getLocalizedMessage());
e.printStackTrace(System.out);
}
System.out.flush();
System.out.close();
}
}