Class SpnegoSOAPConnection


  • public class SpnegoSOAPConnection
    extends javax.xml.soap.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
    • 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 - the name of the login module
        Throws:
        LoginException - if the login fails
      • 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 - the name of the login module
        username - the login id of the user
        password - the login password of the user
        Throws:
        LoginException - if the login fails
    • Method Detail

      • call

        public final javax.xml.soap.SOAPMessage call​(javax.xml.soap.SOAPMessage request,
                                                     Object endpoint)
                                              throws javax.xml.soap.SOAPException
        Specified by:
        call in class javax.xml.soap.SOAPConnection
        Throws:
        javax.xml.soap.SOAPException
      • close

        public final void close()
        Specified by:
        close in class javax.xml.soap.SOAPConnection