• Post Reply Bookmark Topic Watch Topic
  • New Topic

XMLAnyElement request.getAny gives null value

 
rasster shib
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question on the XMLAnyEment

I have wsdl/xsd that generated a request type class that has the following field:

@XmlElement(name = "EncryptedData")
protected EncryptedDataType encryptedData;
@XmlAnyElement(lax = true)
protected List<Object> any;

My question is related to how we can use this any field. First, I thought that in the SOAP UI request, I can just set any field, ex:

<EmpNumber>123456</EmpNumber>
<EmpName>name</EmpName>

(where EmpNumber, EmpName need not map to any existing class)

and when I execute the request xml, the values will become available in the request object

Let's say the request object is named as: SS_ReqType.java

Then, SS_ReqType.getAny() would return a list that contains the EmpName and EmpNumber

However, what I see it prints is

[EmpName : null]

I see that tag name is printing correctly. However the value is null. What am I missing? I am quite new to SOAP web services and the XMLAnyElement, so not sure if I understand it correct.
Any help would be appreciated
 
g tsuji
Ranch Hand
Posts: 697
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing you can do to get a general idea that everything is in place is this.

That would give you a more precise idea what has been going on. I think if you do thing right, the result is something positive.

In a more general setting, elem would be more than a simple element with a text child alone. If you want to get the full structural content, you've to do what you've to do on an dom element, that is to iterate through child nodes of any depth via recursion...
 
rasster shib
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Thanks for your response. I tried what you suggested:

List<Object> listobj=request.getAny();
for (Object obj : listobj) {
org.w3c.dom.Element elem=(org.w3c.dom.Element)obj;
logger.debug(elem.getNodeName());
logger.debug(elem.getNodeValue());
}

elem.getTextContent() didnt seem supported. Instead I used getNodeValue() and that prints nothing

elem.getNodeName prints the name of the node as:

EmpNumber


but elem.getNodeValue() prints nothing.

I am not sure if there is anything that I am missing.

My request classes were generated from the wsdl/xsd using the jaxws-maven-plugin in maven (pom.xml)

From the request in SOAP UI, I just put my own tags as:

<EmpNumber>somenumber</EmpNumber>

thinking that they will get set on the any field but not sure if there is anything more that I need to do.
 
g tsuji
Ranch Hand
Posts: 697
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getTextContent() requires dom level 3 support that your parser might not have. On the other hand, getNodeValue() certainly won't be appropriate for an Element (that's basic knowledge). Hence, you can try this instead at its place under the condition that they are all simple elements with only a text node child.
 
rasster shib
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I tried

logger.debug(elem.getFirstChild().getNodeValue());

and it printed the value for me

So, for <EmpNum>123456</EmpNum>


logger.debug(elem.getFirstChild().getNodeValue());
prints:

123456

So, I guess it was all about using the right way to retrieve this value?

When I had just printed the list and got [EmpNum : null], I thought the value was not getting set correctly, but it looks like it is getting set. Just that I needed to retrieve it the way you suggested?
 
g tsuji
Ranch Hand
Posts: 697
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just that I needed to retrieve it the way you suggested?

For simple element like what you use at the place of xs:any, yes. But, xs:any has a broad range of admissibility that you cannot take that premise for granted.
 
rasster shib
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help, you are awesome. saved me lot of time
 
rasster shib
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another quick question..I would now like to create a Service Provider that will have a login page(and other UI) etc and then it can connect to my
SOAP based web service that I have created. What would be the right way to create this service provider and how do I go about doing it?
Any pointers would be appreciated
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!