Java 无法将同级节点添加到soap响应中
大家好,我需要生成soap响应,如下所示。我已将其生成到“GetTestDetailResult”节点。但无法将“country”添加为根节点(GetTestDetailResponse)的子节点 我还不能发表评论(没有足够的代表性)来澄清,但当您说您不能将Java 无法将同级节点添加到soap响应中,java,xml,soap,xsd,wsdl,Java,Xml,Soap,Xsd,Wsdl,大家好,我需要生成soap响应,如下所示。我已将其生成到“GetTestDetailResult”节点。但无法将“country”添加为根节点(GetTestDetailResponse)的子节点 我还不能发表评论(没有足够的代表性)来澄清,但当您说您不能将国家添加为GetTestDetailResponse的子元素时,我假设您收到了一个XML无效错误 查看WSDL中的XML模式,没有定义country元素 <xs:element name="GetTestDetailResponse
国家
添加为GetTestDetailResponse
的子元素时,我假设您收到了一个XML无效错误
查看WSDL中的XML模式,没有定义country
元素
<xs:element name="GetTestDetailResponse" type="tns:GetTestDetailResponse"/>
因此,将类型更改为类似以下内容应该可以:
<xs:complexType name="GetTestDetailResponse">
<xs:sequence>
<xs:element minOccurs="1" name="GetTestDetailResult" type="tns:GetTestDetailResult"/>
<xs:element minOccurs="0" name="country" type="xs:string"/>
<xs:element minOccurs="0" name="age" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
我还添加了年龄,因为这会有类似的问题。Mike当我尝试添加以下行时,应用程序不会出现@sumit verma当你说“不上来”时,你会得到一个具体的错误吗?您还向Java类添加了注释吗?消息:创建名为“testServiceWsdlEndpointBean”的bean时出错:bean的实例化失败;嵌套异常是org.springframework.beans.factory.BeanDefinitionStoreException:factory方法[public org.apache.cxf.endpoint.Server org.apache.cxf.jaxws.JaxWsServerFactoryBean.create()]抛出异常;嵌套异常是java.lang.NullPointerExceptionI,我看不到日志。不知道StackOverflow把它们放在哪里。我建议为您的JAXB对象编写一个测试用例,看看是否生成了预期的XML。根据发布的Java代码,这似乎是不完整的。以下是日志:-消息:创建名为“testServiceWsdlEndpointBean”的bean时出错:bean的实例化失败;嵌套异常是org.springframework.beans.factory.BeanDefinitionStoreException:factory方法[public org.apache.cxf.endpoint.Server org.apache.cxf.jaxws.JaxWsServerFactoryBean.create()]抛出异常;嵌套异常是java.lang.NullPointerException您可以发布错误消息吗?
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "testDetail", propOrder = {
"id",
"fname",
"lname"
})
public class TestDetail {
protected String id;
protected String fname;
protected String lname;
protected String authFailed;
protected String soapMessage;
public String getId() {
return id;
}
public void setId(String value) {
this.id = value;
}
public String getFname() {
return fname;
}
public void setFname(String value) {
this.fname = value;
}
public String getLname() {
return lname;
}
public void setLname(String value) {
this.lname = value;
}
public String getAuthFailed() {
return authFailed;
}
public void setAuthFailed(String value) {
this.authFailed = value;
}
public String getSoapMessage() {
return soapMessage;
}
public void setSoapMessage(String value) {
this.soapMessage = value;
}
}
<xs:element name="GetTestDetailResponse" type="tns:GetTestDetailResponse"/>
<xs:complexType name="GetTestDetailResponse">
<xs:sequence>
<xs:element minOccurs="1" name="GetTestDetailResult" type="tns:GetTestDetailResult"/>
<xs:element minOccurs="0" name="country" type="xs:string"/>
<xs:element minOccurs="0" name="age" type="xs:integer"/>
</xs:sequence>
</xs:complexType>