无法调用Fabric8公开的Web服务

时间:2015-11-17 14:23:07

标签: web-services jbossfuse fabric8

我在保险丝蓝图上公开了以下CXF Web服务。蓝图部署在Fabric Profile上:

<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
    xmlns:cxf="http://cxf.apache.org/blueprint/core"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd 
             http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
             http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

   <camelcxf:cxfEndpoint id="input-cxf" address="/myfuse-demo/"        
                        serviceClass="com.sample.SourceExampleWS" />      

   <camelContext id="fuse-demo-route-example-cxf" xmlns="http://camel.apache.org/schema/blueprint">

        <route id="demo-source-cxf">


            <from uri="cxf:bean:input-cxf"/>
            <transform>
                <simple>
                    ${in.body[0]}
                </simple>
            </transform>
            <log message="Received: ${in.body}"/>
            <!-- removed for brevity -->
        </route>
    </camelContext>

</blueprint>

SourceExampleWS就是这个简单的界面:

package com.sample;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface SourceExampleWS {

     @WebMethod int call(  @WebParam( name = "struct")Struct s);
}

Struct类只是一个Java Bean:

package com.sample;

@XmlRootElement
public class Struct implements java.io.Serializable {

public Struct()  {

}   
int x;
int y;


public int getX() {
   return x;
}


public int getY() {
   return y;
}

public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
}

问题是,当我在Fabric上部署bundle时,我无法调用WebService的调用方法。

从WSDL(http://10.1.86.122:8182/cxf/myfuse-demo?wsdl),SOAPUI生成以下SOAP消息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="http://sample.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <sam:call>
         <sam:struct>
            <x>201</x>
            <y>144</y>
         </sam:struct>
      </sam:call>
   </soapenv:Body>
</soapenv:Envelope>

但是我得到以下错误作为回复:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Unmarshalling Error: unexpected element (uri:"http://sample.com/", local:"struct"). Expected elements are &lt;{}struct></faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

我已从数据包中删除名称空间“sam”,但仍然收到另一个错误:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Unexpected wrapper element call found.   Expected {http://sample.com/}call.</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

知道如何解决这个问题吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

通过在接口

中声明命名空间来尝试

@WebMethod int call( @WebParam( name = "struct",targetNamespace = "some Namespace")Struct s);

现在,当您运行wsdl时,您将收到如下肥皂请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prefix="namespace declared in interface">
<soapenv:Header/>
  <soapenv:Body>
   <prefix:call>
     <prefix:struct>
        <x>201</x>
        <y>144</y>
     </prefix:struct>
  </prefix:call>
</soapenv:Body>
</soapenv:Envelope>

现在运行它。 我希望这能解决你的问题。