[Java] Java Web 服务性能优化实践 →→→→→进入此内容的聊天室

来自 , 2021-04-05, 写在 Java, 查看 133 次.
URL http://www.code666.cn/view/6f3e29a3
  1. public boolean handleMessage(MessageContext arg0) {
  2.         SOAPMessageContext ct = (SOAPMessageContext) arg0;
  3.         boolean isRequestFlag = (Boolean) arg0
  4.                         .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
  5.         SOAPMessage msg = ct.getMessage();
  6.         if (!isRequestFlag) {
  7.                 try {
  8.                         Object obj = ct.get("Attachments");
  9.                         Attachments atts = (Attachments) obj;
  10.                         List list = atts.getContentIDList();
  11.                         for (int i = 1; i < list.size(); i++) {
  12.                                 String id = (String) list.get(i);
  13.                                 DataHandler d = atts.getDataHandler(id);
  14.                                 InputStream in = d.getInputStream();
  15.                                 ByteArrayOutputStream out = new ByteArrayOutputStream();
  16.                                 GZIPInputStream zip = new GZIPInputStream(in);
  17.                                 byte[] arr = new byte[1024];
  18.                                 int n = 0;
  19.                                 while ((n = zip.read(arr)) > 0) {
  20.                                         out.write(arr, 0, n);
  21.                                 }
  22.                                 Document doc = DocumentBuilderFactory.newInstance()
  23.                                                 .newDocumentBuilder()
  24.                                                 .parse(new ByteArrayInputStream(out.toByteArray()));
  25.                                 SOAPBody body = msg.getSOAPBody();
  26.                                 Node port = body.getChildNodes().item(0);
  27.                                 port.appendChild(doc.getFirstChild().getFirstChild());
  28.                         }
  29.                 } catch (SOAPException e) {
  30.                         e.printStackTrace();
  31.                 } catch (IOException e) {
  32.                         e.printStackTrace();
  33.                 } catch (SAXException e) {
  34.                         e.printStackTrace();
  35.                 } catch (ParserConfigurationException e) {
  36.                         e.printStackTrace();
  37.                 }
  38.         }
  39.         return true;
  40. }//源代码片段来自云代码http://yuncode.net
  41.                        

回复 "Java Web 服务性能优化实践"

这儿你可以回复上面这条便签

captcha