2012-09-18 83 views
0

我用CXF開發了一個Web服務,它工作正常。 我有兩個輸入參數的服務,它們都應該是強制性的。 但是當我打電話給我的服務只是第一個參數是強制性的。 請讓我知道我該怎麼辦?cxf中的強制請求參數

我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> 

謝謝

嗨 我在Web服務

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

增加了新的服務,並沒有這兩個參數是必須的 我應該怎麼辦?請幫我

+0

這種情況以前也討論過(http://stackoverflow.com/questions/2210346/how-can-i-make-a-webmethod-parameter-required),所以也許這將有助於? (我不確定這是否是重複的;這取決於你使用的是多個規範的版本......) –

+0

謝謝Donal,但它沒有幫助。我在我的AuthenticationRequestParam類中使用了@webParam – farhad

回答

0

我找到了我的問題。 我使用org.apache.cxf.aegis.databinding.AegisDatabinding az數據聯編程序,它只是識別原始類型az mandatory.when我表示我的輸入參數成爲強制性的。 我應該使用什麼樣的數據綁定?

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>