删除元素< return>在JAX-WS SOAP响应中 [英] Remove element <return> in JAX-WS SOAP Response

查看:82
本文介绍了删除元素< return>在JAX-WS SOAP响应中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下JAX-WS方法

I'm having the following JAX-WS method

public School createUpdateSchool(Perks reqeustData, DataHandler contentData)
{
----
----
}

在我的SOAP响应中,

And in my SOAP response,

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:CreateUpdateSchoolResponse xmlns:ns2=".........">
<return>
<ns2:Student name="Raj" ......
<ns2:Exam pattern="CBSE"............       
............    
</return>
</ns3:CreateUpdateSchoolResponse>
</S:Body>
</S:Envelope> 

事实上,我可以自定义该元素,但是无法从soap响应中将其完全删除.

In fact I can able to customize the element but i'm unable to remove it altogether from the soap response.

  • 是否可以通过某些配置将其删除?
  • 如果不是,那么至少如何通过SOAP处理程序来做到这一点?

任何帮助将不胜感激.

推荐答案

我遇到了同样的问题,并且找不到删除服务响应标签返回的另一种方法,我发现的唯一方法是实现SOAP处理程序,如下所示:

I have same problem, and could not find another way to remove the tag return of service response, the only way I found was to implement SOAP Handler as follows:

希望这会有所帮助,祝您好运!

Hope this helps, good luck!

import java.util.Iterator;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.Node;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

import org.w3c.dom.NodeList;

import com.millicom.LoggerFFE;
import com.millicom.fulfillment.ws.cin.utils.ConnectorsLoggerUtil;

/**
 * @author jcperez
 * 
 */
public class SOAPLoggingHandler implements SOAPHandler<SOAPMessageContext> {

    protected static LoggerFFE logger=ConnectorsLoggerUtil.getLogger(SOAPLoggingHandler.class);

    @Override
    public boolean handleMessage(SOAPMessageContext context) {

        Boolean outboundProperty = (Boolean) context
                .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        //Verificamos solo los mensajes de salida
        if(outboundProperty){

            try {
                //Obtenemos el mensaje
                SOAPMessage message = context.getMessage();

                //Obtenemos los elementos del cuerpo
                @SuppressWarnings("unchecked")
                Iterator<Node> it = message.getSOAPBody().getChildElements();

                //Obtenemos el primero nodo, el que corresponde al response de la operacion
                Node node = (Node) it.next();

                //Obtenemos el nodo return
                org.w3c.dom.Node returnNode = node.getChildNodes().item(0);
                //Obtenemos los nodos hijos en una varaible temporal
                NodeList nodeList = returnNode.getChildNodes();
                //Eliminamos el nodo return
                node.removeChild(returnNode);
                //Agregamos los hijos del nodo return al nodo response de la operacion
                while(nodeList.getLength() > 0){
                   node.appendChild(nodeList.item(0));
                }

            } catch (SOAPException e) {
               logger.error("SOAPLoggingHandler#handleMessage(context) Error al obtener el body del mensaje SOAP ", e);
            } catch (Exception e) {
                logger.error("SOAPLoggingHandler#handleMessage(context) Error general ", e);
            }

        }

        return true;
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        //do nothing
        return true;
    }

    @Override
    public void close(MessageContext context) {
      //do nothing
    }

    @Override
    public Set<QName> getHeaders() {
        return null;
    }

}

这篇关于删除元素&lt; return&gt;在JAX-WS SOAP响应中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆