Commit aa2a501f authored by Christophe Demarey's avatar Christophe Demarey

Update examples to use the FraSCAti MOJO.

parent 581879f2
......@@ -24,11 +24,15 @@
package org.ow2.frascati.factory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.logging.LogManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
......@@ -43,6 +47,14 @@ import org.apache.maven.project.MavenProject;
* @goal exec
*/
public class FrascatiMojo extends AbstractMojo {
/**
* The path to the logging configuration file.
*
* @parameter expression="${loggingConfFile}"
* @required
* @since 1.1
*/
private String loggingConfFile;
/**
* The name of the SCA composite to execute.
*
......@@ -71,7 +83,14 @@ public class FrascatiMojo extends AbstractMojo {
* @parameter expression="${params}"
* @since 1.1
*/
private String[] params;
private String methodParams;
/**
* List of method parameters with parameter children tags.
*
* @parameter expression="${parameters}"
* @since 1.1
*/
private String[] methodParameters;
/**
* The Maven project reference.
......@@ -115,27 +134,71 @@ public class FrascatiMojo extends AbstractMojo {
return list.toArray(new URL[list.size()]);
}
/**
* Tells if a MOJO parameter is empty or not.
*
* @param s A string parameter.
* @return True if the parameter is not filled.
*/
private static boolean isEmpty(String s) {
return ((s == null) || (s.trim().isEmpty()));
}
/**
* Parse method parameters specified either in the params tag or in the parameters tag.
*
* Return the list of parameters.
*/
private String[] getMethodParams() throws MojoFailureException {
if ( !isEmpty(methodParams) ) { // params tag is filled
if (methodParameters.length > 0)
throw new MojoFailureException(
"You have to choose ONE (and only one) one way to specify parameters: "
+ "either <params> or <parameters> tag.");
else {
return methodParams.split(" ");
}
} else {
if (methodParameters.length > 0) {
return methodParameters;
} else // else no parameters nor params
return new String[0];
}
}
/**
* Launch the Runtime Factory with specified parameters.
*/
public void execute() throws MojoExecutionException, MojoFailureException {
try {
LogManager.getLogManager().readConfiguration( new FileInputStream(loggingConfFile) );
} catch (Exception e) {
getLog().warn("Cannot load logging configuration file : "+loggingConfFile);
}
String[] methodParams = getMethodParams();
Launcher launcher = new Launcher(composite, new Factory(), getClasspath());
if(service == null) { // Run in a server mode
System.out.println("FraSCAti is running in a server mode...");
System.out.println("Press Ctrl+C to quit...");
Thread.yield();
if ( isEmpty(service) ) { // Run in a server mode
getLog().info("FraSCAti is running in a server mode...");
getLog().info("Press Ctrl+C to quit...");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("Calling the '" + service + "' service: ");
System.out.println("\tMethod '" + method + "'"
+ ((params.length == 0) ? "" : " with params: " + params.toString()));
if (params == null) params = new String[0];
Object result = launcher.call(service, method, Object.class, params);
System.out.println("Call done!");
if(result != null) {
System.out.println("Service response:");
System.out.println(result);
getLog().info("Calling the '" + service + "' service: ");
getLog().info("\tMethod '" + method + "'"
+ ((methodParams.length == 0) ? "" : " with params: " + Arrays.toString(methodParams)));
if (methodParams == null) methodParams = new String[0];
Object result = launcher.call(service, method, Object.class, methodParams);
getLog().info("Call done!");
if (result != null) {
getLog().info("Service response:");
getLog().info(result.toString());
}
}
}
......
......@@ -191,44 +191,4 @@ public class Launcher {
}
}
//---------------------------------------------------------------------------
// Main method
// --------------------------------------------------------------------------
/**
* Build a launcher for an SCA composite and perform a call on a service. If
* no service is given, the Launcher runs in a server mode.
* <p>
* Usage:
* <code>Launcher compositeName [serviceName methodName [params]]</code>
*
* @param args
* an array containing, ordered as following:
* <ol>
* <li> the SCA composite name (required) <li> the service name <li>
* the method name <li> arguments of the method
* </ol>
*/
public static void main(String[] args) {
if(args.length == 0) {
throw new Error("Please, provide a composite name.");
}
Launcher l = new Launcher(args[0]);
if(args[1] == null || args[1].equals("")) { // Run in a server mode
System.out.println("FraSCAti is running in a server mode...");
System.out.println("Press Ctrl+C to quit...");
Thread.yield();
} else {
String p = args[3];
Object[] params = p.split(" ");
System.out.println("Calling the '" + args[1] + "' service: ");
System.out.println("\tMethod '" + args[2] + "'"
+ ((params.length == 0) ? "" : " with params: " + p));
Object result = l.call(args[1], args[2], Object.class, params);
if(result != null) {
System.out.println("Service response:");
System.out.println(result.toString());
}
}
}
}
......@@ -45,9 +45,6 @@
<properties>
<composite.file>soap-calc</composite.file>
<service.name>''</service.name>
<method.name>''</method.name>
<method.params>''</method.params>
</properties>
</project>
......@@ -47,7 +47,6 @@
<composite.file>counter-client</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
<method.params>' '</method.params>
</properties>
</project>
......@@ -45,9 +45,6 @@
<properties>
<composite.file>counter-server</composite.file>
<service.name>''</service.name>
<method.name>''</method.name>
<method.params>''</method.params>
</properties>
</project>
......@@ -44,6 +44,7 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<wsdl.file>http://services.aonaware.com/DictService/DictService.asmx?wsdl</wsdl.file>
<composite.file>dictionary</composite.file>
<service.name>Dictionary</service.name>
......
......@@ -43,10 +43,10 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<composite.file>helloworld-wired</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
<method.params>' '</method.params>
</properties>
</project>
......@@ -43,10 +43,10 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<composite.file>helloworld-pojo</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
<method.params>' '</method.params>
</properties>
</project>
......@@ -47,7 +47,6 @@
<composite.file>helloworld-rmi-client</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
<method.params>' '</method.params>
</properties>
</project>
......@@ -45,9 +45,6 @@
<properties>
<composite.file>helloworld-rmi-server</composite.file>
<service.name>''</service.name>
<method.name>''</method.name>
<method.params>''</method.params>
</properties>
</project>
......@@ -43,10 +43,10 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<composite.file>helloworld-script</composite.file>
<service.name>runnable</service.name>
<method.name>run</method.name>
<method.params>' '</method.params>
</properties>
<repositories>
......
......@@ -48,7 +48,6 @@
<composite.file>helloworld-ws-client</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
<method.params>' '</method.params>
</properties>
<build>
......
......@@ -45,9 +45,6 @@
<properties>
<composite.file>helloworld-ws-server</composite.file>
<service.name>''</service.name>
<method.name>''</method.name>
<method.params>''</method.params>
</properties>
</project>
......@@ -44,6 +44,7 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<wsdl.file>http://webservices.daehosting.com/services/isbnservice.wso?wsdl</wsdl.file>
<composite.file>isbntest</composite.file>
<service.name>Verifier</service.name>
......
......@@ -22,7 +22,7 @@
*
* Author: Nicolas Dolet
*
* Contributor(s): Philippe Merle
* Contributor(s): Philippe Merle, Christophe Demarey
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
......@@ -39,6 +39,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<logging.conf.file>../../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
</properties>
<build>
......@@ -58,7 +59,7 @@
<dependencies>
<dependency>
<groupId>org.ow2.frascati.factory</groupId>
<artifactId>frascati-factory-tools</artifactId>
<artifactId>frascati-factory-plugin</artifactId>
<version>${project.version}</version>
</dependency>
......@@ -87,26 +88,28 @@
<!-- To execute an SCA composite type 'mvn -Prun'. -->
<profile>
<id>run</id>
<build>
<defaultGoal>exec:exec</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<plugins>
<plugin>
<groupId>org.ow2.frascati.factory</groupId>
<artifactId>frascati-factory-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Djava.util.logging.config.file=../../distribution/standalone/src/main/conf/logging.properties</argument>
<argument>-classpath</argument>
<classpath />
<argument>org.ow2.frascati.factory.Launcher</argument>
<argument>${composite.file}</argument>
<argument>${service.name}</argument>
<argument>${method.name}</argument>
<argument>${method.params}</argument>
</arguments>
<loggingConfFile>${logging.conf.file}</loggingConfFile>
<composite>${composite.file}</composite>
<service>${service.name}</service>
<method>${method.name}</method>
<methodParams>${method.params}</methodParams>
</configuration>
</plugin>
</plugin>
</plugins>
</build>
</profile>
......
......@@ -43,10 +43,10 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<composite.file>twitter-client</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
<method.params>' '</method.params>
</properties>
</project>
......@@ -43,6 +43,7 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<wsdl.file>http://www.webservicex.net/globalweather.asmx?wsdl</wsdl.file>
<composite.file>twitter-weather</composite.file>
<service.name>tw</service.name>
......
......@@ -43,6 +43,7 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<wsdl.file>http://ws.xwebservices.com/XWebEmailValidation/V2/XWebEmailValidation.wsdl</wsdl.file>
<composite.file>verifymail</composite.file>
<service.name>Verifier</service.name>
......
......@@ -44,6 +44,7 @@
</parent>
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<wsdl.file>http://www.webservicex.net/globalweather.asmx?wsdl</wsdl.file>
<composite.file>weather</composite.file>
<service.name>Weather</service.name>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment