[xgws-dev] CVS Update: codes/xsul/sample_decoder/src/math/service

Aleksander Andrzej Slominski xgws-dev_at_extreme.indiana.edu
Tue Apr 26 00:13:32 2005


aslom       05/04/26 00:12:51

  Added:       xsul/sample_decoder/src/math/client MathClient.java
               xsul/sample_decoder/src/math/service MathService.java
                        MathServiceImpl.java
  Log:
  very simple Adder service to be used for testing without GFac
  
  Revision  Changes    Path
  1.1                  codes/xsul/sample_decoder/src/math/client/MathClient.java
  
  Index: MathClient.java
  ===================================================================
  /* -*- mode: Java; c-basic-offset: 4; indent-tabs-mode: nil; -*-  //------100-columns-wide------>|*/
  /*
   * Copyright (c) 2004 Extreme! Lab, Indiana University. All rights reserved.
   *
   * This software is open source. See the bottom of this file for the licence.
   *
   * based on xsul_dii.XsulDynamicInvoker.java,v 1.8 2005/01/18 10:02:38 aslom Exp $
   */
  
  package math.client;
  
  import java.io.File;
  import java.net.URI;
  import math.service.MathService;
  import org.xmlpull.v1.builder.XmlInfosetBuilder;
  import xsul.MLogger;
  import xsul.XmlConstants;
  import xsul.XsulVersion;
  
  public class MathClient {
      private final static MLogger logger = MLogger.getLogger();
      private final static XmlInfosetBuilder builder = XmlConstants.BUILDER;
      
      private static void usage(String errMsg) {
          System.err.println("Usage: WSDL_URL topic");
      }
      
      public static void main(String[] args) throws Exception {
          XsulVersion.exitIfRequiredVersionMissing(XsulVersion.SPEC_VERSION);
          
          boolean selfTesting = System.getProperty("start_server") != null;
          try {
              if(selfTesting) { // just for testing
                  System.out.println("Doing self testing");
                  //String wsdlLoc = args[0];
                  MathService.main(new String[]{"0"});
                  if(args.length != 1) {
                      throw new IllegalArgumentException("exactly one argument with topic expected in self test");
                  }
                  String newWsdlLoc = MathService.getServiceWsdlLocation();
                  String[] sarr =new String[]{newWsdlLoc, args[0]};
                  args = sarr;
              }
              
              System.err.println("Starting "+MathClient.class.getName());
              
              
              runClient(args);
          } finally {
              if(selfTesting) {
                  try {MathService.shutdownServer();} catch(Exception e) {}
              }
          }
      }
      
      private static void runClient(String[] args) throws Exception {
          URI base = ((new File(".")).toURI());
          
          if(args.length < 2) {
              usage("four args required: WSDL_URL topic");
          }
          
          String wsdlLoc = args[0];
          
          System.err.println("invoking operation WSDL from "+ wsdlLoc);
          
          
  //        Decoder stub = (Decoder)
  //            XmlBeansWSIFRuntime.newClient(wsdlLoc).generateDynamicStub(Decoder.class);
  //
  //        DecoderRunInputParamsDocument runMsg =
  //            DecoderRunInputParamsDocument.Factory.newInstance();
  //        DecoderRunInputParamsType params = runMsg.addNewDecoderRunInputParams();
  //        params.setTopic(args[1]);
  //        DecoderRunOutputParamsDocument resultMsg = stub.run(runMsg);
  //        DecoderRunOutputParamsType result = resultMsg.getDecoderRunOutputParams();
  //        System.out.println("outputUrl="+result.getOutputURL());
  //
  //        DecoderShutdownInputParamsDocument shutdownMsg
  //            = DecoderShutdownInputParamsDocument.Factory.newInstance();
  //        shutdownMsg.addNewDecoderShutdownInputParams();
  //        stub.shutdown(shutdownMsg);
          System.out.println("finished");
      }
  }
  
  
  
  
  
  
  1.1                  codes/xsul/sample_decoder/src/math/service/MathService.java
  
  Index: MathService.java
  ===================================================================
  /* -*- mode: Java; c-basic-offset: 4; indent-tabs-mode: nil; -*-  //------100-columns-wide------>|*/
  /*
   * Copyright (c) 2005 Extreme! Lab, Indiana University. All rights reserved.
   *
   * This software is open source. See the bottom of this file for the licence.
   *
   * $Id: MathService.java,v 1.1 2005/04/26 05:12:50 aslom Exp $
   */
  package math.service;
  
  
  import xsul.XsulVersion;
  import xsul.xservices_xbeans.XmlBeansBasedService;
  import xsul.xservo.XService;
  import xsul.xservo_soap_http.HttpBasedServices;
  
  /**
   * Self-contained service launcher.
   */
  public class MathService {
      private static HttpBasedServices httpServices;
      private static final String ADDER_SERVICE_NAME = "adder";
      
      /**
       * Launch service from command line
       */
      public static void main(String[] args) {
          XsulVersion.exitIfRequiredVersionMissing(XsulVersion.SPEC_VERSION); //sanity check
          XsulVersion.exitIfRequiredVersionMissing("2.0.6");
          int tcpPort = args.length > 0 ? Integer.parseInt(args[0]) : 0;
          httpServices = new HttpBasedServices(tcpPort);
          
          System.out.println("Server started on "+httpServices.getServerPort());
          String wsdlLoc = args.length > 1 ? args[1] : "config/adder-example.wsdl";
          System.out.println("Using WSDL for service description from "+wsdlLoc);
          XService xsvc =
              httpServices.addService(
              new XmlBeansBasedService(ADDER_SERVICE_NAME, wsdlLoc, new MathServiceImpl()));
          xsvc.startService();
          
          System.out.println("Service started");
          System.out.println("Service WSDL available at "+getServiceWsdlLocation());
      }
      
      public static String getServiceWsdlLocation() {
          return httpServices.getServer().getLocation() + "/"+ADDER_SERVICE_NAME+"?wsdl";
      }
      public static void shutdownServer() {
          httpServices.getServer().shutdownServer();
      }
  }
  
  /*
   * Indiana University Extreme! Lab Software License, Version 1.2
   *
   * Copyright (c) 2002-2005 The Trustees of Indiana University. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met:
   *
   * 1) All redistributions of source code must retain the above copyright notice,
   * the list of authors in the original source code, this list of conditions and
   * the disclaimer listed in this license;
   *
   * 2) All redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the disclaimer listed in this license in
   * the documentation and/or other materials provided with the distribution;
   *
   * 3) Any documentation included with all redistributions must include the
   * following acknowledgement:
   *
   * "This product includes software developed by the Indiana University Extreme!
   * Lab. For further information please visit http://www.extreme.indiana.edu/"
   *
   * Alternatively, this acknowledgment may appear in the software itself, and
   * wherever such third-party acknowledgments normally appear.
   *
   * 4) The name "Indiana University" or "Indiana University Extreme! Lab" shall
   * not be used to endorse or promote products derived from this software without
   * prior written permission from Indiana University. For written permission,
   * please contact http://www.extreme.indiana.edu/.
   *
   * 5) Products derived from this software may not use "Indiana University" name
   * nor may "Indiana University" appear in their name, without prior written
   * permission of the Indiana University.
   *
   * Indiana University provides no reassurances that the source code provided
   * does not infringe the patent or any other intellectual property rights of any
   * other entity. Indiana University disclaims any liability to any recipient for
   * claims brought by any other entity based on infringement of intellectual
   * property rights or otherwise.
   *
   * LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH NO
   * WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA UNIVERSITY GIVES
   * NO WARRANTIES AND MAKES NO REPRESENTATION THAT SOFTWARE IS FREE OF
   * INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR OTHER PROPRIETARY RIGHTS.
   * INDIANA UNIVERSITY MAKES NO WARRANTIES THAT SOFTWARE IS FREE FROM "BUGS",
   * "VIRUSES", "TROJAN HORSES", "TRAP DOORS", "WORMS", OR OTHER HARMFUL CODE.
   * LICENSEE ASSUMES THE ENTIRE RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR
   * ASSOCIATED MATERIALS, AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION
   * GENERATED USING SOFTWARE.
   */
  
  
  
  
  1.1                  codes/xsul/sample_decoder/src/math/service/MathServiceImpl.java
  
  Index: MathServiceImpl.java
  ===================================================================
  /* -*- mode: Java; c-basic-offset: 4; indent-tabs-mode: nil; -*-  //------100-columns-wide------>|*/
  /*
   * Copyright (c) 2005 Extreme! Lab, Indiana University. All rights reserved.
   *
   * This software is open source. See the bottom of this file for the licence.
   *
   * $Id: MathServiceImpl.java,v 1.1 2005/04/26 05:12:50 aslom Exp $
   */
  package math.service;
  
  import math.adder.service.Adder;
  import math.adder.xmlbeans.AdderRunInputParamsDocument;
  import math.adder.xmlbeans.AdderRunInputParamsType;
  import math.adder.xmlbeans.AdderRunOutputParamsDocument;
  import math.adder.xmlbeans.AdderRunOutputParamsType;
  import xsul.MLogger;
  
  /**
   * Service is implementation of Math related interfaces (Adder etc).
   */
  public class MathServiceImpl implements Adder {
      private final static MLogger logger = MLogger.getLogger();
      
      public AdderRunOutputParamsDocument run(AdderRunInputParamsDocument inputMsg) {
          AdderRunInputParamsType params = inputMsg.getAdderRunInputParams();
          String topic = params.getTopic();
          String corrId = params.getCorrelationID();
          String xs = params.getX();
          String ys = params.getY();
          logger.finest("got topic="+topic+" CorrelationID="+corrId+" x="+xs+" y="+ys);
          int x = Integer.parseInt(xs);
          int y = Integer.parseInt(ys);
          int z = x + y;
          AdderRunOutputParamsDocument resultDoc = AdderRunOutputParamsDocument.Factory.newInstance();
          AdderRunOutputParamsType result = resultDoc.addNewAdderRunOutputParams();
          result.setZ(Integer.toString(z));
          return resultDoc;
      }
      
      
  }
  
  /*
   * Indiana University Extreme! Lab Software License, Version 1.2
   *
   * Copyright (c) 2002-2005 The Trustees of Indiana University. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met:
   *
   * 1) All redistributions of source code must retain the above copyright notice,
   * the list of authors in the original source code, this list of conditions and
   * the disclaimer listed in this license;
   *
   * 2) All redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the disclaimer listed in this license in
   * the documentation and/or other materials provided with the distribution;
   *
   * 3) Any documentation included with all redistributions must include the
   * following acknowledgement:
   *
   * "This product includes software developed by the Indiana University Extreme!
   * Lab. For further information please visit http://www.extreme.indiana.edu/"
   *
   * Alternatively, this acknowledgment may appear in the software itself, and
   * wherever such third-party acknowledgments normally appear.
   *
   * 4) The name "Indiana University" or "Indiana University Extreme! Lab" shall
   * not be used to endorse or promote products derived from this software without
   * prior written permission from Indiana University. For written permission,
   * please contact http://www.extreme.indiana.edu/.
   *
   * 5) Products derived from this software may not use "Indiana University" name
   * nor may "Indiana University" appear in their name, without prior written
   * permission of the Indiana University.
   *
   * Indiana University provides no reassurances that the source code provided
   * does not infringe the patent or any other intellectual property rights of any
   * other entity. Indiana University disclaims any liability to any recipient for
   * claims brought by any other entity based on infringement of intellectual
   * property rights or otherwise.
   *
   * LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH NO
   * WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA UNIVERSITY GIVES
   * NO WARRANTIES AND MAKES NO REPRESENTATION THAT SOFTWARE IS FREE OF
   * INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR OTHER PROPRIETARY RIGHTS.
   * INDIANA UNIVERSITY MAKES NO WARRANTIES THAT SOFTWARE IS FREE FROM "BUGS",
   * "VIRUSES", "TROJAN HORSES", "TRAP DOORS", "WORMS", OR OTHER HARMFUL CODE.
   * LICENSEE ASSUMES THE ENTIRE RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR
   * ASSOCIATED MATERIALS, AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION
   * GENERATED USING SOFTWARE.
   */