文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在GT4下发布及调用基于Axis的自定义对象序列化的服务

在GT4下发布及调用基于Axis的自定义对象序列化的服务

时间:2006-05-24  来源:xianglinyan

这里以我的MultiService为例 1.定义wsdl文件: /*/usr/local/globus-4.0.0/xly/progtutorial-examples_0.2.1/schema/examples/MultiService_instance/Multi.wsdl*/ <?xml version="1.0" encoding="UTF-8"?>
<definitions name="MultiService"
    targetNamespace="http://www.globus.org/namespaces/examples/core/MultiService_instance"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://www.globus.org/namespaces/examples/core/MultiService_instance"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"
    xmlns:wsrpw="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"
    xmlns:wsdlpp="http://www.globus.org/namespaces/2004/10/WSDLPreprocessor"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:import
    namespace=
    "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"
    location="../../wsrf/properties/WS-ResourceProperties.wsdl" />

<!--============================================================
                      T Y P E S
                     
  ============================================================-->
<types>
<xsd:schema targetNamespace="http://www.globus.org/namespaces/examples/core/MultiService_instance"
    xmlns:tns="http://www.globus.org/namespaces/examples/core/MultiService_instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   
 <!-- REQUESTS AND RESPONSES -->
 
 <xsd:element name="multipy" >
  <xsd:complexType>
  <xsd:sequence>
  <xsd:element name="a1" type="xsd:int"/>
  <xsd:element name="a2" type="xsd:int"/>
  </xsd:sequence> 
  </xsd:complexType>
 </xsd:element>
 <xsd:element name="multipyResponse">
  <xsd:complexType/>
 </xsd:element>
 <xsd:element name="getValueRP">
  <xsd:complexType/>
 </xsd:element>
 <xsd:element name="getValueRPResponse" type="xsd:int"/>

 <!-- RESOURCE PROPERTIES -->
 <xsd:element name="Value" type="xsd:int"/>
 <xsd:element name="LastOp" type="xsd:string"/>
 <xsd:element name="MultiResourceProperties">
 <xsd:complexType>
  <xsd:sequence>
   <xsd:element ref="tns:Value" minOccurs="1" maxOccurs="1"/>
   <xsd:element ref="tns:LastOp" minOccurs="1" maxOccurs="1"/>
  </xsd:sequence>
 </xsd:complexType>
 </xsd:element>
       
</xsd:schema>
</types>

<!--============================================================
                       M E S S A G E S
                     
  ============================================================-->
<message name="MultipyInputMessage">
 <part name="parameters" element="tns:multipy"/>
</message>
<message name="MultipyOutputMessage">
 <part name="parameters" element="tns:multipyResponse"/>
</message>
<message name="GetValueRPInputMessage">
 <part name="parameters" element="tns:getValueRP"/>
</message>
<message name="GetValueRPOutputMessage">
 <part name="parameters" element="tns:getValueRPResponse"/>
</message>
  <!--============================================================                        P O R T T Y P E
                     
  ============================================================-->
<portType name="MultiPortType"
    wsdlpp:extends="wsrpw:GetResourceProperty"
    wsrp:ResourceProperties="tns:MultiResourceProperties">
 <operation name="multipy">
  <input message="tns:MultipyInputMessage"/>
  <output message="tns:MultipyOutputMessage"/>
 </operation>
 <operation name="getValueRP">
  <input message="tns:GetValueRPInputMessage"/>
  <output message="tns:GetValueRPOutputMessage"/>
 </operation>
</portType>
</definitions>
2.namespace2packagemapping和build.mapping和普通的一样
3.Qname类,和普通的一样: /usr/local/globus-4.0.0/xly/progtutorial-examples_0.2.1/org/globus/examples/services/core/multi/impl/MutliQname.java   package org.globus.examples.services.core.multi.impl;
import javax.xml.namespace.QName;
public interface MultiQNames {
 public static final String NS = "http://www.globus.org/namespaces/core/MultiService_instance";
 public static final QName RP_VALUE = new QName(NS, "Value");  public static final QName RP_LASTOP = new QName(NS, "LastOp");  public static final QName RESOURCE_PROPERTIES = new QName(NS,
   "MultiResourceProperties");
}
4.序列化类:MultiObject.java package org.globus.examples.services.core.multi.impl;
import java.io.Serializable;
import org.globus.examples.stubs.MultiService_instance.Multipy;
public class MultiObject extends Multipy implements Serializable
{
private int  a1= 0;
private int a2=0;
public void setA1(int a1)
{
this.a1=a1;
}
public int getA1()
{
return a1;
}
public void setA2(int a2)
{
this.a2=a2;
}
public int getA2()
{
return a2;
}
}
     
5.MultiService服务类:
package org.globus.examples.services.core.multi.impl; import java.rmi.RemoteException;
import java.util.*;
import org.globus.wsrf.Resource;
import org.globus.wsrf.ResourceProperties;
import org.globus.wsrf.ResourceProperty;
import org.globus.wsrf.ResourcePropertySet;
import org.globus.wsrf.impl.ReflectionResourceProperty;
import org.globus.wsrf.impl.SimpleResourcePropertySet;

import org.globus.examples.stubs.MultiService_instance.Multipy;
import org.globus.examples.stubs.MultiService_instance.MultipyResponse;
import org.globus.examples.stubs.MultiService_instance.GetValueRP;
public class MultiService implements Resource, ResourceProperties {
 /* Resource Property set */
 private ResourcePropertySet propSet;
 /* Resource properties */
 private int value;
 private String lastOp;
 /* Constructor. Initializes RPs */
 public MultiService() throws RemoteException {
  /* Create RP set */
  this.propSet = new SimpleResourcePropertySet(
    MultiQNames.RESOURCE_PROPERTIES);
  /* Initialize the RP's */
  try {
   ResourceProperty valueRP = new ReflectionResourceProperty(
     MultiQNames.RP_VALUE, "Value", this);
   this.propSet.add(valueRP);
   setValue(0);
   ResourceProperty lastOpRP = new ReflectionResourceProperty(
     MultiQNames.RP_LASTOP, "LastOp", this);
   this.propSet.add(lastOpRP);
   setLastOp("NONE");
  } catch (Exception e) {
   throw new RuntimeException(e.getMessage());
  }
 }
 /* Get/Setters for the RPs */
 public int getValue() {
  return value;
 }
 public void setValue(int value) {
  this.value = value;
 }
 public String getLastOp() {
  return lastOp;
 }
 public void setLastOp(String lastOp) {
  this.lastOp = lastOp;
 }
 /* Remotely-accessible operations */  public MultipyResponse multipy(MultiObject params) throws RemoteException {
  int a1=params.getA1();
  int a2=params.getA2();
  value = a1*a2;
  lastOp = "MULTIPY";
  return new MultipyResponse();
 }

 public int getValueRP(GetValueRP params) throws RemoteException {
  return value;
 }
 /* Required by interface ResourceProperties */
 public ResourcePropertySet getResourcePropertySet() {
  return this.propSet;
 }
}
6.重点注意deploy-server.wsdd文件 <?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultServerConfig"
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <service name="examples/core/multi/MultiService" provider="Handler" use="literal" style="document">
        <parameter name="className" value="org.globus.examples.services.core.multi.impl.MultiService"/>    
        <wsdlFile>share/schema/examples/MultiService_instance/Multi_service.wsdl</wsdlFile>
        <parameter name="allowedMethods" value="*"/>
       <beanMapping languageSpecificType="java:org.globus.examples.services.core.multi.impl.MultiObject" qname="ns:MultiObject" xmlns:ns="urn:BeanService"/>
  <parameter name="handlerClass" value="org.globus.axis.providers.RPCProvider"/>
        <parameter name="scope" value="Application"/>
        <parameter name="providers" value="GetRPProvider"/>
        <parameter name="loadOnStartup" value="true"/>
    </service>
</deployment>
7.客户端: 7.1相同的序列化类(略) 7.2客户端程序 //Client1.java
import org.globus.axis.util.Util;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.globus.examples.stubs.MultiService_instance.MultiPortType;
import org.globus.examples.stubs.MultiService_instance.GetValueRP;
import org.globus.examples.stubs.MultiService_instance.service.MultiServiceAddressingLocator;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
public class Client1 {
        static {
         Util.registerTransport();
       }
 public static void main(String[] args) {
  MultiServiceAddressingLocator locator = new MultiServiceAddressingLocator();
  try {
   String serviceURI = args[0];
   // Create endpoint reference to service
   EndpointReferenceType endpoint = new EndpointReferenceType();
   endpoint.setAddress(new Address(serviceURI));
   MultiPortType multi = locator.getMultiPortTypePort(endpoint);
   // Get PortType
   multi = locator.getMultiPortTypePort(endpoint);
   // Perform an addition
   MultiObject mo=new MultiObject();
   mo.setA1(5);
   mo.setA2(10);
   multi.multipy(mo);
   // Perform another addition
   
   // Access value
   System.out.println("Current value: "
     + multi.getValueRP(new GetValueRP()));
   // Perform a subtraction
   mo.setA1(15);
   mo.setA2(10);
   multi.multipy(mo);
   // Access value
   System.out.println("Current value: "
     + multi.getValueRP(new GetValueRP()));
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}
8.在发布完服务后,使用 编译客户端,现生成MultiObject类,再编译客户端。 source $GLOBUS_LOCATION/etc/globus-devel-env.sh 然后启动container 调用服务: java -classpath ./build/stubs/classes/:$CLASSPATH Client1 http://localhost:8080/wsrf/services/examples/core/multi/MultiService
 
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载