いつまで続くか分かりませんが、 情報発信を開始しました。
/** * */ package jp.blogspot.tanakanbb; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.StringWriter; import java.net.URL; import java.net.URLConnection; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPMessage; import javax.xml.soap.SOAPPart; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import org.w3c.dom.Document; import com.tanakanbb.sample.soap.SayHello; import com.tanakanbb.sample.soap.SayHelloResponse; public class JaxWSExecutor { public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().newDocument(); JAXBContext context = JAXBContext.newInstance(SayHello.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); SayHello sayHello = new SayHello(); sayHello.setName("hoge"); marshaller.marshal(sayHello, doc); // We now have a DOM tree which has been populated by JAX-B MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); message.getSOAPBody().addDocument(doc); message.saveChanges(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); message.writeTo(outputStream); String xml = outputStream.toString("utf-8"); // hoge System.out.println(xml); try { URL url = new URL( "http://localhost:8084/soap_sample/services/Hello"); URLConnection con = url.openConnection(); // 送信するよ!指定 con.setDoOutput(true); con.setRequestProperty("Content-Type", "application/soap+xml"); con.setRequestProperty("SoapAction", ""); // -------------------- // 送信する // -------------------- OutputStreamWriter ow1 = new OutputStreamWriter(con .getOutputStream()); BufferedWriter bw1 = new BufferedWriter(ow1); // POSTの内容を書き出す bw1.write(xml); // クローズ bw1.close(); ow1.close(); // -------------------- // 受信する // -------------------- InputStreamReader ir1 = new InputStreamReader(con.getInputStream()); BufferedReader br1 = new BufferedReader(ir1); ByteArrayOutputStream ba = new ByteArrayOutputStream(); // 1行ずつ書き出す int b; while ((b = br1.read()) != -1) { ba.write(b); } String response = ba.toString("utf-8"); // クローズ br1.close(); ir1.close(); ba.close(); // Hello!, hoge System.out.println(response); // Create SoapMessage MessageFactory msgFactory = MessageFactory.newInstance(); SOAPMessage message2 = msgFactory.createMessage(); SOAPPart soapPart = message2.getSOAPPart(); // Load the SOAP text into a stream source byte[] buffer = response.getBytes(); ByteArrayInputStream stream = new ByteArrayInputStream(buffer); StreamSource source = new StreamSource(stream); // Set contents of message soapPart.setContent(source); // -- DONE // Hello!, hoge message2.writeTo(System.out); System.out.println(""); org.w3c.dom.Node srcNode = message2.getSOAPPart().getEnvelope() .getBody().getFirstChild(); StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance() .newTransformer(); transformer.transform(new DOMSource(srcNode), new StreamResult( writer)); // Hello!, hoge System.out.println(writer.toString()); JAXBContext context2 = JAXBContext .newInstance(SayHelloResponse.class); Unmarshaller m = context2.createUnmarshaller(); Object obj = m.unmarshal(srcNode); SayHelloResponse ret = (SayHelloResponse) obj; // Hello!, hoge System.out.println(ret.getSayHelloReturn()); } catch (Exception e) { e.printStackTrace(); } } }