Axis 2 で開発された Web サービスがあります。EmployeeService と呼ばれます。
EmployeeService.java
public class EmployeeService {
public Employee getEmployee(Employee emp) {
emp.getTeam().setTeamName("TeamName");
return emp;
}
}
従業員.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 + "]";
}
}
チーム.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>
サービスが正常にデプロイされました。
Axis 1 を使用してサービスにアクセスしています。
EmployeeServiceLocator locator = new EmployeeServiceLocator();
EmployeeServicePortType endpoint = locator.getEmployeeServiceHttpSoap11Endpoint();
Employee emp = new Employee();
emp.setName( "SomeName" );
emp.setAge( new Integer( 21 ) );
emp.setEmail( "test@test.com" );
Team team = new Team();
team.setBusinessUnitName( "businessUnitName" );
emp.setTeam( team );
Employee ret = endpoint.getEmployee( emp );
TeamNameType resTeamName = ret.getTeam().getTeamName();
System.out.println( resTeamName.toString() );
結果から、resTeamName には、応答で受信するデータを取得する機能がありません。
応答をコンソールに出力すると、TeamName が応答の一部として送信されていることがわかります。
応答を出力するコード。
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>
しかし、Web サービスの結果から TeamName データにアクセスする方法が見つかりませんでした。
TeamName オブジェクトを調べると、オブジェクトを返す可能性のあるフィールドも表示されません。
誰かが試してみる必要がある場合に備えて、サービスも共有しました。
https://dl.dropbox.com/u/27532041/employee.aar
ありがとう、ポール