//Copyright (c) The University of Edinburgh, 2007. //See OGSA-DAI-Licence.txt for licencing information. package practical; import java.net.URL; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Collections; import java.io.FileReader; import uk.org.ogsadai.client.toolkit.DataRequestExecutionResource; import uk.org.ogsadai.client.toolkit.PipelineWorkflow; import uk.org.ogsadai.client.toolkit.RequestExecutionType; import uk.org.ogsadai.client.toolkit.RequestResource; import uk.org.ogsadai.client.toolkit.ServerProxy; import uk.org.ogsadai.client.toolkit.activities.block.Tee; import uk.org.ogsadai.client.toolkit.activities.delivery.DeliverToFTP; import uk.org.ogsadai.client.toolkit.activities.delivery.DeliverToSMTP; import uk.org.ogsadai.client.toolkit.activities.file.ReadFromFile; import uk.org.ogsadai.client.toolkit.activities.sql.SQLQuery; import uk.org.ogsadai.client.toolkit.activities.transform.XSLTransform; import uk.org.ogsadai.client.toolkit.exception.RequestCompletedWithErrorException; import uk.org.ogsadai.resource.ResourceID; import uk.org.ogsadai.resource.request.RequestStatus; import uk.org.ogsadai.client.toolkit.activities.transform.TupleToWebRowSetCharArrays; // http://library.iceage-eu.org/resolve/resolver.jsp?rft_dat=lib%3a8993&rft_title=&svc_dat=details&referer=nesc.ac.uk%3alibrary&rfr_id=info:sid/nesc.ac.uk:library import org.globus.wsrf.impl.security.authentication.Constants; import org.globus.wsrf.impl.security.authorization.HostAuthorization; import org.globus.axis.util.Util; import uk.org.ogsadai.client.toolkit.DataRequestExecutionResource; /** * Simple command-line client. *
* $ java uk.org.ogsadai.client.toolkit.example.FileClient * -u services base URL - default "http://localhost:8080/wsrf/services/dai"; * -e DRER ID - default DataRequestExecutionResource ** * @author The OGSA-DAI Project Team */ public class Scenario1 extends ClientBase { /** Command-line flag for URL. */ private static final String URL = "u"; /** Command-line flag for DRER. */ private static final String DRER = "e"; // http://library.iceage-eu.org/resolve/resolver.jsp?rft_dat=lib%3a8993&rft_title=&svc_dat=details&referer=nesc.ac.uk%3alibrary&rfr_id=info:sid/nesc.ac.uk:library static { Util.registerTransport(); } /** * Run from command line. * * @param args * Command-line arguments. * @throws Exception * If there are any problems. */ public static void main(String[] args) throws Exception { Scenario1 client = new Scenario1(); client.execute(args); } /** * Parse the arguments, submit a request to the OGSA-DAI server * and pretty-print the results. * * @param args * Command-line arguments. * * @throws Exception if an error occurs. */ public void execute(String[] args) throws Exception { Map parameters = new Hashtable(); super.parseArguments(args, parameters); // Initialise arguments. String url = super.getSingleValueOptionalFlag(parameters, URL); if (url == null) { url = "http://localhost:8080/wsrf/services/dai"; } String drerIDStr = super.getSingleValueOptionalFlag(parameters, DRER); if (drerIDStr == null) { drerIDStr = "DataRequestExecutionResource"; } ResourceID drerID = new ResourceID(drerIDStr); // http://library.iceage-eu.org/resolve/resolver.jsp?rft_dat=lib%3a8993&rft_title=&svc_dat=details&referer=nesc.ac.uk%3alibrary&rfr_id=info:sid/nesc.ac.uk:library url = "https://tc07.nesc.ed.ac.uk:8443/wsrf/services/dai/"; ServerProxy server = new ServerProxy(); server.setDefaultBaseServicesURL(new URL(url)); server = new ServerProxy(); server.setDefaultBaseServicesURL( new URL(url) ); // Get DRER DataRequestExecutionResource drer = server.getDataRequestExecutionResource(drerID); // Execute. executeRequest(drer); } /** * Submit a request to a DRER to read a file that's * part of a file system data resource and then deliver its * contents to an FTP server and to your email account. * * @param drer * Client toolkit data request execution resource proxy. * @param fileResourceID * ID of file system data resource. * @throws Exception * If there are any problems. */ private static void executeRequest(DataRequestExecutionResource drer) throws Exception { // Add code here // http://training.omii-europe.org/Tutorials/OGSA-DAI/SimpleWorkflowTC.html drer.addServerCommsProperty(Constants.GSI_SEC_CONV, Constants.ENCRYPTION); drer.addServerCommsProperty(Constants.AUTHORIZATION, HostAuthorization.getInstance()); // 3. A simple workflow PipelineWorkflow pipeline = new PipelineWorkflow(); // http://www.ogsadai.org.uk/documentation/ogsadai3.0/ogsadai3.0-gt/ActivitiesAppendix.html#SQLQueryActivityRef SQLQuery dsql = new SQLQuery(); dsql.setResourceID("LittleBlackBook"); dsql.addExpression("select * from LittleBlackBook where id<10"); pipeline.add(dsql); // http://www.ogsadai.org.uk/documentation/ogsadai3.0/ogsadai3.0-gt/ActivitiesAppendix.html#TupleToWebRowSetCharArraysRef TupleToWebRowSetCharArrays tupleToWebRowSet = new TupleToWebRowSetCharArrays(); tupleToWebRowSet.connectDataInput(dsql.getDataOutput()); pipeline.add(tupleToWebRowSet); // http://www.ogsadai.org.uk/documentation/ogsadai3.0/ogsadai3.0-gt/ActivitiesAppendix.html#DeliverToFTPActivityRef DeliverToFTP dftp = new DeliverToFTP(); //dftp.addFilename("/incoming/user00/SQLOutput.txt"); //dftp.addFilename("/incoming/ogsa-dai005/SQLOutput.txt"); dftp.addFilename("/incoming/ogsa-dai005_SQLOutput.txt"); dftp.addHost("anonymous:anonymous@tc07.nesc.ed.ac.uk"); dftp.addPassiveMode(true); dftp.connectDataInput(tupleToWebRowSet.getResultOutput()); pipeline.add(dftp); // We have now added out 3 activities, and connected them to the pipeline. The pipeline request is now ready and you can submit it for execution by the DataRequestExecutionresource on the server. RequestResource requestResource = drer.execute(pipeline, RequestExecutionType.SYNCHRONOUS); System.out.println(requestResource.getRequestStatus()); } }