CXF aegis 服务的客户端到底怎么回事?

View: New views
3 Messages — Rating Filter:   Alert me  

CXF aegis 服务的客户端到底怎么回事?

by Qianqian's lover :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

部署了一个CXF 的服务,使用aegis绑定,因为是java first,不想为了jaxb在已有的源码上加很多的注释,另外web方法的输入输出
参数也不是简单的String,Long,而是已有的很多DTO,所以,用aegis比较方便,只需要在集合类的成员变量上加其包含的集合成员的类型说
明就行了,例如DTO有属性 List<String> destination_names, Map<Long,String>
CurrencyInfo, 等等。

服务端运行OK,用soapUI访问也没问题,但是用编写的客户端测试就有问题,原因是

服务器只接受SOAPUI 发出的如下的soap request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
envelope/" xmlns:trav="http://travel.interfaces.ws.mycompany.com/"
xmlns:mod="http://models.ws.mycompany.com">
   <soapenv:Header/>
   <soapenv:Body>
      <trav:getTravelPurposes>
         <arg0>100032</arg0>
         <arg1>
            <mod:customerName>thename</mod:customerName>
            <mod:password>welcome</mod:password>
            <mod:userId>admin</mod:userId>
         </arg1>
      </trav:getTravelPurposes>
   </soapenv:Body>
</soapenv:Envelope>

而java手写的客户端发出的请求为:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
 <ns1:getTravelPurposes xmlns:ns1="http://
travel.interfaces.ws.mycompany.com/">
   <ns1:arg0>100032</ns1:arg0>
   <ns1:arg1>
         <ns2:customerName xmlns:ns2="http://
models.ws.mycompany.com">thename</ns2:customerName>
         <ns2:password xmlns:ns2="http://
models.ws.mycompany.com">welcome</ns2:password>
         <ns2:userId xmlns:ns2="http://models.ws.mycompany.com">admin</
ns2:userId>
   </ns1:arg1>
 </ns1:getTravelPurposes>
</soap:Body>
</soap:Envelope>

请注意这里: <arg0>100032</arg0>  与 <ns1:arg0>100032</ns1:arg0>, 对后者,服务器跟踪的结果
是参数为空,
也就是说服务器不认 后一种带有命名空间的参数格式,换了几种java客户端写法,都是一样的结果,服务器参数解析为nulll

不知道有没有人遇到过类似的情况,



付客户端代码如下:使用CXF的JaxWsProxyFactoryBean,我服务器和客户端都用的最新版本CXF2.2.3,服务器
JBOSS5.10GA
当然集成了JBOSSWS-CXF,但是我想那应该不是问题的原因,为何SOAPUI能发出正确的格式呢?如果能使得java客户端也能
像SOAPUI一样发出相同格式的没有ns1前缀的arg0和arg1呢?


import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;

import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.mycompany.mglobal.entity.model.TravelPurposeDTO;
import com.mycompany.ws.interfaces.travel.ITravelWS;
import com.mycompany.ws.models.UserProfileLightDTO4WS;


public class jaxwsclient {

        public static void jaxws() {

                UserProfileLightDTO4WS userProfile = new
UserProfileLightDTO4WS();
                userProfile.setUserId("admin");
                userProfile.setPassword("welcome");
                userProfile.setCustomername("thename");

                 //here we can add to see the client logging
                 List<AbstractFeature> features = new ArrayList<AbstractFeature>
();
                 features.add(new org.apache.cxf.feature.LoggingFeature());

                ClientProxyFactoryBean sf = new JaxWsProxyFactoryBean();
                sf.setFeatures(features);

                     AegisDatabinding db = new AegisDatabinding();db.setSchemas
(null);
                     sf.getServiceFactory().setDataBinding(db);

                     sf.setServiceClass(ImyServiceInterface.class);
                     sf.setAddress("http://127.0.0.1:8080/myServiceInterface/
myServiceInterfaceImpl");

                     ImyServiceInterface service = (ImyServiceInterface) sf.create
();



                                try {
                                        TravelPurposeDTO[] res1 = service.getTravelPurposes
(100032L,userProfile);

                                        for (TravelPurposeDTO dto : res1) {
                                                //dto.showsomething();
                                        }
                                }
                                catch (Exception e)
                                {
                                        e.printStackTrace();
                                }

        }

}

服务器端web方法对应的也很简单,public TravelPurposeDTO[]
myServiceInterfaceImpl.getTravelPurposes(Long id,
UserProfileLightDTO4WS upf);

但是就是无法准确接收到java客户端发出的参数,非常令人烦恼!请高人指点,多谢。

--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“cxf-zh”论坛。
 要在此论坛发帖,请发电子邮件到 cxf-zh@...
 要退订此论坛,请发邮件至 cxf-zh-unsubscribe@...
 更多选项,请通过 http://groups.google.com/group/cxf-zh?hl=zh-CN 访问该论坛
----
Apache CXF 首页 http://cwiki.apache.org/confluence/display/CXF/Index
-~----------~----~----~----~------~----~------~--~---


Re: CXF aegis 服务的客户端到底怎么回事?

by 刘涛-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

是在不行,想点阴招 用JSON结构吧

2009/9/23 Qianqian's lover <bryan.xu2006@...>
部署了一个CXF 的服务,使用aegis绑定,因为是java first,不想为了jaxb在已有的源码上加很多的注释,另外web方法的输入输出
参数也不是简单的String,Long,而是已有的很多DTO,所以,用aegis比较方便,只需要在集合类的成员变量上加其包含的集合成员的类型说
明就行了,例如DTO有属性 List<String> destination_names, Map<Long,String>
CurrencyInfo, 等等。

服务端运行OK,用soapUI访问也没问题,但是用编写的客户端测试就有问题,原因是

服务器只接受SOAPUI 发出的如下的soap request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
envelope/
" xmlns:trav="http://travel.interfaces.ws.mycompany.com/"
xmlns:mod="http://models.ws.mycompany.com">
  <soapenv:Header/>
  <soapenv:Body>
     <trav:getTravelPurposes>
        <arg0>100032</arg0>
        <arg1>
           <mod:customerName>thename</mod:customerName>
           <mod:password>welcome</mod:password>
           <mod:userId>admin</mod:userId>
        </arg1>
     </trav:getTravelPurposes>
  </soapenv:Body>
</soapenv:Envelope>

而java手写的客户端发出的请求为:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
 <ns1:getTravelPurposes xmlns:ns1="http://
travel.interfaces.ws.mycompany.com/">
  <ns1:arg0>100032</ns1:arg0>
  <ns1:arg1>
        <ns2:customerName xmlns:ns2="http://
models.ws.mycompany.com">thename</ns2:customerName>
        <ns2:password xmlns:ns2="http://
models.ws.mycompany.com">welcome</ns2:password>
        <ns2:userId xmlns:ns2="http://models.ws.mycompany.com">admin</
ns2:userId>
  </ns1:arg1>
 </ns1:getTravelPurposes>
</soap:Body>
</soap:Envelope>

请注意这里: <arg0>100032</arg0>  与 <ns1:arg0>100032</ns1:arg0>, 对后者,服务器跟踪的结果
是参数为空,
也就是说服务器不认 后一种带有命名空间的参数格式,换了几种java客户端写法,都是一样的结果,服务器参数解析为nulll

不知道有没有人遇到过类似的情况,



付客户端代码如下:使用CXF的JaxWsProxyFactoryBean,我服务器和客户端都用的最新版本CXF2.2.3,服务器
JBOSS5.10GA
当然集成了JBOSSWS-CXF,但是我想那应该不是问题的原因,为何SOAPUI能发出正确的格式呢?如果能使得java客户端也能
像SOAPUI一样发出相同格式的没有ns1前缀的arg0和arg1呢?


import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;

import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.mycompany.mglobal.entity.model.TravelPurposeDTO;
import com.mycompany.ws.interfaces.travel.ITravelWS;
import com.mycompany.ws.models.UserProfileLightDTO4WS;


public class jaxwsclient {

       public static void jaxws() {

               UserProfileLightDTO4WS userProfile = new
UserProfileLightDTO4WS();
               userProfile.setUserId("admin");
               userProfile.setPassword("welcome");
               userProfile.setCustomername("thename");

                //here we can add to see the client logging
                List<AbstractFeature> features = new ArrayList<AbstractFeature>
();
                features.add(new org.apache.cxf.feature.LoggingFeature());

               ClientProxyFactoryBean sf = new JaxWsProxyFactoryBean();
               sf.setFeatures(features);

                    AegisDatabinding db = new AegisDatabinding();db.setSchemas
(null);
                    sf.getServiceFactory().setDataBinding(db);

                    sf.setServiceClass(ImyServiceInterface.class);
                    sf.setAddress("http://127.0.0.1:8080/myServiceInterface/
myServiceInterfaceImpl");

                    ImyServiceInterface service = (ImyServiceInterface) sf.create
();



                               try {
                                       TravelPurposeDTO[] res1 = service.getTravelPurposes
(100032L,userProfile);

                                       for (TravelPurposeDTO dto : res1) {
                                               //dto.showsomething();
                                       }
                               }
                               catch (Exception e)
                               {
                                       e.printStackTrace();
                               }

       }

}

服务器端web方法对应的也很简单,public TravelPurposeDTO[]
myServiceInterfaceImpl.getTravelPurposes(Long id,
UserProfileLightDTO4WS upf);

但是就是无法准确接收到java客户端发出的参数,非常令人烦恼!请高人指点,多谢。




--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“cxf-zh”论坛。
 要在此论坛发帖,请发电子邮件到 cxf-zh@...
 要退订此论坛,请发邮件至 cxf-zh-unsubscribe@...
 更多选项,请通过 http://groups.google.com/group/cxf-zh?hl=zh-CN 访问该论坛
----
Apache CXF 首页 http://cwiki.apache.org/confluence/display/CXF/Index
-~----------~----~----~----~------~----~------~--~---


Re: CXF aegis 服务的客户端到底怎么回事?

by willem.jiang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ha, 既然你的服务器端没有用 JaxWs frontend, 那你的客户端也别用 JaxWs frontend。
把这段代码

  ClientProxyFactoryBean sf = new JaxWsProxyFactoryBean();
改成
  ClientProxyFactoryBean sf = new ClientProxyFactoryBean();

试一下看看

姜宁 (Willem)
------------------
Apache CXF, Apache Camel committer
Open SOA http://www.fusesource.com
Blog http://willemjiang.blogspot.com
Tiwtter http://twitter.com/willemjiang

On 9月23日, 上午4时35分, "Qianqian's lover" <bryan.xu2...@...> wrote:

> 部署了一个CXF 的服务,使用aegis绑定,因为是java first,不想为了jaxb在已有的源码上加很多的注释,另外web方法的输入输出
> 参数也不是简单的String,Long,而是已有的很多DTO,所以,用aegis比较方便,只需要在集合类的成员变量上加其包含的集合成员的类型说
> 明就行了,例如DTO有属性 List<String> destination_names, Map<Long,String>
> CurrencyInfo, 等等。
>
> 服务端运行OK,用soapUI访问也没问题,但是用编写的客户端测试就有问题,原因是
>
> 服务器只接受SOAPUI 发出的如下的soap request
>
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
> envelope/" xmlns:trav="http://travel.interfaces.ws.mycompany.com/"
> xmlns:mod="http://models.ws.mycompany.com">
>    <soapenv:Header/>
>    <soapenv:Body>
>       <trav:getTravelPurposes>
>          <arg0>100032</arg0>
>          <arg1>
>             <mod:customerName>thename</mod:customerName>
>             <mod:password>welcome</mod:password>
>             <mod:userId>admin</mod:userId>
>          </arg1>
>       </trav:getTravelPurposes>
>    </soapenv:Body>
> </soapenv:Envelope>
>
> 而java手写的客户端发出的请求为:
>
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
>  <ns1:getTravelPurposes xmlns:ns1="http://
> travel.interfaces.ws.mycompany.com/">
>    <ns1:arg0>100032</ns1:arg0>
>    <ns1:arg1>
>          <ns2:customerName xmlns:ns2="http://
> models.ws.mycompany.com">thename</ns2:customerName>
>          <ns2:password xmlns:ns2="http://
> models.ws.mycompany.com">welcome</ns2:password>
>          <ns2:userId xmlns:ns2="http://models.ws.mycompany.com">admin</
> ns2:userId>
>    </ns1:arg1>
>  </ns1:getTravelPurposes>
> </soap:Body>
> </soap:Envelope>
>
> 请注意这里: <arg0>100032</arg0>  与 <ns1:arg0>100032</ns1:arg0>, 对后者,服务器跟踪的结果
> 是参数为空,
> 也就是说服务器不认 后一种带有命名空间的参数格式,换了几种java客户端写法,都是一样的结果,服务器参数解析为nulll
>
> 不知道有没有人遇到过类似的情况,
>
> 付客户端代码如下:使用CXF的JaxWsProxyFactoryBean,我服务器和客户端都用的最新版本CXF2.2.3,服务器
> JBOSS5.10GA
> 当然集成了JBOSSWS-CXF,但是我想那应该不是问题的原因,为何SOAPUI能发出正确的格式呢?如果能使得java客户端也能
> 像SOAPUI一样发出相同格式的没有ns1前缀的arg0和arg1呢?
>
> import java.util.ArrayList;
> import java.util.List;
> import javax.xml.namespace.QName;
>
> import org.apache.cxf.aegis.databinding.AegisDatabinding;
> import org.apache.cxf.feature.AbstractFeature;
> import org.apache.cxf.frontend.ClientProxyFactoryBean;
> import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
>
> import com.mycompany.mglobal.entity.model.TravelPurposeDTO;
> import com.mycompany.ws.interfaces.travel.ITravelWS;
> import com.mycompany.ws.models.UserProfileLightDTO4WS;
>
> public class jaxwsclient {
>
>         public static void jaxws() {
>
>                 UserProfileLightDTO4WS userProfile = new
> UserProfileLightDTO4WS();
>                 userProfile.setUserId("admin");
>                 userProfile.setPassword("welcome");
>                 userProfile.setCustomername("thename");
>
>                  //here we can add to see the client logging
>                  List<AbstractFeature> features = new ArrayList<AbstractFeature>
> ();
>                  features.add(new org.apache.cxf.feature.LoggingFeature());
>
>                 ClientProxyFactoryBean sf = new JaxWsProxyFactoryBean();
>                 sf.setFeatures(features);
>
>                      AegisDatabinding db = new AegisDatabinding();db.setSchemas
> (null);
>                      sf.getServiceFactory().setDataBinding(db);
>
>                      sf.setServiceClass(ImyServiceInterface.class);
>                      sf.setAddress("http://127.0.0.1:8080/myServiceInterface/
> myServiceInterfaceImpl");
>
>                      ImyServiceInterface service = (ImyServiceInterface) sf.create
> ();
>
>                                 try {
>                                         TravelPurposeDTO[] res1 = service.getTravelPurposes
> (100032L,userProfile);
>
>                                         for (TravelPurposeDTO dto : res1) {
>                                                 //dto.showsomething();
>                                         }
>                                 }
>                                 catch (Exception e)
>                                 {
>                                         e.printStackTrace();
>                                 }
>
>         }
>
> }
>
> 服务器端web方法对应的也很简单,public TravelPurposeDTO[]
> myServiceInterfaceImpl.getTravelPurposes(Long id,
> UserProfileLightDTO4WS upf);
>
> 但是就是无法准确接收到java客户端发出的参数,非常令人烦恼!请高人指点,多谢。
--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“cxf-zh”论坛。
 要在此论坛发帖,请发电子邮件到 cxf-zh@...
 要退订此论坛,请发邮件至 cxf-zh-unsubscribe@...
 更多选项,请通过 http://groups.google.com/group/cxf-zh?hl=zh-CN 访问该论坛
----
Apache CXF 首页 http://cwiki.apache.org/confluence/display/CXF/Index
-~----------~----~----~----~------~----~------~--~---