public class SpnegoSOAPConnection extends SOAPConnection
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.
SpnegoHttpURLConnection
Modifier and Type | Field and Description |
---|---|
private SpnegoHttpURLConnection |
conn |
private DocumentBuilderFactory |
documentFactory |
private static Logger |
LOGGER
Default LOGGER.
|
private MessageFactory |
messageFactory |
Constructor and Description |
---|
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(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.
|
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.
|
Modifier and Type | Method and Description |
---|---|
SOAPMessage |
call(SOAPMessage request,
Object endpoint) |
void |
close() |
private SOAPMessage |
createMessage(InputStream stream) |
private Document |
parse(InputStream stream) |
private SOAPMessage |
transform(Node soapBody) |
get
private final transient SpnegoHttpURLConnection conn
private final transient DocumentBuilderFactory documentFactory
private final transient MessageFactory messageFactory
public SpnegoSOAPConnection(String loginModuleName) throws LoginException
loginModuleName
- LoginException
public SpnegoSOAPConnection(GSSCredential creds)
creds
- credentials to usepublic SpnegoSOAPConnection(GSSCredential creds, boolean dispose)
creds
- credentials to usedispose
- true if GSSCredential should be diposed after usepublic SpnegoSOAPConnection(GSSCredential creds, boolean dispose, boolean confidential, boolean integrity)
creds
- credentials to usedispose
- true if GSSCredential should be diposed after useconfidential
- integrity
- public SpnegoSOAPConnection(String loginModuleName, String username, String password) throws LoginException
loginModuleName
- username
- password
- LoginException
public final SOAPMessage call(SOAPMessage request, Object endpoint) throws SOAPException
call
in class SOAPConnection
SOAPException
public final void close()
close
in class SOAPConnection
private SOAPMessage createMessage(InputStream stream) throws SOAPException
SOAPException
private Document parse(InputStream stream) throws SAXException, IOException, ParserConfigurationException
private SOAPMessage transform(Node soapBody) throws SOAPException, IOException, TransformerException, SAXException, ParserConfigurationException