正 文

通过 SOAP 和 HTTP 发送安全/非安全附件


www.7dspace.com  更新日期:2006-2-13 22:58:35  七度空间


      在处理程序(此处的处理程序是 tip.attachment.NameValidatorHandler)的 handleRequest 方法中,您需要将 MessageContext 修改为包含发送合作伙伴的 ID 和接收合作伙伴的 ID,如下面的清单 3 中所示:

清单 3. handleRequest 方法

public boolean handleRequest(javax.xml.rpc.handler.MessageContext ctx)
{
     try{
        com.ibm.ws.webservices.engine.MessageContext soapMessageContext =
          (com.ibm.ws.webservices.engine.MessageContext)ctx;
        SOAPMessage sm = soapMessageContext.getMessage();

        SOAPHeader soapHeader = sm.getSOAPPart().getEnvelope().getHeader();
        javax.xml.soap.Name name = sm.getSOAPPart().getEnvelope().
             createName("sender-id","b2b","http://ibm.com/b2b");
        soapHeader.addHeaderElement(name).addTextNode("b2b");;

        name = sm.getSOAPPart().getEnvelope().
             createName("receiver-id","b2c","http://ibm.com/b2c");
        soapHeader.addHeaderElement(name).addTextNode("b2c");

        // variable for soap body
        SOAPBody sb = null;

        // get soap body from soap message
        sb = sm.getSOAPPart().getEnvelope().getBody();

     }catch(Exception ex){
        ex.printStackTrace();
     }
   return true;
}

      服务器端代码处理

      当将合作伙伴 ID 放入到服务器端的 SOAP Header 中时,需要通过一个标准方法来在 webservices.xml 文件中配置该处理程序。进行此工作时,webservices.xml 文件将与下面的清单 4 类似:

清单 4. 将 ID 放入到 SOAP Header 中

<port-component>
       <port-component-name>AttachmentTip
         </port-component-name>
       <wsdl-port xmlns:pfx=
         "urn:attachment.tip">pfx:AttachmentTip</wsdl-port>
       <service-endpoint-interface>tip.attachment.AttachmentTip
         </service-endpoint-interface>
       <service-impl-bean>
        <servlet-link>AttachmentTip</servlet-link>
     </service-impl-bean>
     <handler>
   <handler-name>NameValidatorHandler</handler-name>
   <handler-class>tip.attachment.NameValidatorHandler
     </handler-class>
 </handler>
</port-component>

      然后,您需要在 RPC 处理程序的服务器端访问此 SOAP 消息,以提取 SOAP Header 来标识合作伙伴的 ID。在服务器端处理程序中,必须将这些合作伙伴 ID 存储在外部存储中,并通过从此处读取合作伙伴 ID 来使用附件。

6页,页码:[1] [2] [3] [4] [5] [6] 

上一篇:DVD备份之王花落谁家 Divx6 VS RatDVD
下一篇:使用AJAX调用SOAP Web服务:构建Web服务客户机
标题:通过 SOAP 和 HTTP 发送安全/非安全附件 作者:Vikas Arora 来源:developerWorks 中国
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐