unexpected null value for literal data

There is a challenge that is hard to overcome at first; making sense of error messages.

You can always Google with the text of the error, “unexpected null value for literal data” and hope to be lucky. If you are using Oracle Application Server 10.1.3.0, here is the explaination for the message and two ways out.

The Exception:

unexpected null value for literal data
at oracle.j2ee.ws.common.util.exception.JAXRPCExceptionBase.<init>(JAXRPCExceptionBase.java:52)
at oracle.j2ee.ws.common.encoding.SerializationException.<init>(SerializationException.java:26)
...

The relevant schema:

<complexType name="Customer">
<sequence>
<element name="address" type="tns:Address"/>
<element name="firstName" type="string"/>
<element name="lastName" type="string"/>
</sequence>
</complexType>

A sample code that will cause this exception:

public void testServ() throws Exception {
ServiceSoapHttpPortClient service = new ServiceSoapHttpPortClient();

Customer c = new Customer();
c.setFirstName("eric");
c.setLastName("rajkovic");
service.echoCustomer(c);
}

The problem: Based on the schema definition, the Address is required for every Customer instance. This is because the default value for the minOccurs attribute is 1.

The ways out: i) make sure that you do not use any 'null' value in your Java code for inputs that are mendatories, based on the schema definition or ii) make the element optional in the schema. This second option will be especially handy if you have a large number of complex types nested in your schema and the server is OK with missing input elements.

i) modified client code:

public void testServ() throws Exception {
ServiceSoapHttpPortClient service = new ServiceSoapHttpPortClient();

Customer c = new Customer();
c.setFirstName("eric");
c.setLastName("rajkovic");
Address a = new Address();
a.setStreet("street name");
c.setAddress(a);
service.echoCustomer(c);
}
ii) modified XML Schema

<complexType name="Customer">
<sequence>
<element name="address" type="tns:Address" minOccurs="0"/>
<element name="firstName" type="string"/>
<element name="lastName" type="string"/>
</sequence>
</complexType>
It's the drawback of trying to be strict and avoid serialiazing data that may be rejected by a strict service endpoint.

-ecco

Comments

SanjGaut said…
IS there a way to Generate the Proxies which can take the Null Parameters as well ?? apart from the xsd changes .

Thanks
SanjGaut said…
IS there a way to Generate the Proxies which can take the Null Parameters as well ?? apart from the xsd changes .

Thanks
Aashish Dalmia said…
Again, your knowledge helped me today.

One advise for the developers---- always double check/pay attention to the xsd (schema) files that you use in your wsdl/web services.

Thank you so much
Aashish Dalmia
glow said…
Thanks! This vas truly heplful to me :-)

Popular posts from this blog

Changing the version of JDK used by JDeveloper

Connection reset from a WCF Web Service

Test locally first, then deploy to the cloud.