Commit 48b4cd6e authored by Lionel Seinturier's avatar Lionel Seinturier

Improve the Jetty OSGi example.

parent d2d355aa
......@@ -3,13 +3,14 @@ Tinfi 1.1.1
* move to sca-model 2.0.0
* FCOOCtrlNoIntentSourceCodeGenerator for scaPrimitive and scaComposite
membranes with no intent interceptor (feature requested by Nicolas P.)
* OSGi implementation type for the SCA Assembly Language EMF parser
Tinfi 1.1
---------
* add a setFcContentClassName method in the SCA Content control interface
(suggested by Valerio)
* EMF parser for the SCA Assembly Language
* SCA Assembly Language EMF parser
* new optimization level source code generator (ultra-merge) for inlining
applications
* move to Juliac 2.2.1
......
This example the use of the OSGi implementation type in a .composite file. Two
components are included in the composite: a Java component which steers a Jetty
HTTP server bundle.
To compile and run the example:
mvn test
......@@ -24,9 +24,6 @@
<tinfi.run.interface>r</tinfi.run.interface>
</properties>
<!-- ============================= -->
<!-- Dependency for generated code -->
<!-- ============================= -->
<dependencies>
<dependency>
<groupId>org.ow2.frascati.tinfi</groupId>
......@@ -91,6 +88,11 @@
<opt>org.objectweb.fractal.juliac.felix.FCOOCtrlSourceCodeGenerator</opt>
<opt>OO</opt>
</opts>
<mixins>
<mixin>org.ow2.frascati.tinfi:frascati-tinfi-mixins:${project.version}:sources</mixin>
<mixin>org.objectweb.fractal.julia:julia-mixins:${julia.version}:sources</mixin>
<mixin>org.objectweb.fractal.juliac.osgi:juliac-osgi-mixins:${juliac.version}:sources</mixin>
</mixins>
<adls><adl>${tinfi.run.component}</adl></adls>
<modules>
<module>org.ow2.frascati.tinfi:frascati-tinfi-oo:${project.version}</module>
......
......@@ -23,6 +23,17 @@
package example.jetty;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.ConnectException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Dictionary;
import java.util.Hashtable;
import junit.framework.Assert;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
......@@ -30,21 +41,87 @@ import org.osoa.sca.annotations.Reference;
public class ClientImpl implements Runnable {
public ClientImpl() {
Console.println("CLIENT created");
System.err.println("CLIENT created");
}
@Init
public void init() {
Console.println("CLIENT initialized");
System.err.println("CLIENT initialized");
}
@Reference
public void setPrintService( ManagedService service ) {
this.s = service;
}
private ManagedService s;
public void run() {
try {
innerRun();
}
catch (IOException e) {
throw new RuntimeException(e);
}
catch (ConfigurationException e) {
throw new RuntimeException(e);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
private ManagedService s;
private void innerRun()
throws IOException, ConfigurationException, InterruptedException {
// Let some time for Jetty to start up
Thread.sleep(1500);
try {
load("http://localhost");
String msg = "Jetty server should have thrown FileNotFoundException";
Assert.fail(msg);
}
catch( FileNotFoundException fnfe ) {
/*
* Jetty does not have any file to serve so the throwing of
* FileNotFoundException is the correct behavior. This means that
* the HTTP request has been accepted and served with a 404 return
* code. Else, ConnectException would have been thrown.
*/
}
/*
* Update the configuration of Jetty by changing the TCP port number.
*/
Dictionary dict = new Hashtable();
dict.put("org.osgi.service.http.port","8080");
s.updated(dict);
/*
* Check that Jetty does no longer serve requests on TCP port number 80.
*/
try {
load("http://localhost");
String msg = "Jetty server should have thrown ConnectException";
Assert.fail(msg);
}
catch( ConnectException ce ) {}
/*
* Check that Jetty serves requests on TCP port number 8080.
*/
try {
load("http://localhost:8080");
String msg = "Jetty server should have thrown FileNotFoundException";
Assert.fail(msg);
}
catch( FileNotFoundException fnfe ) {}
}
@Reference
public void setPrintService( ManagedService service ) {
this.s = service;
private void load( String url ) throws IOException {
System.err.println("Loading URL: "+url);
URL u = new URL(url);
URLConnection uc = u.openConnection();
uc.getInputStream();
}
}
\ No newline at end of file
package example.jetty;
/***
* OW2 FraSCAti Assembly Factory Examples : HelloWorld
* Copyright (C) 2008 INRIA, USTL
* Juliac
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -17,19 +16,35 @@ package example.jetty;
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: Damien.Fournier@inria.fr
* Contact: Lionel.Seinturier@univ-lille1.fr
*
* Author: Damien Fournier
* Author: Lionel Seinturier
*/
package example.jetty;
import java.io.PrintStream;
import org.junit.Test;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.ow2.frascati.tinfi.TinfiDomain;
public class Console {
/**
* Test the <code>Jetty.composite</code> component.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.1.1
*/
public class JettyTestCase {
public static PrintStream ps = System.err;
public static void println( String msg ) {
ps.println(msg);
@Test
public void run()
throws
ClassNotFoundException, InstantiationException, IllegalAccessException,
IllegalLifeCycleException, NoSuchInterfaceException,
InstantiationException, java.lang.InstantiationException {
Runnable r = TinfiDomain.getService("Jetty",Runnable.class,"r");
r.run();
}
}
......@@ -17,6 +17,7 @@
<module>helloworld-composite</module>
<module>helloworld-no-intent</module>
<module>helloworld-pojo</module>
<module>jetty-osgi</module>
<module>ultra-merge-helloworld</module>
</modules>
......
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