Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@webparam

 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have one requirement, in my SOAP i have to use fields which has - (hiphens) , which cannot be used in Java objects as field names .
For example <ValidatePinRequest>
<user-pin></user-pin>
<user-id></user-id>
</ValidatePinRequest>

And in my Java Object i have a class ValidatePinRequest ,and it has fields userPin, userId ( i cannot name it user-pin,user-id).
Is there anyway we can use webparam annotation to map it ?

thanks in advance.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you go



Service is published at http://localhost:8085/ValidatePin

Now I used SOAP UI tool to test the code. Configured service in SOAP UI and generated Request XML.

Request XML in SOAP UI



Response got in SOAP UI



 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot abhay ,but one query what about if my fields are all in a POJO.
But wheenver i annote it, it says invalid location of webparam

for example

public class User{

@WebParam(
@WebParam(name = "user-id") String userId;

//getter setter

any idea on this?
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct. @Webparam can not be applied at the location where you are trying to apply it.
For these kind of requirements, you may have to write your own client and server side code using Low level API (for example using Provider, Dispatch and SOAP Message classes)
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Finally found simple solution to your problem. It just striked me few minutes back. Just remember that XML generation is backed by JAXB.
I have used JAXB annotations to solve your problem

Below mentioned is the code.



SOAP Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pin="http://pin.validation.com/">
<soapenv:Header/>
<soapenv:Body>
<pin:ValidatePinRequest>
<!--Optional:-->
<user-id>abhay</user-id>
<!--Optional:-->
<user-pin>pin001</user-pin>
</pin:ValidatePinRequest>
</soapenv:Body>
</soapenv:Envelope>


SOAP Response

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:ValidatePinRequestResponse xmlns:ns2="http://pin.validation.com/">true</ns2:ValidatePinRequestResponse>
</S:Body>
</S:Envelope>


 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi abhay I tried your suggestion and am using ant task jws even though no errors while building but when I check the wsdl after generations the fields are still the same
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I ran my code through eclipse. not used Ant task.
Please provide your Ant task code here. I will try to execute on my machine.

~ abhay



 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also please post WSDL file and XSD file which got generated from Ant task
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abhay
Unfortunately I cannot copy the wsdl and saop here.
Any idea if jaxb is compatible with weblogic 9.2 or not? am using weblogic 9.2 and jaxb 2.1...everything executes fine but at the end wsdl has no change its generating exactly as it field names are.

Regards
Sudharsan
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the way which version of weblogic are you using?
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

I did not used Weblogic to run my sample code (shown in previous post).
I use Java 7 integrated JAX-WS and SOAPUI to execute my piece of code.
Your problem seem like to more specific.
I try to find any solution to it. But it is difficult as it seem that reason for error may drill down to some specific settings in weblogic or jaxb .

thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic