JAVAでSOAPメッセージをJAXBを使用してBeanにマッピングしたいのですがうまくいきません。
何かおかしなところがあれば教えていただきたいです。どうぞよろしくお願いします。
###該当のソースコード
XML
1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 3 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 4 xmlns:ns1="urn:Samplewsdl" 5 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 6 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 7 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 8 <SOAP-ENV:Header /> 9 <SOAP-ENV:Body> 10 <ns1:sampleResponse> 11 <return xsi:type="ns1:sampleInfo"> 12 <name xsi:type="xsd:string">名前</name> 13 <address xsi:type="xsd:string">住所</address> 14 </return> 15 </ns1:sampleResponse> 16 </SOAP-ENV:Body> 17</SOAP-ENV:Envelope>
java
1@XmlAccessorType(XmlAccessType.FIELD) 2@XmlRootElement(name = "return") 3public class SearchSample { 4 5 private String name; 6 private String address; 7 8 public String getName() { 9 return name; 10 } 11 12 public void setName(String name) { 13 this.name = name; 14 } 15 16 public String getAddress() { 17 return address; 18 } 19 20 public void setAddress(String address) { 21 this.address = address; 22 }
Java
1 public void unMarshal() { 2 String xml="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:Samplewsdl\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><SOAP-ENV:Header /><SOAP-ENV:Body><ns1:sampleResponse><return xsi:type=\"ns1:sampleInfo\"><name xsi:type=\"xsd:string\">名前</name><address xsi:type=\"xsd:string\">住所</address></return></ns1:sampleResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> 3"; 4 SearchSample searchSample = JAXB.unmarshal(new StringReader(xml), SearchSample.class); 5 }
あなたの回答
tips
プレビュー