Hi Romain,
I converted your first email into github issues. Neither is major, but I currently cannot commit to any schedule.
https://github.com/membrane/service-proxy/issues/146https://github.com/membrane/service-proxy/issues/147But reading your second email I think you are already past that point anyways. So regarding custom language extensions:
Yes, it is possible to use the
@MC* annotations for an easy way of extending the Membrane/Spring XML configuration language.
Basically, you have to
1. create your own project, preferrably using Maven.
2. add a dependency on service-proxy-annot and service-proxy-core
3. use the @MC* annotations in your code:
3a. one @MCMain annotation
3b. and as many @MCElement/@MCAttribute annontations as you like
4. activate the annotation processor
com.predic8.membrane.annot.SpringConfigurationXSDGeneratingAnnotationProcessor
in your compiler.
5. add META-INF/spring.handlers and META-INF/spring.schemas as resource files
6. implement a NamespaceHandler class for your new namespace (copy
https://github.com/membrane/service-proxy/blob/master/war/src/main/java/com/predic8/membrane/servlet/config/spring/NamespaceHandler.java to your own java package).
Effectively you have to create your own namespace for the new Spring configuration elements you are about to define.
You need to:
A. Choose a namespace URI.
B. Choose a Java package for the parser classes. (Some autogenerated, some not.)
C. Choose a file name for the autogenerated XML Schema file. (will be put into the same java package)
D. (Possibly, if you want to make use of an XML editor) Upload the autogenerated XML schema file to some URL where your XML editor can retrieve it.
Then you write (step 3a)
@MCMain(
outputPackage="B",
outputName="C",
targetNamespace="A")
in the one place where your @MCMain is. (@MCMain just contains meta-information and activates the @MC... processing. Which class is annotated with @MCMain does not matter: Just use it once in your project.)
Declare your interceptor (step 3b), for example
@MCElement(name="myInterceptor", configPackage="B")
public class MyInterceptor extends AbstractInterceptor {
public String getFoo() {...}
@Required
@MCAttribute
public void setFoo(String foo) {...}
}
Write (step 5) one line
A=B
into META-INF/spring.handlers (where ':' is escaped by a '\' in A) and one line
A=B/C
into META-INF/spring.schemas (where ':' is escaped by a '\' in A and where '.' is replaced by '/' within B).
Then package your project with dependencies and start Membrane using a Spring context using a config file like
<spring:beans xmlns="
http://membrane-soa.org/proxies/1/"
xmlns:spring="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="A"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd A D">
<router>
<serviceProxy port="2000">
<my:myInterceptor foo="somevalue" />
<target host="
www.predic8.de" />
</serviceProxy>
</router>
</spring:beans>
(Simply drop the "A D" line if you chose not to do D.)
All this is done by service-proxy-war, which I suggest you have a look at. In this case,
A =
http://membrane-soa.org/war/1/B = com.predic8.membrane.servlet.config.spring
C = router-conf.xsd
D =
http://membrane-soa.org/schemas/war-1.xsdThe service-proxy-war source code can be found at
https://github.com/membrane/service-proxy/tree/master/war .
As we plan to write a tutorial for exactly this case, I'd be happy to talk you through any problems you run into. Unfortunately, we haven't started the tutorial yet - but now I'll use this email as a template. ;)
Best, Tobias