Java Web services performance optimization

From , 5 Years ago, written in Java, viewed 185 times.
URL https://pastebin.vip/view/c32d9bf2
  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.                         SOAPBody body = msg.getSOAPBody();
  9.                         Node port = body.getChildNodes().item(0);
  10.                         String portContent = port.toString();
  11.                         NodeList list = port.getChildNodes();
  12.                         for (int i = 0; i < list.getLength(); i++) {
  13.                                 port.removeChild(list.item(i));
  14.                         }
  15.                         ByteArrayOutputStream outArr = new ByteArrayOutputStream();
  16.                         GZIPOutputStream zip = new GZIPOutputStream(outArr);
  17.                         zip.write(portContent.getBytes());
  18.                         zip.flush();
  19.                         zip.close();
  20.                         byte[] arr = outArr.toByteArray();
  21.                         TestDataSource ds = new TestDataSource(arr);
  22.                         AttachmentPart attPart = msg.createAttachmentPart();
  23.                         attPart.setDataHandler(new DataHandler(ds));
  24.                         msg.addAttachmentPart(attPart);
  25.                 } catch (SOAPException e) {
  26.                         e.printStackTrace();
  27.                 } catch (IOException e) {
  28.                         e.printStackTrace();
  29.                 }
  30.         }
  31.         return true;
  32. }
  33.  
  34.  
  35. public boolean handleMessage(MessageContext arg0) {
  36.         SOAPMessageContext ct = (SOAPMessageContext) arg0;
  37.         boolean isRequestFlag = (Boolean) arg0
  38.                         .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
  39.         SOAPMessage msg = ct.getMessage();
  40.         if (!isRequestFlag) {
  41.                 try {
  42.                         Object obj = ct.get("Attachments");
  43.                         Attachments atts = (Attachments) obj;
  44.                         List list = atts.getContentIDList();
  45.                         for (int i = 1; i < list.size(); i++) {
  46.                                 String id = (String) list.get(i);
  47.                                 DataHandler d = atts.getDataHandler(id);
  48.                                 InputStream in = d.getInputStream();
  49.                                 ByteArrayOutputStream out = new ByteArrayOutputStream();
  50.                                 GZIPInputStream zip = new GZIPInputStream(in);
  51.                                 byte[] arr = new byte[1024];
  52.                                 int n = 0;
  53.                                 while ((n = zip.read(arr)) > 0) {
  54.                                         out.write(arr, 0, n);
  55.                                 }
  56.                                 Document doc = DocumentBuilderFactory.newInstance()
  57.                                                 .newDocumentBuilder()
  58.                                                 .parse(new ByteArrayInputStream(out.toByteArray()));
  59.                                 SOAPBody body = msg.getSOAPBody();
  60.                                 Node port = body.getChildNodes().item(0);
  61.                                 port.appendChild(doc.getFirstChild().getFirstChild());
  62.                         }
  63.                 } catch (SOAPException e) {
  64.                         e.printStackTrace();
  65.                 } catch (IOException e) {
  66.                         e.printStackTrace();
  67.                 } catch (SAXException e) {
  68.                         e.printStackTrace();
  69.                 } catch (ParserConfigurationException e) {
  70.                         e.printStackTrace();
  71.                 }
  72.         }
  73.         return true;
  74. }
  75.  
  76.  
  77.  
  78.  
  79. <handler-chains>
  80. <handler-chain>
  81.         <handler>
  82.                 <handler-name>TestClientHandler</handler-name>
  83.                 <handler-class>test.TestClientHandler</handler-class>
  84.         </handler>
  85. </handler-chain>
  86. </handler-chains>
  87.  

Reply to "Java Web services performance optimization"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website