允许带有可选命名空间的EJB 3.1 Webservice

时间:2011-11-07 09:48:26

标签: java web-services netbeans jaxb ejb

我正在使用带有NetBeans 7.0的EJB 3.1来部署WebServices。我已经从我的XSD文件中生成了类。

NetBeans为此WebServices生成WSDL文件。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jii="http//webservice.example.de/jii" xmlns:j="http://testservice.example.de/updatecheck/j">
   <soapenv:Header/>
   <soapenv:Body>
      <jii:RegisterUser>
         <j:RequestHeader>
            <Nonce>test</Nonce>
            <UserAgent>chrome</UserAgent>
            <ManualRequest>true</ManualRequest>
         </j:RequestHeader>
         <jii:UserName>test</jii:UserName>
         <jii:UserPassword>123456</jii:UserPassword>
      </jii:RegisterUser>
   </soapenv:Body>
</soapenv:Envelope>

正在运作,但是

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jii="http//webservice.example.de/jii" xmlns:j="http://testservice.example.de/updatecheck/j">
   <soapenv:Header/>
   <soapenv:Body>
      <jii:RegisterUser>
         <j:RequestHeader>
            <j:Nonce>test</j:Nonce>
            <j:UserAgent>chrome</j:UserAgent>
            <j:ManualRequest>true</j:ManualRequest>
         </j:RequestHeader>
         <jii:UserName>test</jii:UserName>
         <jii:UserPassword>123456</jii:UserPassword>
      </jii:RegisterUser>
   </soapenv:Body>
</soapenv:Envelope>

抛出javax.ejb.EJBTransactionRolledbackException。在调试时,我看到Nonce,UserAgent和ManualRequest参数为空。

WebService在无状态Bean中注释,如:

@WebService(name = "TestII", serviceName = "TestService", targetNamespace = "http//webservice.example.de/jii")
@Stateless()
public class TestServiceProvider {

@WebMethod(operationName = "RegisterUser")
    @WebResult(name = "RegisterUserResult", targetNamespace = "http//webservice.example.de/jii")
    public RegisterUserResult registerUser(
            @WebParam(name = "RequestHeader", targetNamespace = "http://testservice.example.de/updatecheck/j") @XmlElement(required = true, nillable = false) RequestHeader requestHeader,
            @WebParam(name = "UserEmail", targetNamespace = "http//webservice.example.de/jii") @XmlElement(required = true, nillable = false) String userEmail,
            @WebParam(name = "UserPassword", targetNamespace = "http//webservice.example.de/jii") @XmlElement(required = true, nillable = false) String userPassword) {

//logic
}
}

通过XML Schema生成的复杂类型Request Header:

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.2-147 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2011.11.07 at 10:31:16 AM MEZ 
//



import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for RequestHeader complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="RequestHeader">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="Nonce" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="UserAgent" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="ManualRequest" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "RequestHeader", propOrder = {
    "nonce",
    "userAgent",
    "manualRequest"
})
public class RequestHeader {

    @XmlElement(name = "Nonce", required = true)
    protected String nonce;
    @XmlElement(name = "UserAgent", required = true)
    protected String userAgent;
    @XmlElement(name = "ManualRequest")
    protected boolean manualRequest;

    /**
     * Gets the value of the nonce property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getNonce() {
        return nonce;
    }

    /**
     * Sets the value of the nonce property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setNonce(String value) {
        this.nonce = value;
    }

    /**
     * Gets the value of the userAgent property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getUserAgent() {
        return userAgent;
    }

    /**
     * Sets the value of the userAgent property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setUserAgent(String value) {
        this.userAgent = value;
    }

    /**
     * Gets the value of the manualRequest property.
     * 
     */
    public boolean isManualRequest() {
        return manualRequest;
    }

    /**
     * Sets the value of the manualRequest property.
     * 
     */
    public void setManualRequest(boolean value) {
        this.manualRequest = value;
    }

}

两个SOAP-Request都是相同的。第一个没有命名空间,第二个没有命名空间。任何知道如果我在第二个SOAP请求中看到带有名称空间的EJB容器时,EJB容器无法找到参数的人吗?

谢谢!

0 个答案:

没有答案