on 11-07-2008 11:14 AM
Hi Experts,
we have implemented a WebService with following method:
@WebMethod(operationName = "createOrChangeCostBlock", exclude = false)
public void createOrChangeCostBlock(@WebParam(name = "idCostBlock") Integer idCostBlock,
@WebParam(name = "name") String name,
@WebParam(name = "remark") String remark) {
...
}
We have imported the WebService as an Adaptive WebService Model into a WebDynpro-DC. In its context we see as expected following structure:
Request_CreateOrChangeCostBlock
... CreateOrChangeCostBlock
...... IdCostBlock
...... Name
...... Remark
... Response_CreateOrChangeCostBlock
In the properties of attribute "IdCostBlock" we see type "integerObject".
When we call the WebService-methode we assign some parameters:
wdContext.currentCreateOrChangeCostBlockElement().setIdCostBlock(null);
wdContext.currentCreateOrChangeCostBlockElement().setName("someName");
wdContext.currentCreateOrChangeCostBlockElement().setRemark("someRemark");
wdContext.currentRequest_CreateOrChangeCostBlockElement().modelObject().execute();
On runtime this leads to the following exception:
Exception occured during processing of Web Dynpro application karmann.com/daccwdroot/DaccMasterDataApp. See exception stacktrace for details.
[EXCEPTION]
com.sap.tc.webdynpro.model.webservice.base.exception.BaseModelRuntimeException: Must not assign null to primitive type 'int' of attribute 'IdCostBlock' in model class 'CreateOrChangeCostBlock'
at com.sap.tc.webdynpro.model.webservice.base.model.BaseGenericModelClass.setAttributeValue(BaseGenericModelClass.java:276)
at com.sap.tc.webdynpro.model.webservice.gci.WSTypedModelClass.setAttributeValue(WSTypedModelClass.java:61)
at com.karmann.dacc.wd.model.models.md.CreateOrChangeCostBlock.setIdCostBlock(CreateOrChangeCostBlock.java:52)
at com.karmann.dacc.wd.model.daccmdmodelcomp.wdp.IPublicDaccMDModelComp$ICreateOrChangeCostBlockElement.wdSetObject(IPublicDaccMDModelComp.java:3103)
at com.sap.tc.webdynpro.progmodel.context.MappedNodeElement.wdSetObject(MappedNodeElement.java:74)
at com.sap.tc.webdynpro.progmodel.context.NodeElement.wdSetObject(NodeElement.java:649)
at com.sap.tc.webdynpro.progmodel.context.NodeElement.gciSetObject(NodeElement.java:1121)
at com.karmann.dacc.wd.ui.masterdatacomp.wdp.IPublicMasterDataComp$ICreateOrChangeCostBlockElement.setIdCostBlock(IPublicMasterDataComp.java:2633)
at com.karmann.dacc.wd.ui.masterdatacomp.MasterDataComp.saveCostBlock(MasterDataComp.java:270)
Why this? Is it not possible to pass null to an Integer-parameter of a WebService-method? I can't believe this. Our WSDL looks like this:
u2212 <xs:complexType name="createOrChangeCostBlock">
u2212
<xs:sequence>
<xs:element name="idCostBlock" type="xs:int" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="remark" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
The Wizard for Adaptive WebService-model generated the following class:
public final class CreateOrChangeCostBlock extends com.sap.tc.webdynpro.model.webservice.gci.WSTypedModelClass
{
...
/** setter for ModelAttribute -> IdCostBlock
* @param value new value for ModelAttribute IdCostBlock */
public void setIdCostBlock(java.lang.Integer value) {
super.setAttributeValue("IdCostBlock", value);
}
...
}
Obviously the wizard recognizes the Integer-parameter idCostBlock. The error occurs when calling "super.setAttributeValue(...)" which is located in WSTypedModelClass. Unfortunately here we cannot analyze any more, because this class belongs to WebDynpro-framework ans so we do not have access to the source of this class.
Thanks for each hint,
Christoph
Hi,
As it is obviouss from the code that you have posted, that IDCosttVBlock is an Integer vlaue.
Instead of initializing it as:
wdContext.currentCreateOrChangeCostBlockElement().setIdCostBlock(null);
you should be using:
wdContext.currentCreateOrChangeCostBlockElement().setIdCostBlock(new Integer(0));
NULL is not an accepted value for java.lang.Integer.
Best Regards,
Alka.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
As I have already mentioned NULL is not an accepted value for the java.lang.Integer Class.
If you want the service implementation to recognize it, then you should be define IdCostBlock as String in you Service Definition and do the internal conversion in the service implementation.
Regards,
Alka.
Ok, we've found a workaround that seems to be acceptable. You even might say it's not a workaround but the solution. Anyway.
If the value that should be passed as parameter is null, one should not set the parameter at all:
if (<valueToSet> != null) {
wdContext.currentCreateOrChangeCostBlockElement().setIdCostBlock(<valueToSet>);
} else {
// don't mind - nothing to pass
;
}
wdContext.currentRequest_CreateOrChangeCostBlockElement().modelObject().execute();
This works fine. I don't like it to much because there is one "if" too much whose appearance is not feasable at first glance. Reader of code might ask why they implemented this condition. Moreover a developer easily forgets to implement the "if". And this lack would bang not at compile time but at run time. So the user would find the error.
Christoph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I can't believe this. In Java I may set each variable of type Integer to null. Does the framework really work so different to Java-Standard?
Nevertheless, a great thank you for your prompt answers!
Regards,
Christoph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This is because the Schema Type for Integer and int is xs:int.
Following document will give some hints to change the schema
http://www.ibm.com/developerworks/xml/library/ws-tip-null.html
Regards
Ayyapparaj
Hi Ayyapparaj,
thanks for this hint. What does it mean exactly? I think the WSDL should be correct. Otherwise I would not find "Integer" instead od int in the generated class CreateOrChangeCostBlock. And following the link shows as well that the WSDL seems to be correct (minOccurs="0").
Regards,
Christoph
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.