Sigo experimentando con Apache Tuscany, hoy el objetivo es hacer un ejemplo con integración con spring. Mismo ejemplo que hicimos en :
http://emanuelpeg.blogspot.com/2010/05/desarrollar-un-ejemplo-con-apache.html Comenzamos escribiendo la interfaz:
@Remotable
public interface ExampleService {
String sayHello();
}
Su implementación :
@Service(ExampleService.class)
public class ExampleServiceImpl implements
ExampleService {
private String hello = "Holasss !!! \n";
public void setHello(String hello) {
this.hello = hello;
}
/**
* @see org.assembly.nornas.ExampleService#sayHello()
*/
@Override
public String sayHello() {
System.out.print("llamaron a Say");
return hello;
}
@Init
public void init() {
System.out.println("Starting with "+ExampleServiceImpl.class + " \n");
}
}
Ahora tenemos que configurar el beans de spring, en un archivo que llamaremos: appcontext-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sca="http://www.springframework.org/schema/sca"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd ">
<bean id="service.example" class="com.elpaquete.ExampleServiceImpl">
<property name="hello" value="Hola desde Spring!!" ></property>
</bean>
<sca:service name="ExampleService"
type="org.assembly.nornas.sandbox.service.example.ExampleService" target="service.example" />
</beans>
Notaron que además de declarar el bean le indicamos a Apache Tuscany cual es la interfaz de nuestro bean que va a ser un componente de Apache Tuscany.
Ahora escribimos el archivo ExampleSpring.composite:
<?xml version="1.0" encoding="UTF-8" ?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
targetNamespace="http://nornas"
xmlns:nornas="http://nornas"
name="Example" >
<component name="ExampleServiceComponent">
<implementation.spring location="spring-sandbox.xml" />
<service name="ExampleService">
<interface.java interface="org.assembly.nornas.sandbox.service.example.ExampleService"/>
<binding.ws uri="http://localhost:8080/nornas/ws" />
<t:binding.atom uri="http://localhost:8080/nornas/atom" />
<t:binding.jsonrpc uri="http://localhost:8080/nornas/jsonrpc" />
<t:binding.rss uri = "http://localhost:8080/nornas/rss"/>
<binding.sca />
</service>
</component>
</composite>
Notaron que la implementación del componente no se indica clase si no el archivo appcontext-spring.xml, Apache tuscany va a leer y buscar de ahí la implementación.
Ya lo tenemos, ahora vamos a hacer la clase main:
public class MainSpring {
public static void main(String[] args) throws IOException {
System.out.println("Starting ...");
SCADomain scaDomain = SCADomain.newInstance("ExampleSpring.composite");
System.out.println("Example in "+scaDomain.getURI());
System.in.read();
System.out.println("Stopping ...");
scaDomain.close();
System.out.println();
}
}
Si todo salio bien, en
http://localhost:8080/nornas/ws?wsdl va a estar wsdl de su web service soap.
Por ultimo las dependencias de maven:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6.SEC01</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-sca-api</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-core-spi</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-policy-security</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-data-api</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-atom-abdera</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-rss-rome</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-ws-axis2</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-jsonrpc-runtime</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-rmi-runtime</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-resource-runtime</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-http-runtime</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-jetty</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-spring</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-spring-runtime</artifactId>
<version>1.6</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>