You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by hwaastad <he...@waastad.org> on 2014/06/05 23:48:24 UTC

cxf advanced examples

Hi,
this is a humble request for input on how to implement cxf
interceptor/filters in cxf (ws/rs) and tomee.

At cxf home the docs usually shows spring beans implementation but I "old
school" and like to do it the ee6 way ;-)

Does anyone know any resources?

Maybe something for tomee examples also?
I would very much like to contribute, but right now I'm stuck with http
filters....

br hw



--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Romain Manni-Bucau <rm...@gmail.com>.
2. yes
3. @WebFilter


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-06 9:11 GMT+02:00 hwaastad <he...@waastad.org>:
> Hi,
>
> 2. @InIncterceptos/@OutInterceptors.....?
>
> 3. @webfilter or @Provider @PreMatching and inplementing
> ContainerRequestFilter?
>
> br hw
>
>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669933.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by hwaastad <he...@waastad.org>.
Hi,

2. @InIncterceptos/@OutInterceptors.....?

3. @webfilter or @Provider @PreMatching and inplementing
ContainerRequestFilter?

br hw





--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669933.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Romain Manni-Bucau <rm...@gmail.com>.
1. yes in tomee but not always portable

2. also possible through cxf annotations

3. can be with annotation only too

but globally yes


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-06 8:27 GMT+02:00 hwaastad <he...@waastad.org>:
> That means, in TomEE perspective, sometime this autumn?
>
> I agree, better to wait for cxf 3 in tomee.
>
> So, Im I right defining it like this:
>
> 1. Providers is OK in Application
> 2. interceptors i resources.xml/tomee.xml and openejb-jar.xml config
> 3. filters: web.xml(?)
>
> br hw
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669931.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by hwaastad <he...@waastad.org>.
That means, in TomEE perspective, sometime this autumn?

I agree, better to wait for cxf 3 in tomee.

So, Im I right defining it like this:

1. Providers is OK in Application
2. interceptors i resources.xml/tomee.xml and openejb-jar.xml config
3. filters: web.xml(?)

br hw



--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669931.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

it is not but we could support it but i'm almost -1 since jaxrs2 will
give portable hooks


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-06 6:59 GMT+02:00 hwaastad <he...@waastad.org>:
> Hi,
> thanks alot. I guess knowing the service and openejb-jar configuration is
> important.
>
> I wonder, cxf providers can also be configured in openejb-jar. But it can
> also be added to Application (ApplicationPath).
> Do you know if something similar is possible for filters/intercaptors?
>
> br hw
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669929.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Anthony Fryer <ap...@hotmail.com>.
Hwaastad, just interested to know where you are?  I used to live in
Switerland and going snowboarding in the swiss and french alps.  Your pic
looks like that.  Am i close?



--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669947.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Romain Manni-Bucau <rm...@gmail.com>.
You can still write
http://svn.apache.org/repos/asf/tomee/tomee/trunk/examples/server-events/src/main/java/org/superbiz/event/AutoDiscoveredListener.java
and modify AppInfo to add the interceptors. Globally adding in the
ejbJarInfo of your app a new pojoConfigurations which is just what is in
xml.



Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-06 11:26 GMT+02:00 hwaastad <he...@waastad.org>:

> I'm going to stay faithful to TomEE.
> Don'nt need no portability :-)
>
> @Anthony: my investigations are also because I'm not to keen on xml
> programming.
> On the other hand, I get Romains angle.
>
> br hw
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669945.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: cxf advanced examples

Posted by hwaastad <he...@waastad.org>.
I'm going to stay faithful to TomEE.
Don'nt need no portability :-)

@Anthony: my investigations are also because I'm not to keen on xml
programming.
On the other hand, I get Romains angle.

br hw



--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669945.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Anthony Fryer <ap...@hotmail.com>.
Thanks but that would waste time that can be valuably spent on other more
deserving things.



--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669944.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Yes, but that's why it is often in files and not in code.

If you really need it we can add it but it was just to explain why it was
like it today.



Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-06 10:16 GMT+02:00 Anthony Fryer <ap...@hotmail.com>:

> I know you're right and usually at some point we have to configure
> something
> that is specific to an implementation.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669942.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: cxf advanced examples

Posted by Anthony Fryer <ap...@hotmail.com>.
I know you're right and usually at some point we have to configure something
that is specific to an implementation.



--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669942.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Romain Manni-Bucau <rm...@gmail.com>.
basically this is not portable. You can also observes tomee internal events
and modify OpenEjbJar (openejb-jar.xml mapping) to add it programmatically.



Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-06 9:34 GMT+02:00 Anthony Fryer <ap...@hotmail.com>:

> I was hoping there was more to it than that.  Like being able to inject
> interceptors and do away with config in resources.xml and openejb-jar.xml.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669937.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: cxf advanced examples

Posted by Anthony Fryer <ap...@hotmail.com>.
I was hoping there was more to it than that.  Like being able to inject
interceptors and do away with config in resources.xml and openejb-jar.xml.



--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669937.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hmm, it is already in TomEE and better than it can be in CXF since it
supports EJBs (think to it and trnsactional endpoints, that's just
awesome)


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-06 9:24 GMT+02:00 Anthony Fryer <ap...@hotmail.com>:
> The CDI support looks like its coming along...
>
> http://java.dzone.com/articles/apache-cxf-30-cdi-11-support
>
>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669935.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Anthony Fryer <ap...@hotmail.com>.
The CDI support looks like its coming along...

http://java.dzone.com/articles/apache-cxf-30-cdi-11-support





--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669935.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by hwaastad <he...@waastad.org>.
Hi,
thanks alot. I guess knowing the service and openejb-jar configuration is
important.

I wonder, cxf providers can also be configured in openejb-jar. But it can
also be added to Application (ApplicationPath).
Do you know if something similar is possible for filters/intercaptors?

br hw



--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669929.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: cxf advanced examples

Posted by Anthony Fryer <ap...@hotmail.com>.
I have a simple cxf interceptor in a project that just forces the text of an
xml element in a web service response to be wrapped in a CDATA element.  It
would probably make for a good example.

There's 2 classes I have to implement the interceptor...

public class CDataContentWriter extends DelegatingXMLStreamWriter {
	private static final Pattern XML_CHARS = Pattern.compile("[&<>]");
	private String currentElementLocalName;

	public CDataContentWriter(XMLStreamWriter writer) {
		super(writer);
	}

	@Override
	public void writeCharacters(String text) throws XMLStreamException {
		boolean useCData = XML_CHARS.matcher(text).find();
		if (useCData) {
			super.writeCData(text);
		} else {
			super.writeCharacters(text);
		}
	}

	@Override
	public void writeStartElement(String prefix, String local, String uri)
			throws XMLStreamException {
		currentElementLocalName = local;
		super.writeStartElement(prefix, local, uri);
	}
}

public class CDataWriterInterceptor extends
AbstractPhaseInterceptor<Message> {

	public CDataWriterInterceptor() {
		super(Phase.PRE_STREAM);
		addAfter(AttachmentOutInterceptor.class.getName());
	}

	@Override
	public void handleMessage(Message message) throws Fault {
		message.put("disable.outputstream.optimization", Boolean.TRUE);
		XMLStreamWriter writer =
StaxUtils.createXMLStreamWriter(message.getContent(OutputStream.class));
		message.setContent(XMLStreamWriter.class, new CDataContentWriter(writer));
	}
}

Then in my resources.xml (or you could use tomee.xml) i declare the
interceptor as a service...

<resources>
    ....
   <Service id="cdataWriterInterceptor"
class-name="au.com.cyberavenue.cxf.CDataWriterInterceptor"/>
   
</resources> 

Lastly, I had to create an openejb-jar.xml (located in my WEB-INF folder)
which is where i hook up the interceptor service to individual web
services...

<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">

  <ejb-deployment ejb-name="GetBoardingPassDataImpl">
    <properties>
      cxf.jaxws.out-interceptors = cdataWriterInterceptor
    </properties>
  </ejb-deployment>
  
  <ejb-deployment ejb-name="BoardingPassBarCodeImpl">
    <properties>
      cxf.jaxws.out-interceptors = cdataWriterInterceptor
    </properties>
  </ejb-deployment>
  
</openejb-jar>

So I ended up with 2 webservices where the response xml will have CDATA
elements instead of escaped strings.  Hope this helps.

Regards,

Anthony





--
View this message in context: http://openejb.979440.n4.nabble.com/cxf-advanced-examples-tp4669927p4669928.html
Sent from the OpenEJB User mailing list archive at Nabble.com.