/* * Copyright (c) 2000-2011 LabVantage Solutions, Inc. All rights reserved. * * No part of this work may be reproduced or distributed without the * permission of LabVantage Solutions, Inc. * * If you are not authorized by LabVantage to utilize this * software and/or documentation, you must immediately discontinue any * further use or viewing of this software and documentation. * Violaters will be prosecuted to the fullest extent of the law by * LabVantage Solutions, Inc. * * Developed by LabVantage Solutions, Inc. * 1160 US Highway 22 East * Bridgewater, NJ, 08807 */ package com.labvantage.training; import sapphire.xml.PropertyList; import java.io.*; import org.apache.axis.client.Service; import org.apache.axis.client.Call; import javax.xml.namespace.QName; /** * Enter description here * * @author gstimson * @version $Author: dkemp $ * $Source: /extra/CVS/development/procedures/idea/config/fileTemplates/includes/File\040header.java,v $ * $Revision: 1.1 $ * $Date: 2006/06/30 21:08:51 $ * $State: Exp $ * $Id: File\040header.java,v 1.1 2006/06/30 21:08:51 dkemp Exp $ */ //@todo Update JavaDoc public class RunWebService1 { /** * * This class shows how to call web services in Java pre-R5.2. * * The web service calls accept strings and return strings only, therefore any object such as a propertylist or dataset * must be converted into XML first and then sent through the web service call. Then the returned string needs to be * passed to a new propertylist or dataset to recreate the object. * * In R5.2 onwards this way of working is still supported, however we have also added the ability to pass native bean objects which * wrap the API objects through web services. Please see RunWebService2 class. * */ private static String getInput(){ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try{ return br.readLine(); } catch( IOException e ){ System.out.println( e.getMessage() ); return ""; } } public static void main( String[] args ){ try { String server; String port; String webapp; if ( args.length > 0 ){ server = args[0]; System.out.println( "Server: " + server ); if ( args.length > 1 ){ port = args[1]; System.out.println( "Port: " + port ); if ( args.length > 2 ){ webapp = args[2]; System.out.println( "Web App: " + webapp ); } else{ System.out.print( "Enter Web App: " ); webapp = getInput(); } } else{ System.out.print( "Enter Port: " ); port = getInput(); System.out.print( "Enter Web App: " ); webapp = getInput(); } } else{ System.out.print( "Enter Server: " ); server = getInput(); System.out.print( "Enter Port: " ); port = getInput(); System.out.print( "Enter Web App: " ); webapp = getInput(); } String endpoint = "http://" + server + ":" + port + "/" + webapp + "/services/SapphireWS?wsdl"; System.out.println( "RunWebService started..." ); System.out.println( "Web service URL = " + endpoint ); Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("http://soapinterop.org/", "getConnectionId")); String database; String username ; String password; if ( args.length > 3 ){ database = args[3]; System.out.println( "Database: " + database ); if ( args.length > 4 ){ username = args[4]; System.out.println( "Username: " + username ); if ( args.length > 5 ){ password = args[5]; System.out.println( "Password: " + password ); } else{ System.out.print( "Enter Password: " ); password = getInput(); } } else{ System.out.print( "Enter Username: " ); username = getInput(); System.out.print( "Enter Password: " ); password = getInput(); } } else{ System.out.print( "Enter Database: " ); database = getInput(); System.out.print( "Enter Username: " ); username = getInput(); System.out.print( "Enter Password: " ); password = getInput(); } if ( database.length() > 0 && username.length() > 0 && password.length() > 0 ){ // dbid, user, pass String connectionid = (String) call.invoke( new Object[] { database, username, password } ); if ( connectionid != null && connectionid.length() > 0 ){ System.out.println("Sent....connectionid = '" + connectionid + "'"); String sampledesc; if ( args.length > 6 ){ sampledesc = args[6]; System.out.println( "Sample Description: " + sampledesc ); } else{ System.out.print( "Enter Sample Description: " ); sampledesc = getInput(); } call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("http://soapinterop.org/", "processAction")); PropertyList pl = new PropertyList(); pl.setProperty( "sdcid", "Sample" ); pl.setProperty( "sampledesc", sampledesc ); pl.setProperty( "copies", "1" ); // The call to run process action accepts a string of the property list xml. Therefore we need to call // the toXMLString method on the property list. String ret = (String) call.invoke( new Object[] { connectionid, "AddSDI", "1", pl.toXMLString() } ); System.out.println("Sent....action"); // The returned string is actually a propertylist xml string which then needs converting back into a propertylist PropertyList plret = new PropertyList(); plret.setPropertyList( ret ); System.out.println( "New Sample: " + plret.getProperty( "newkeyid1" ) ); } else{ System.out.println("Invalid username, database or password provided as no connection Id could be obtained."); } } else{ System.out.println("No username, database or password provided."); } } catch (Exception e) { System.err.println(e.toString()); } } }