views:

104

answers:

2

This is related to a previous question. I've pulled out the main problem as I've updated much of the code but I still have an issue. How can I have a custom SOAPHandler class add a new element to a SOAP message? I need to add a username and password to the message. If I use:

public boolean handleMessage(SOAPMessageContext context) {

  SOAPMessage msg = context.getMessage();
  SOAPPart part = msg.getSOAPPart();
  SOAPEnvelope envelope = part.getEnvelope();

  .... //additional header information

  SOAPElement element.addChildElement("Username", "sse");
  element.addTextNode("user1");
  element.addChildElement("Password", "sse");
  element.addTextNode("1234");
}

I end up with this where the tags are closed and the values aren't enclosed:

<sse:Username/>user1
<sse:Password/>1234

I want to end up with the username and password formatted like this:

<sse:Username>user1</sse:Username>
<sse:Password>1234</sse:Password>

How can I get the values (user1 and 1234) enclosed in the element?

A: 

Try this:

element.addChildElement("Password", "sse").addTextNode("1234");
Superfilin
A: 

Aside from the fact that the line

SOAPElement element.addChildElement("Username", "sse");

isn't valid java, you need to remember that addChildElement returns the newly-created child element, and you need to add the text nodes to that, not to the parent. All your code is doing is adding a child node (empty), then adding a text node, then another empty child, then another text node.

You probably want this:

element.addChildElement("Username", "sse").addTextNode("user1");
element.addChildElement("Password", "sse").addTextNode("1234");

As a final note, talking to an SEE web service from java will only lead to tears and loss of hair. Microsoft SEE web services are not standards compliant (shocking, I know).

skaffman