显示从servlet到JSP页面的Web Service Adapter调用

时间:2018-01-24 02:08:19

标签: java web-services soap soap-client

我有如下的java servlet代码:

// splits the string
Stage<String, String[]> splitter = dataItem -> new DataItem<>(dataItem.data.split(" "));
// converts each string from the array to an integer
Stage<String[], List<Integer>> transformer = dataItem -> 
    new DataItem<>(Arrays.stream(dataItem.data)
        .map(Integer::parseInt).collect(Collectors.toList()));
// sums all integers
Stage<List<Integer>, Integer> accumulator = dataItem -> 
    new DataItem<>(dataItem.data.stream().reduce(0, Integer::sum));

DataItem<String> in = new DataItem<>("1 35 42 2 10 5 2 3");
DataItem<Integer> out = in.process(splitter).process(transformer).process(accumulator);

System.out.println(out.data); // prints 100

当我尝试使用protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); String code = request.getParameter("code"); String myNamespace = "wsad"; String myNamespaceURI = "http://ws.iris.co.id/wsadev"; SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration(myNamespace, myNamespaceURI); SOAPBody soapBody = soapEnvelope.getBody(); /*SOAPBody soapBody = envelope.getBody();*/ SOAPElement soapBodyElem = soapBody.addChildElement("getItem", myNamespace); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("iDomain", myNamespace); SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("iCode", myNamespace); soapBodyElem1.addTextNode("PLS"); soapBodyElem2.addTextNode(code); Source source = soapPart.getContent(); /*Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(root), new StreamResult(System.out));*/ SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); String soapEndpointUrl = "http://svrqad:8080/wsadev/services/"; String soapAction = "http://schemas.xmlsoap.org/soap/envelope/"; // Send SOAP Message to SOAP Server SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(soapAction), soapEndpointUrl); JSONArray list = new JSONArray(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); Source sourceContent = soapResponse.getSOAPPart().getContent(); //String source = sourceContent.toString(); StreamResult result = new StreamResult(System.out); /*transformer.transform(sourceContent, result);*/ /*result.setOutputStream(out);*/ transformer.transform(sourceContent, result); result.setOutputStream(out); response.setContentType("text/html"); PrintWriter out = response.getWriter(); RequestDispatcher view = request.getRequestDispatcher("GetItem.jsp"); view.forward(request, response); } catch (Exception ex) { } } 时,它运行正常。我想在JSP页面上显示代码的响应,有人可以帮我吗? 这是输出图像。

enter image description here

0 个答案:

没有答案