简体   繁体   English

我可以在soap标头中使用Java表达式语言吗?

[英]can I use java Expression Language in soap header?

I am working on secured web service and created client classes using wsimport tool. 我正在研究安全的Web服务,并使用wsimport工具创建了客户端类。

Web service which I am working will send the response only when it recieve the request in the following format in the soap header 我正在使用的Web服务仅在soap头中以以下格式接收请求时才发送响应

  <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? 我的问题是${=(com.company.xxx.util.classname.getXXX("SomeString"))}在Soap UI工具中如何工作?

Do we need to add jar that contains class in soap UI? 我们是否需要在soap UI中添加包含类的jar?

How the same works in java code ? 这在Java代码中如何工作?

Thanks in Advance 提前致谢

Rajesh 拉杰什

Note that ${=(com.company.xxx.util.classname.getXXX("SomeString"))} it's not an expression language (intended as EL for JSP...). 请注意, ${=(com.company.xxx.util.classname.getXXX("SomeString"))}不是一种表达语言(意为JSP的EL ...)。 This is a specific notation for SOAPUI to use groovy code inside SOAP Requests. 这是SOAPUI在SOAP请求中使用常规代码的一种特殊表示法。

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. 要在groovy testStep或groovy表达式中使用来自外部jar的java类(就像您使用${=groovy exp}表示法在SOAP请求中所做的那样),必须将jar库添加到SOAPUI_HOME/bin/ext目录中。 Once libraries are copied in that directory restart SOAPUI in order that it can load the new libraries. 将库复制到该目录后,请重新启动SOAPUI,以便可以加载新的库。

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. ${=groovy exp}表示SOAPUI工具,SOAPUI在发送请求之前使用groovy解析表达式并将值发送到WS。

In java you can't use this notation, and also you can't not send a SOAP request with your java code as: 在Java中,您不能使用此表示法,也不能通过以下Java代码发送SOAP请求:

<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. 因为WS将com.company.xxx.util.classname.getXXX("SomeString")解释为用户名“字符串”值。 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: 您必须在客户端中评估com.company.xxx.util.classname.getXXX("SomeString")表达式,并在将其发送到WS之前更改请求中的值,因此客户端发送的请求必须类似于例如:

<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. 但是,对我来说,您通常手动创建WSS headers以生成此标头似乎有些wss4j.jar ,使用了诸如wss4j.jar框架。

Hope this helps, 希望这可以帮助,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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