【问题标题】:mandatory request param in cxfcxf 中的强制请求参数
【发布时间】:2012-09-10 10:28:33
【问题描述】:

我用 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);

这两个参数都不是强制性的 我该怎么办?请帮帮我

【问题讨论】:

  • 这个问题之前已经讨论过 (stackoverflow.com/questions/2210346/…) 所以也许这会有所帮助? (我不确定这是否是重复的;这取决于您使用的多个规格的版本……)
  • 谢谢 Donal,但这没有帮助。我在 AuthenticationRequestParam 类中使用了@webParam

标签: cxf


【解决方案1】:

我发现了我的问题。 我使用 org.apache.cxf.aegis.databinding.AegisDatabinding az 数据绑定器,它只识别原始类型 az 强制。当我推荐我的输入参数成为强制时。 我应该使用哪种数据绑定器?

【讨论】:

    【解决方案2】:

    如果您想使用 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      • 2014-12-31
      • 1970-01-01
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多