cxf中的强制请求参数

时间:2012-09-18 07:25:30

标签: cxf

我使用CXF开发了一个Web服务,它工作正常。 我有一个带有两个输入参数的服务,它们都是必需的。 但是当我调用我的服务时,第一个参数是强制性的。 请告诉我该怎么办?

我的SEI

@WebService(
    endpointInterface = "com.myCompany.product.webService",
    targetNamespace = "http://product.myCompany.com",
    portName = "product",
    serviceName = "ProductService")

@DataBinding(org.apache.cxf.aegis.databinding.AegisDatabinding.class)
public interface ProductService {

    @WebMethod(operationName = "authentication")
    @WebResult(name = "authenticationResponseParam")
    public AuthenticationResponseParam authentication(@WebParam(name = "user", header = true) String user,
                                 @WebParam(name = "authenticationRequestParam") AuthenticationRequestParam authenticationRequestParam);

}

和我的AuthenticationResponseParam类

@XmlAccessorType(XmlAccessType.FIELD
)

@XmlType(name = "authenticationRequestParam", propOrder = {
    "account", "password"
 })

public class AuthenticationRequestParam implements Serializable {
    @XmlElement(name = "account", required = true)
    private BigDecimal account;

    @XmlElement(name = "password", required = true)
    private String password;

    public BigDecimal getAccount() {
        return account;
    }

    public void setAccount(BigDecimal account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "AuthenticationRequestParam{" +
                "account=" + account +
                ", password='" + password + '\'' +
                '}';
    }
}

和我的CXF servlet xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:cxf="http://cxf.apache.org/core"
       xmlns:soap="http://cxf.apache.org/bindings/soap"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
       http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
       http://cxf.apache.org/bindings/soap
       http://cxf.apache.org/schemas/configuration/soap.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

    <cxf:bus>
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus>

    <!--Data binding-->
    <bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope="prototype"/>

    <bean id="jaxws-and-aegis-service-factory"
          class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
          scope="prototype">
        <property name="dataBinding" ref="aegisBean"/>
    </bean>

    <jaxws:endpoint id="telBank" implementor="#myService" address="/telBank">
        <jaxws:binding>
            <soap:soapBinding mtomEnabled="false" version="1.2"/>
        </jaxws:binding>
    </jaxws:endpoint>

    <bean id="myService" class="com.myCompany.product.webService.impl.ProductServiceImpl"/>

</beans>

谢谢

嘿伙计们 我在我的网络服务中添加了一项新服务

public BigDecimal sample(@WebParam(name = "sam1") BigDecimal a1,@WebParam(name = "sam2") BigDecimal a2);

并且这两个参数都不是必需的 我该怎么办?请帮帮我

2 个答案:

答案 0 :(得分:0)

我发现了我的问题。 我使用org.apache.cxf.aegis.databinding.AegisDatabinding az数据绑定器,它只是识别基本类型az必需的。当我推荐我的输入参数成为强制性。 我应该使用什么样的数据绑定器?

答案 1 :(得分:0)

如果要将AegisDatabinding类用作数据绑定器,请将此属性设置为bean定义。

<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope="prototype">
    <property name="configuration">
        <bean class="org.apache.cxf.aegis.type.TypeCreationOptions">
            <property name="defaultMinOccurs" value="1"/>
            <property name="defaultNillable" value="false"/>
        </bean>
    </property>
</bean>