IBM WebSphere Jax-WS RI 框架。我有一个chunckHandler。我需要向客户端发送一行 xml 响应。我制作单行 xml。调试显示一切正常 - xml 是单行的。但在发送框架之前进行“漂亮打印”输出。它需要签名并且不需要任何 xml 转换。一般问题:如何在 SOAPHandler 中不进行任何转换就发送 xml 数据。
public class SignHandler implements SOAPHandler<SOAPMessageContext>{
private String makeOneLineXml(String xml) throws IOException{
BufferedReader br = new BufferedReader(new StringReader(xml));
String line=null;
StringBuilder sb = new StringBuilder();
while((line=br.readLine())!= null){
sb.append(line.trim());
}
return sb.toString();
}
public boolean handleMessage(SOAPMessageContext context) {
Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
//for response message only, true for outbound messages, false for inbound
if(isRequest){
try{
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
Document orig = soapEnv.getOwnerDocument();
orig =
// I need send to client one-line-xml
XmlUtils.deserialize(makeOneLineXml(XmlUtils.serializeNode(signedSoap, false, false)));
soapMsg.saveChanges();
//tracking
soapMsg.writeTo(System.out); // In CONSOLE ALL ok. Xml is one line
}catch(SOAPException e){
System.err.println(e);
}catch(IOException e){
System.err.println(e);
}
}
//continue other handler chain
return true;
}