Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在SOAPHandler中不进行任何转换就发送xml_Java_Web Services_Websphere_Jax Ws_Handlers - Fatal编程技术网

Java 如何在SOAPHandler中不进行任何转换就发送xml

Java 如何在SOAPHandler中不进行任何转换就发送xml,java,web-services,websphere,jax-ws,handlers,Java,Web Services,Websphere,Jax Ws,Handlers,ibmwebspherejax-WS-RI框架。 我有一个笨蛋。 我需要向客户端发送一行xml响应。 我制作了一行xml。调试表明一切正常-xml是单行的。 但在发送框架之前,请生成一个“漂亮的打印”输出。 签名需要它,任何xml转换都不需要它。 一般问题:如何在SOAPHandler中发送xml数据而不进行任何转换 public class SignHandler implements SOAPHandler<SOAPMessageContext>{ priva

ibmwebspherejax-WS-RI框架。 我有一个笨蛋。 我需要向客户端发送一行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;
    }
public类SignHandler实现SOAPHandler{
私有字符串makeOneLineXml(字符串xml)引发IOException{
BufferedReader br=新的BufferedReader(新的StringReader(xml));
字符串行=null;
StringBuilder sb=新的StringBuilder();
而((line=br.readLine())!=null){
sb.append(line.trim());
}
使某人返回字符串();
}
公共布尔handleMessage(SOAPMessageContext上下文){
Boolean isRequest=(Boolean)context.get(MessageContext.MESSAGE\u OUTBOUND\u属性);
//仅对于响应消息,对于出站消息为true,对于入站消息为false
如果(isRequest){
试一试{
SOAPMessage soapMsg=context.getMessage();
SOAPEnvelope soapEnv=soapMsg.getSOAPPart().getEnvelope();
SOAPHeader-SOAPHeader=soapEnv.getHeader();
Document orig=soapEnv.getOwnerDocument();
来源=
//我需要向客户端发送一行xml
反序列化(makeOneLineXml(XmlUtils.serializeNode(signedSoap,false,false));
saveChanges();
//追踪
soapMsg.writeTo(System.out);//在控制台中,所有ok.Xml都是一行
}捕获(SOAPE例外){
系统错误println(e);
}捕获(IOE异常){
系统错误println(e);
}
}
//继续其他处理程序链
返回true;
}

我在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_字符串。 它对于xmldsig、jax和wss安全问题非常有用