用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

Java Web 服务性能优化

2014-12-28 作者: java源代码大全举报

[java]代码库

public boolean handleMessage(MessageContext arg0) { 
	SOAPMessageContext ct = (SOAPMessageContext) arg0; 
	boolean isRequestFlag = (Boolean) arg0 
			.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); 
	SOAPMessage msg = ct.getMessage(); 
	if (isRequestFlag) { 
		try { 
			SOAPBody body = msg.getSOAPBody(); 
			Node port = body.getChildNodes().item(0); 
			String portContent = port.toString(); 
			NodeList list = port.getChildNodes(); 
			for (int i = 0; i < list.getLength(); i++) { 
				port.removeChild(list.item(i)); 
			} 
			ByteArrayOutputStream outArr = new ByteArrayOutputStream(); 
			GZIPOutputStream zip = new GZIPOutputStream(outArr); 
			zip.write(portContent.getBytes()); 
			zip.flush(); 
			zip.close(); 
			byte[] arr = outArr.toByteArray(); 
			TestDataSource ds = new TestDataSource(arr); 
			AttachmentPart attPart = msg.createAttachmentPart(); 
			attPart.setDataHandler(new DataHandler(ds)); 
			msg.addAttachmentPart(attPart); 
		} catch (SOAPException e) { 
			e.printStackTrace(); 
		} catch (IOException e) { 
			e.printStackTrace(); 
		} 
	} 
	return true; 
}


public boolean handleMessage(MessageContext arg0) { 
	SOAPMessageContext ct = (SOAPMessageContext) arg0; 
	boolean isRequestFlag = (Boolean) arg0 
			.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); 
	SOAPMessage msg = ct.getMessage(); 
	if (!isRequestFlag) { 
		try { 
			Object obj = ct.get("Attachments"); 
			Attachments atts = (Attachments) obj; 
			List list = atts.getContentIDList(); 
			for (int i = 1; i < list.size(); i++) { 
				String id = (String) list.get(i); 
				DataHandler d = atts.getDataHandler(id); 
				InputStream in = d.getInputStream(); 
				ByteArrayOutputStream out = new ByteArrayOutputStream(); 
				GZIPInputStream zip = new GZIPInputStream(in); 
				byte[] arr = new byte[1024]; 
				int n = 0; 
				while ((n = zip.read(arr)) > 0) { 
					out.write(arr, 0, n); 
				} 
				Document doc = DocumentBuilderFactory.newInstance() 
						.newDocumentBuilder() 
						.parse(new ByteArrayInputStream(out.toByteArray())); 
				SOAPBody body = msg.getSOAPBody(); 
				Node port = body.getChildNodes().item(0); 
				port.appendChild(doc.getFirstChild().getFirstChild()); 
			} 
		} catch (SOAPException e) { 
			e.printStackTrace(); 
		} catch (IOException e) { 
			e.printStackTrace(); 
		} catch (SAXException e) { 
			e.printStackTrace(); 
		} catch (ParserConfigurationException e) { 
			e.printStackTrace(); 
		} 
	} 
	return true; 
}




<handler-chains> 
<handler-chain> 
	<handler> 
		<handler-name>TestClientHandler</handler-name> 
		<handler-class>test.TestClientHandler</handler-class> 
	</handler> 
</handler-chain> 
</handler-chains>


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...