users@jax-ws.java.net

Re: problem with jax-ws and optional attributes

From: Vivek Pandey <Vivek.Pandey_at_Sun.COM>
Date: Wed, 31 Jan 2007 11:00:31 -0800

Hi Hank,

Sorry your posting on forum did not get answered. You can post your
query here at users_at_jax-ws or the forum. We will try to get back to you
as soon as we can.

The problem you reported looks like a bug, at least the error could be
better. Please report your issue at
http://jax-ws.dev.java.net/servlets/ProjectIssues.

thanks,

-vivek.

Oxford, Hank wrote:
> I posted this on the community forums as well. I'm not sure which place
> is the most appropriate for this kind of question.
>
> I'm developing some web services, starting by defining the object model
> in schemas, then doing WSDL first to define the services.
>
> I've come across a problem that appears to be caused by jax-ws not
> properly handling optional attributes. I've tried this with both 2.0 and
> 2.1ea3 and both fail the same way.
>
> I created a simplified test case to repeatably demonstrate the problem.
>
> The type definition for the object looks like this :
>
> <xsd:complexType name="TestObject" >
> <xsd:attribute name="name" type="xsd:string" use="required"/>
> <xsd:attribute name="subId" type="xsd:integer" use="optional" />
> </xsd:complexType>
>
> And in the wsdl:
> <wsdl:message name="testRequest">
> <wsdl:part name="testrequest" type="mf:TestObject"/>
> </wsdl:message>
>
>
> <wsdl:operation name="testAction">
> <wsdl:input name="testRequest" message="mf:testRequest"/>
> <wsdl:output name="successResponse" message="mf:successResponse"/>
> </wsdl:operation>
>
>
> and the test code:
>
> public void testOptionalAttrs()
> {
> TestObject testObj = new TestObject();
>
> testObj.setName("testName");
> //testObj.setSubId(2);
>
> MDSProvisioningResourcePortType resourceManager =
> factory.getGatewayResourceManager();
> boolean success = resourceManager.testAction(testObj);
>
> }
>
>
> Running the test code with the 'setSubId' uncommented works.
>
> With the 'setSubId' call commented out out results in this error:
>
> javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
> - with linked exception:
> [com.sun.xml.bind.api.AccessorException: java.lang.NullPointerException]
> at
> com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:
> 301)
> at
> com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.j
> ava:124)
> at
> com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:91)
> at
> com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:22
> 5)
> at
> com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTrans
> portPipe.java:121)
> at
> com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(Ht
> tpTransportPipe.java:69)
> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:541)
> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:497)
> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:392)
> at com.sun.xml.ws.client.Stub.process(Stub.java:213)
> at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:120)
> at
> com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.jav
> a:238)
> at
> com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.jav
> a:212)
> at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
> at $Proxy58.testAction(Unknown Source)
> at
> com.qualcomm.mf.prov.ProvisioningGatewayClientFactoryTest.testOptionalAt
> trs(ProvisioningGatewayClientFactoryTest.java:118)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethod
> Runner.java:99)
> at
> org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRun
> ner.java:81)
> at
> org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAf
> terRunner.java:34)
> at
> org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.j
> ava:75)
> at
> org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45
> )
> at
> org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestC
> lassMethodsRunner.java:71)
> at
> org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRu
> nner.java:35)
> at
> org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRun
> ner.java:42)
> at
> org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAf
> terRunner.java:34)
> at
> org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4Tes
> tReference.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.ja
> va:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
> stRunner.java:460)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
> stRunner.java:673)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
> ner.java:386)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
> nner.java:196)
> Caused by: javax.xml.bind.MarshalException
> - with linked exception:
> [com.sun.xml.bind.api.AccessorException: java.lang.NullPointerException]
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:255
> )
> at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:64)
> at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:105)
> at
> com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:
> 292)
> ... 35 more
> Caused by: com.sun.xml.bind.api.AccessorException:
> java.lang.NullPointerException
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java
> :224)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java
> :239)
> at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeAttributes(ClassB
> eanInfoImpl.java:302)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
> ava:661)
> at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:111)
> at
> com.sun.xml.bind.v2.runtime.CompositeStructureBeanInfo.serializeBody(Com
> positeStructureBeanInfo.java:71)
> at
> com.sun.xml.bind.v2.runtime.CompositeStructureBeanInfo.serializeBody(Com
> positeStructureBeanInfo.java:19)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
> ava:663)
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:250
> )
> ... 38 more
> Caused by: com.sun.xml.bind.api.AccessorException:
> java.lang.NullPointerException
> at
> com.sun.xml.bind.v2.runtime.reflect.AdaptedAccessor.get(AdaptedAccessor.
> java:33)
> at
> com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransduc
> edAccessorImpl.print(TransducedAccessor.java:199)
> at
> com.sun.xml.bind.v2.runtime.property.AttributeProperty.serializeAttribut
> es(AttributeProperty.java:61)
> at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeAttributes(ClassB
> eanInfoImpl.java:295)
> ... 44 more
> Caused by: java.lang.NullPointerException
> at org.w3._2001.xmlschema.Adapter3.marshal(Adapter3.java:23)
> at org.w3._2001.xmlschema.Adapter3.marshal(Adapter3.java:1)
> at
> com.sun.xml.bind.v2.runtime.reflect.AdaptedAccessor.get(AdaptedAccessor.
> java:31)
> ... 47 more
>
>
> So am I missing something or is jax-ws not handling optional attributes
> correctly?
>
> Thanks,
> Hank
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jax-ws.dev.java.net
> For additional commands, e-mail: users-help_at_jax-ws.dev.java.net
>
>