简体   繁体   中英

can I use java Expression Language in soap header?

I am working on secured web service and created client classes using wsimport tool.

Web service which I am working will send the response only when it recieve the request in the following format in the soap header

  <wsse:Security xmlns:wsse="http://somename.xsd"> <wsse:UsernameToken xmlns:wsu="http://somename2.xsd"> <wsse:Username>${=(com.company.xxx.util.classname.getXXX("SomeString"))}</wsse:Username> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> 

my question is how ${=(com.company.xxx.util.classname.getXXX("SomeString"))} works in Soap UI tool?

Do we need to add jar that contains class in soap UI?

How the same works in java code ?

Thanks in Advance

Rajesh

Note that ${=(com.company.xxx.util.classname.getXXX("SomeString"))} it's not an expression language (intended as EL for JSP...). This is a specific notation for SOAPUI to use groovy code inside SOAP Requests.

To use a java class from an external jar in a groovy testStep or in a groovy expression (like you do in your SOAP request using ${=groovy exp} notation) you've to add the jar libraries in SOAPUI_HOME/bin/ext directory. Once libraries are copied in that directory restart SOAPUI in order that it can load the new libraries.

EDIT BASED ON COMMENT:

I'm not sure if you're really asking about this, however I give you a possible explanation:

${=groovy exp} notation is for SOAPUI tool, SOAPUI before send the request parse the expression using groovy and sends the value to the WS.

In java you can't use this notation, and also you can't not send a SOAP request with your java code as:

<wsse:Security xmlns:wsse="http://somename.xsd">
         <wsse:UsernameToken xmlns:wsu="http://somename2.xsd">
            <wsse:Username>com.company.xxx.util.classname.getXXX("SomeString")</wsse:Username>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>

Because the WS will interpret com.company.xxx.util.classname.getXXX("SomeString") as Username "string" value. You've to evaluate com.company.xxx.util.classname.getXXX("SomeString") expression in your client, and change the value in your request before send this to your WS, so the request send by your client must looks like for example:

<wsse:Security xmlns:wsse="http://somename.xsd">
         <wsse:UsernameToken xmlns:wsu="http://somename2.xsd">
            <wsse:Username>someUserName</wsse:Username>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>

However seems strange to me that you manually create the WSS headers normally to generate this headers some framework like wss4j.jar is used.

Hope this helps,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM