Java Axis 1能否在限制条件下工作
我在Axis 2中开发了一个web服务。叫雇员服务 EmployeeService.javaJava Axis 1能否在限制条件下工作,java,web-services,axis2,axis,Java,Web Services,Axis2,Axis,我在Axis 2中开发了一个web服务。叫雇员服务 EmployeeService.java public class EmployeeService { public Employee getEmployee(Employee emp) { emp.getTeam().setTeamName("TeamName"); return emp; } } Employee.java public class Employee { priv
public class EmployeeService {
public Employee getEmployee(Employee emp) {
emp.getTeam().setTeamName("TeamName");
return emp;
}
}
Employee.java
public class Employee {
private String name;
private int age;
private String email;
private Team team;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Team getTeam() {
return team;
}
public void setTeam(Team team) {
this.team = team;
}
@Override
public String toString() {
return "Employee [name=" + name + ", age=" + age + ", email=" + email
+ ", team=" + team + "]";
}
}
Team.java
public class Team {
private String businessUnitName;
private String teamName;
public String getBusinessUnitName() {
return businessUnitName;
}
public void setBusinessUnitName(String businessUnitName) {
this.businessUnitName = businessUnitName;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
@Override
public String toString() {
return "Team [businessUnitName=" + businessUnitName + ", teamName="
+ teamName + "]";
}
}
对于团队POJO中的teamName字段,我在WSDL中添加了一个限制,并且我正在使用自定义WSDL
<simpleType name="teamNameType">
<restriction base="string">
<minLength value="0"/>
<maxLength value="80"/>
</restriction>
</simpleType>
从结果来看,resTeamName没有任何函数来获取响应中的数据
Call call = ( ( org.apache.axis.client.Stub ) endpoint )._getCall();
SOAPEnvelope envelope = call.getResponseMessage().getSOAPEnvelope();
Document doc = envelope.getAsDocument();
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.setOutputProperty( OutputKeys.METHOD, "xml" );
trans.setOutputProperty( OutputKeys.INDENT, "yes" );
trans.setOutputProperty( "{http://xml.apache.org/xslt}indent-amount", Integer.toString( 2 ) );
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult( sw );
DOMSource source = new DOMSource( doc );
trans.transform( source, result );
String xmlString = sw.toString();
System.out.println( xmlString );
如果我将响应打印到控制台,我可以看到团队名称是响应的一部分
Call call = ( ( org.apache.axis.client.Stub ) endpoint )._getCall();
SOAPEnvelope envelope = call.getResponseMessage().getSOAPEnvelope();
Document doc = envelope.getAsDocument();
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.setOutputProperty( OutputKeys.METHOD, "xml" );
trans.setOutputProperty( OutputKeys.INDENT, "yes" );
trans.setOutputProperty( "{http://xml.apache.org/xslt}indent-amount", Integer.toString( 2 ) );
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult( sw );
DOMSource source = new DOMSource( doc );
trans.transform( source, result );
String xmlString = sw.toString();
System.out.println( xmlString );
用于打印响应的代码
Call call = ( ( org.apache.axis.client.Stub ) endpoint )._getCall();
SOAPEnvelope envelope = call.getResponseMessage().getSOAPEnvelope();
Document doc = envelope.getAsDocument();
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.setOutputProperty( OutputKeys.METHOD, "xml" );
trans.setOutputProperty( OutputKeys.INDENT, "yes" );
trans.setOutputProperty( "{http://xml.apache.org/xslt}indent-amount", Integer.toString( 2 ) );
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult( sw );
DOMSource source = new DOMSource( doc );
trans.transform( source, result );
String xmlString = sw.toString();
System.out.println( xmlString );
打印的答复是
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getEmployeeResponse xmlns:ns="http://employee">
<ns:return>
<ns:age>21</ns:age>
<ns:email>test@test.com</ns:email>
<ns:name>SomeName</ns:name>
<ns:team>
<ns:businessUnitName>businessUnitName</ns:businessUnitName>
<ns:teamName>TeamName</ns:teamName>
</ns:team>
</ns:return>
</ns:getEmployeeResponse>
</soapenv:Body>
</soapenv:Envelope>
21
test@test.com
名字
业务单位名称
团队名称
但是我找不到任何方法从web服务的结果访问TeamName数据
如果我检查TeamName对象,那么我也看不到任何可以返回该对象的字段
我也分享了我的服务,以防有人需要尝试
谢谢,
保罗遇到了这个错误。
请参考Tom Jordahl的评论
“此时,轴1.x不支持此类限制。”
和
“没有计划在Axis1.x中支持这一点。Axis2正在使用XMLBeans,我相信它会生成代码来实施限制。”您的WSDL基本上是不正确的。我查看了AAR文件中的WSDL,发现
simpleType
定义及其子体没有正确的名称空间。在Eclipse中,只需右键单击WSDL文件并选择“验证”,然后更正报告的错误。一旦WSDL文件正确,Axis1.x应该能够生成一个存根,允许您设置teamName
属性。但是(正如我在对K Vikas Chandran的评论中所解释的),Axis 1.x不会强制执行minLength
/maxLength
限制面。Axis-119并没有说Axis 1.x根本不支持这种类型的限制(您需要在上下文中阅读Tom的评论);它只是说忽略了限制方面(而不是枚举)。在Paul的例子中,这意味着Axis1.x不会对minLength
/maxLength
面执行任何操作。但是,仍然需要将teamNameType
映射到java.lang.String
,Paul应该能够为teamName
属性设置一个值。