1

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;
    }
4

1 回答 1

0

我在 SoapUI 中进行的所有测试。但默认情况下,soapUI 响应是漂亮打印格式的。所有的问题都在这。

要替换 SoapMessage 中的可选soap xml,您可以使用以下命令:

 private SOAPMessage makeSOAPMessage(String msg)
        {
        try {

            SOAPMessage message = MessageFactory.newInstance().createMessage();

            StringReader sReader = new StringReader(msg);                        

            message.getSOAPPart().setContent(new StreamSource(sReader));
            message.saveChanges();
             return message;
        }
        catch (Exception e) {
            return null;
        }
        }   
.....................

 context.setMessage(makeSOAPMessage(yours_xml_string));

在此之后,您会在客户端收到这个 xml_string。它对 xmldsig、​​jax-wss 安全问题很有用。

于 2012-07-31T12:40:20.170 回答