关于weblogic平台和axis上开发webservices的比较

来源:互联网 发布:二胡校音器软件下载 编辑:程序博客网 时间:2024/04/29 18:55

1.bea workshop太大,开发的方式相对比较单一(基于jws),主要以业务为主,使用起来不灵活,与平台紧紧靠在一起,对EJB,JSP,swing等开发都限制在weblogic平台上,否则很难在相互之间的调用,开发部署的透明度不高(要根据醒目来部署,而不是一个简单的项目来)。
2.axis则相对是轻量级的web services开发环境,提供了JWS,wsdd开发方式,还可以结合wsdl2Java工具来完成根据wsdl文件生成合适的web services的开发。axis更是一个开放的组件,它的实现不依赖于任何特定的服务器,可看成一个简单的web应用,同时提供web services的容器。这是因为它的核心是基于servlet容器上的soap通信容器。
axis实现web services的基本原理(基于servlet引擎的web services):
  有关于mesage Envelope等包应用在xml soap底层文件处理上,可以结合xmlDOM来处理soap消息,在结合servlet就可以实现一个web services.而不需要任何环境;
  其思路:
    1.客户端是基于message,和xml来都到合适的envelope的soap消息,上面就是例子。
    2.服务端是一个servlet文件,其中用XMLDOM和Envlope来解析envelope,处理之后生成envelope,并通过soap走http给于请求回应。
    这样他们之间就可以实现基于soap的web services。
这只是一基本原理,其实质的远比这复杂.
这样在处理soap消息的过程中,可以结合上面的一些底层的东西处理soap消息,从而获得根大的灵活性
例:一个得到的soap消息中根据其对cid描述,对其附加上附件。
关键代码如下:
   import javax.mail.internet.MimeBodyPart;
import org.apache.axis.*;
import javax.xml.soap.AttachmentPart;
import org.apache.axis.Message;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPEnvelope;
import java.io.*;
public class test{
  public static void main(String arg[]){
   try{
    File file=new File("HelloWorld.java");
    BufferedReader br=new BufferedReader(new FileReader(file));
    StringBuffer sb=new StringBuffer();
    for(String line=br.readLine();line!=null;line=br.readLine()){
     sb.append(line);
    }
   Message m=new Message("<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><soapenv:Body><ns1:putFile soapenv:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:ns1='http://127.0.0.1:7001/axis/services/FileService'><s1 href='cid:attachement' xsi:type='ns2:DataHandler' xmlns:ns2='FileService'/><s2 xsi:type='xsd:string'>HelloWorld.java</s2></ns1:putFile></soapenv:Body></soapenv:Envelope>");
   AttachmentPart ap1 = m.createAttachmentPart();
      ap1.setContent(sb.toString(), "text/plain");
      ap1.setContentId("attachement");
    m.addAttachmentPart(ap1);
      String endpoint="http://127.0.0.1:7003/axis/services/FileService";
   String name="gaolong1";
   Service service=new Service();
   Call call=(Call) service.createCall();
   System.out.println(m.getSOAPEnvelope());
   call.setTargetEndpointAddress(new java.net.URL(endpoint));
  SOAPEnvelope ret=(SOAPEnvelope)call.invoke(m);
   System.out.println(ret.toString());
  }catch(Exception e){
   e.printStackTrace();
  }
   }
   }
原创粉丝点击