Class 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:

     System.setProperty("java.security.krb5.conf", "C:/Users/dfelix/krb5.conf");
     System.setProperty("java.security.auth.login.config", "C:/Users/dfelix/login.conf");
     
     final SpnegoSOAPConnection conn =
         new SpnegoSOAPConnection(this.module, this.kuser, this.kpass);
     
     try {
         MessageFactory factory = MessageFactory.newInstance();
         SOAPMessage message = factory.createMessage();
         
         SOAPHeader header = message.getSOAPHeader();
         SOAPBody body = message.getSOAPBody();
         header.detachNode();
         
         QName bodyName = new QName("http://wombat.ztrade.com",
             "GetLastTradePrice", "m");
         SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
         
         QName name = new QName("symbol");
         SOAPElement symbol = bodyElement.addChildElement(name);
         symbol.addTextNode("SUNW");
         
         URL endpoint = new URL("http://spnego.sourceforge.net/soap.html");
         SOAPMessage response = conn.call(message, endpoint);
         
         SOAPBody soapBody = response.getSOAPBody();
         
         Iterator iterator = soapBody.getChildElements(bodyName);
         bodyElement = (SOAPBodyElement)iterator.next();
         String lastPrice = bodyElement.getValue();
         
         System.out.print("The last price for SUNW is ");
         System.out.println(lastPrice);
         
     } 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 -
        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​(GSSCredential creds,
                                    boolean dispose,
                                    boolean confidential,
                                    boolean integrity)
        Create an instance where the GSSCredential is specified by the parameter and whether the GSSCredential should be disposed after use. Set confidentiality and mutual integrity to both be false or both be true.
        Parameters:
        creds - credentials to use
        dispose - true if GSSCredential should be diposed after use
        confidential -
        integrity -
      • 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