赛迪网 > IT技术 Java > 架构-与-模式
  IT资讯搜索
 
IT产品搜索
[程序开发][网管世界][网络安全][数据库技术]
[操作系统][嘉宾聊天·在线访谈][活动集锦]
[精彩专题][Symantec专区][订阅IT技术周刊]
[开发论坛][网管论坛][安全论坛][数据库论坛]
[操作系统论坛][Sybase专区][IBM dW技术专区]
[病毒求助][病毒与漏洞播报][文档·源码下载]

axis2中对soapfault的处理的一个小bug

发布时间:2008.01.23 04:56     来源:赛迪网    作者:gjs0064114

由于项目的需要,需要axis2的客户端能够对服务端返回的soap fault 进行处理。但在实际中发现axis2对soapfault处理中有问题
首先,(1)明确一下axis2 engine  接收到的soapfault 消息的格式:

HTTP/1.1 500 Internal Server Error

Server: gSOAP/2.7

Content-Type: text/xml; charset=utf-8

Content-Length: 1916

Connection: close




   
                  error String
                  error code 
               
            
         
      
   
(2)在axis2将soapfault消息封装到axisfault的代码如下:
 org.apache.axis2.clientapi.OutMEPClient.java
.....

    public MessageContext invokeBlocking(OperationDescription axisop,
                                         final MessageContext msgctx)
            throws AxisFault {
        prepareInvocation(axisop, msgctx);

        // The message ID is sent all the time
        String messageID = String.valueOf(System.currentTimeMillis());
        msgctx.setMessageID(messageID);
        //
        if (useSeparateListener) {
            //This mean doing a Request-Response invocation using two channel. If the
            //transport is two way transport (e.g. http) Only one channel is used (e.g. in http cases
            //202 OK is sent to say no repsone avalible). Axis2 get blocked return when the response is avalible.

            SyncCallBack callback = new SyncCallBack();
            //this method call two channel non blocking method to do the work and wait on the callbck
            invokeNonBlocking(axisop, msgctx, callback);
            long index = timeOutInMilliSeconds / 100;
            while (!callback.isComplete()) {
                //wait till the reponse arrives
                if (index-- >= 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw new AxisFault(e);
                    }
                } else {
                    throw new AxisFault(Messages.getMessage("responseTimeOut"));
                }
            }
            //process the resule of the invocation
            if (callback.envelope != null) {
                MessageContext resMsgctx =
                        new MessageContext(serviceContext.getEngineContext());
                resMsgctx.setEnvelope(callback.envelope);
                return resMsgctx;
            } else {
                if (callback.error instanceof AxisFault) {
                    throw (AxisFault) callback.error;
                } else {
                    throw new AxisFault(callback.error);
                }
            }
        } else {
            //This is the Usual Request-Response Sync implemetation
            msgctx.setTo(to);
            msgctx.setServiceContext(serviceContext);
            ConfigurationContext syscontext = serviceContext.getEngineContext();
            msgctx.setConfigurationContext(syscontext);

            checkTransport(msgctx);

            //find and set the Operation Context
            ConfigurationContext sysContext = serviceContext.getEngineContext();
            AxisConfiguration registry = sysContext.getAxisConfiguration();
            msgctx.setOperationContext(OperationContextFactory.createOperationContext(WSDLConstants.MEP_CONSTANT_IN_OUT,
                    axisop,
                    serviceContext));
            //Send the SOAP Message and receive a response
            MessageContext response =
                    TwoWayTransportBasedSender.send(msgctx, listenerTransport);

            //check for a fault and return the result
            SOAPEnvelope resenvelope = response.getEnvelope();
            if (resenvelope.getBody().hasFault()) {
                SOAPFault soapFault = resenvelope.getBody().getFault();
                Exception ex = soapFault.getException();

                if (isExceptionToBeThrownOnSOAPFault) {
                    //does the SOAPFault has a detail element for Excpetion
                    if (ex != null) {
                        throw new AxisFault(ex);
                    } else {
                        //if detail element not present create a new Exception from the detail
                        String message = "";


                        message = message + "Code =" + soapFault.getCode()==null?"":
                                soapFault.getCode().getValue()==null?"":soapFault.getCode().getValue().getText();
           

                        message = message + "Reason =" + soapFault.getReason()==null?"":
                                soapFault.getReason().getSOAPText()==null?"":soapFault.getReason().getSOAPText().getText();
                        System.out.println("message "+message);
                        throw new AxisFault(message);
                    }
                }
            }
            return response;
        }
    }

.....
应改为
                  message = message + "Code =" + (soapFault.getCode()==null?"":
                                soapFault.getCode().getValue()==null?"":soapFault.getCode().getValue().getText());
                        System.out.println(""+message);
                       Iterator t=   soapFault.getDetail().getAllDetailEntries();
                        loop(t,1);
                        org.apache.axis2.soap.impl.llom.SOAPFaultDetailImpl a;

                        message = message + "Reason =" + (soapFault.getReason()==null?"":
                                soapFault.getReason().getSOAPText()==null?"":soapFault.getReason().getSOAPText().getText());
这段代码只是对进行了处理
而对于并未处理

3)可以自行对代码修改处理部分。



    public void loop(Iterator t,int i ){
      OMElementImpl omE;
      OMTextImpl omT;
      Object tx;
      char [] sapace1=new char[i];
      String sapace=new String(sapace1);
      OMChildrenIterator tor=(OMChildrenIterator)t;
      while ( t.hasNext()){
    tx= t.next();
    System.out.println(sapace+tx.getClass().getName());
    if(tx instanceof OMElementImpl){
    omE=(OMElementImpl)tx;
    System.out.println(sapace+omE.getText());
      loop(omE.getChildren()  ,i+1);
    }else if(tx instanceof OMTextImpl)
    { omT=(OMTextImpl)tx;
      System.out.println(sapace+omT.getText());
    }else{
    System.out.println(sapace+"other type");
    }
      }
}

并在一下处调用该函数
                    if (ex != null) {
                        throw new AxisFault(ex);
                    } else {
                        //if detail element not present create a new Exception from the detail
                        String message = "";


                        message = message + "Code =" + (soapFault.getCode()==null?"":
                                soapFault.getCode().getValue()==null?"":soapFault.getCode().getValue().getText());
                        System.out.println(""+message);
                       Iterator t=   soapFault.getDetail().getAllDetailEntries();
                        loop(t,1); 
         (责任编辑:包春林)


[ 发表评论 ] 字体[  ] [ 打印 ] [ 进入博客 ] [ 进入论坛 ]  [ 推荐给朋友 ]
  相关文章
· 一个合格程序员该做的事情??你做好了吗 (01-22) · 数据库:简单的类似ibatis的sqlmap工具 (01-22)
· J2EE综合--总结java编程中的经验教训 (01-22) · 进阶--servlet-api基本类和接口介绍 (01-22)
· 浅谈信息时代如何成为一名优秀的程序员 (01-22) · 开发框架:关于struts 连接数据库的问题 (01-22)
· Struts常见错误及原因分析 (01-22) · 开发框架:关于struts 连接数据库的问题 (01-21)
· 程序人生:如何作一个真正合格的程序员 (01-21) · 程序人生:程序员不得不习惯一个人寂寞 (01-21)
  客户需求反馈表
* 姓  名:
更多资料  了解方案  认识厂商
* 单位名称:
* 联系电话:
* 电子邮件:
  赛迪推荐  
  手机·资费 ·新品·导购·评测·手机资费·宽带
手机搜索  诺基亚 N73 MOTO Z6
  IT产品 ·笔记本·台式机·服务器·打印·投影
IT产品搜索 
  IT技术 ·开发·网管·安全·数据库·操作系统
  信息化 ·热点·专题·访谈·周刊·方案案例
· 网银交易收费 我国银行业如何达国际化标准
· 家庭信息化普及率提高 网上缴费成为新时尚
· 五条黄金准则能够让CIO巧妙加薪 CIO焦虑调查
· 网上书店解决方案 深圳边检指挥中心ITSM项目
  IT博客 ·曾剑秋·项立刚·Java学习·网管
  IT技术论坛 ·开发·网管·安全·数据库·系统