net.sourceforge.spnego
Class SpnegoSOAPConnection

java.lang.Object
  extended by javax.xml.soap.SOAPConnection
      extended by net.sourceforge.spnego.SpnegoSOAPConnection

public class SpnegoSOAPConnection
extends SOAPConnection

This class can be used to make SOAP calls to a protected SOAP Web Service.

The idea for this class is to replace code that looks like this...

  final SOAPConnectionFactory soapConnectionFactory =
      SOAPConnectionFactory.newInstance();
  conn = soapConnectionFactory.createConnection();
 

with code that looks like this...

  conn = new SpnegoSOAPConnection("spnego-client", "dfelix", "myp@s5");
 

Example:

 SOAPMessage response = null;
 
 final SpnegoSOAPConnection conn =
     new SpnegoSOAPConnection(this.module, this.kuser, this.kpass);
 
 try {
     final MessageFactory msgFactory = MessageFactory.newInstance();
     final SOAPMessage message = msgFactory.createMessage();
 
     final SOAPBody body = message.getSOAPBody();
     
     final SOAPBodyElement bodyElement = body.addBodyElement(
             new QName(this.namespace, this.methodName, this.nsprefix));
     
     for (int i=0; i<args.length; i++) {
         final SOAPElement element = bodyElement.addChildElement(
                 new QName("arg" + i));
 
         element.addTextNode(args[i]);
     }
     
     response = conn.call(message, this.serviceLocation);
 
 } finally {
     conn.close();
 }
 

To see a full working example, take a look at the ExampleSpnegoSOAPClient.java example.

Also, take a look at the how to connect to a protected SOAP Web Service example.

Author:
Darwin V. Felix
See Also:
SpnegoHttpURLConnection

Field Summary
private  SpnegoHttpURLConnection conn
           
 
Constructor Summary
SpnegoSOAPConnection(GSSCredential creds)
          Create an instance where the GSSCredential is specified by the parameter and where the GSSCredential is automatically disposed after use.
SpnegoSOAPConnection(GSSCredential creds, boolean dispose)
          Create an instance where the GSSCredential is specified by the parameter and whether the GSSCredential should be disposed after use.
SpnegoSOAPConnection(String loginModuleName)
          Creates an instance where the LoginContext relies on a keytab file being specified by "java.security.auth.login.config" or where LoginContext relies on tgtsessionkey.
SpnegoSOAPConnection(String loginModuleName, String username, String password)
          Creates an instance where the LoginContext does not require a keytab file.
 
Method Summary
 SOAPMessage call(SOAPMessage request, Object endpoint)
           
 void close()
           
 
Methods inherited from class javax.xml.soap.SOAPConnection
get
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conn

private final transient SpnegoHttpURLConnection conn
Constructor Detail

SpnegoSOAPConnection

public SpnegoSOAPConnection(String loginModuleName)
                     throws LoginException
Creates an instance where the LoginContext relies on a keytab file being specified by "java.security.auth.login.config" or where LoginContext relies on tgtsessionkey.

Parameters:
loginModuleName -
Throws:
LoginException

SpnegoSOAPConnection

public SpnegoSOAPConnection(GSSCredential creds)
Create an instance where the GSSCredential is specified by the parameter and where the GSSCredential is automatically disposed after use.

Parameters:
creds - credentials to use

SpnegoSOAPConnection

public SpnegoSOAPConnection(GSSCredential creds,
                            boolean dispose)
Create an instance where the GSSCredential is specified by the parameter and whether the GSSCredential should be disposed after use.

Parameters:
creds - credentials to use
dispose - true if GSSCredential should be diposed after use

SpnegoSOAPConnection

public SpnegoSOAPConnection(String loginModuleName,
                            String username,
                            String password)
                     throws LoginException
Creates an instance where the LoginContext does not require a keytab file. However, the "java.security.auth.login.config" property must still be set prior to instantiating this object.

Parameters:
loginModuleName -
username -
password -
Throws:
LoginException
Method Detail

call

public final SOAPMessage call(SOAPMessage request,
                              Object endpoint)
                       throws SOAPException
Specified by:
call in class SOAPConnection
Throws:
SOAPException

close

public final void close()
Specified by:
close in class SOAPConnection