正 文

使用处理链处理WEB服务中的请求/响应消息


www.7dspace.com  更新日期:2006-1-12 2:58:53  七度空间


       这里给出了ant脚本build.xml用来打包EAR,注意在打包之前必须有Web.xml 和 application.xml

build.xml

<project name="webservices-handler" default="all" basedir=".">
<!--  set global properties for this build  -->
<property environment="env" />
<property name="compiler" value="modern" />
<property name="debug" value="yes" />
<property name="deprecation" value="yes" />
<property name="build.compiler" value="${compiler}" />
<property name="source" value="." />
<property name="build" value="${source}/build" />
<property name="war_file" value="BalanceEnquiry.war" />
<property name="ear_file" value="BalanceEnquiry.ear" />
<property name="namespace" value="http://www.bea.com" />
<property name="client.classes.dir" value="{source}/clientclasses" />
<target name="all" depends="clean, war, ear" />
<target name="clean">
<delete dir="${build}" />
<delete file="${source}/${ear_file}" />
<delete file="${war_file}" />
</target>
<target name="war">
<delete dir="${build}" />
<mkdir dir="${build}" />
<mkdir dir="${build}/WEB-INF" />
<mkdir dir="${build}/WEB-INF/classes" />
<javac srcdir="${source}" includes="AuthenticationHandler.java,
                          BalanceEnquiryService.java"
                          destdir="${build}/WEB-INF/classes" />
<copy todir="${build}/WEB-INF">
<fileset dir="${source}">
<include name="web-services.xml" />
<include name="web.xml" />
</fileset>
</copy>
<jar jarfile="${war_file}" basedir="${build}" />
</target>
<target name="ear" depends="war">
<delete dir="${build}" />
<mkdir dir="${build}" />
<mkdir dir="${build}/META-INF" />
<copy todir="${build}">
<fileset dir="${source}">
<include name="${war_file}" />
</fileset>
</copy>
<copy todir="${build}/META-INF">
<fileset dir="${source}">
<include name="application.xml" />
</fileset>
</copy>
<jar jarfile="${source}/${ear_file}" basedir="${build}" />
</target>
</project>

       ant脚本在创建WAR文件的同时也进行EAR打包,在WEBLOGIC服务器上部署打包好的EAR文件,下面是客户端调用余额查询的程序:

Client.java
import org.apache.axis.client.Call;
import org.apache.axis.client.ServiceFactory;
import org.apache.axis.client.Service;
import org.apache.axis.MessageContext;
import org.apache.axis.attachments.Attachments;
import org.apache.axis.message.SOAPEnvelope;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.rpc.ParameterMode;

import java.net.URL;
import java.util.Iterator;

public class Client
{
   private static String TARGET_NAMESPACE = "http://www.bea.com";
   private static QName xsdFloat = new
                  QName("http://www.w3.org/2001/XMLSchema", "float");
   public static org.apache.axis.message.SOAPEnvelope env = null;
   public static SOAPMessage message = null;
   public static void main(String[] argv) throws Exception
   {
      Client client = new Client();
      env = client.constructSOAPEnvelope();
      client.constructHeader(env);
      client.constructBody(env);
      System.setProperty( "javax.xml.rpc.ServiceFactory",
                          "org.apache.axis.client.ServiceFactory" );

      String url =
     "http://localhost:7001/BalanceEnquiry/BalanceEnquiryService";
     ServiceFactory factory =
         (org.apache.axis.client.ServiceFactory)ServiceFactory.
              newInstance();
      QName serviceName   = new QName(TARGET_NAMESPACE,
         "BalanceEnquiryService");

      Service service =
         (org.apache.axis.client.Service)factory.
          createService(serviceName);
      Call call = (org.apache.axis.client.Call)service.createCall();
      call.setTargetEndpointAddress(url);
      SOAPEnvelope result = call.invoke(env);
      System.out.println(result);
   }
   public SOAPEnvelope constructSOAPEnvelope() throws Exception
   {
      org.apache.axis.message.SOAPEnvelope env = new
         org.apache.axis.message.SOAPEnvelope();
      return env;
   }
   public void constructHeader(SOAPEnvelope envelope) throws Exception
   {
      SOAPHeader header = envelope.getHeader();
      Name headerElementName =
         envelope.createName("AccountDetails","",
                             "http://schemas.xmlsoap.org/soap/
                                     envelope/");
      SOAPHeaderElement headerElement =
         header.addHeaderElement(headerElementName);
      headerElement.setMustUnderstand(false);
      headerElement.addNamespaceDeclaration("soap",
         "http://schemas.xmlsoap.org/soap/envelope/");
      SOAPElement accNo = headerElement.addChildElement("accountNo");
      accNo.addTextNode("12345");
      SOAPElement pinNo = headerElement.addChildElement("pin");
      pinNo.addTextNode("6789");
   }

   public void constructBody(SOAPEnvelope envelope) throws Exception
   {
      SOAPBody body = envelope.getBody();
      Name bodyRootElementName =
         envelope.createName("getBalance","",
                             "http://schemas.xmlsoap.org/soap/
                                     encoding/");
      SOAPBodyElement bodyRootElement =
         body.addBodyElement(bodyRootElementName);
      SOAPElement bodyElement =
         bodyRootElement.addChildElement("param0");
      bodyElement.addAttribute(envelope.createName("xsi:type"),
                                                   "xsd:string");
      bodyElement.addTextNode("12");
   }
}

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

上一篇:世界上最优秀的二十款防火墙简介
下一篇:集群的负载均衡技术
标题:使用处理链处理WEB服务中的请求/响应消息 作者:xzzhouhu 来源:matrix ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐