0

I got a CXF OSGi Web service (based on the example demo in servicemix: https://github.com/apache/servicemix/tree/master/examples/cxf/cxf-jaxws-blueprint)

The Web service works fine and i call all the available implemented methods of the service.

My question is how can i retrieve the request inside a WS method and parse in a string XML format.

I have found that this is possible inside interceptors for logging, but i want also to the WS-Request inside my methods.

Stephan
  • 696
  • 15
  • 37
  • If you want the plain xml then why use jax ws? What do yo need the xml for? – Christian Schneider Feb 13 '17 at 09:21
  • i want the actual payload of the request as seen in my servicemix logs. To the question "What for do i need it" . I store the payload in my database for further future processing. – Stephan Feb 13 '17 at 09:27
  • I see here ( http://stackoverflow.com/questions/11038313/how-to-get-incoming-outgoing-soap-xml-in-a-simple-way-using-apache-cxf ) some ways to get the message from an interceptor as mentioned above , but i need that payload in me WS methods. – Stephan Feb 13 '17 at 09:29
  • One of the main goal of jax-ws and jaxb is to translate the payload into a tree of java Object. Getting the payload "as string" at the WebService level is simply a nonsense. If you really want the payload as string, you should not work at WebService level but at HTTP level. – Alexandre Cartapanis Feb 13 '17 at 10:21
  • We are missing the point. I do not mind if it is nonsense or not. My question is if it is possible something like that. As i said on my previous comment, i have an implementation that at some points stores the payload as a string in the database. Thats why the LoegEventSender or interceptors do not qualify my needs – Stephan Feb 13 '17 at 11:49

3 Answers3

1

For storing the request in the database I suggest to extend the new CXF message logging.

You can implement a custom LogEventSender that writes into the database.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Thank you for your proposal but this does not answer the actual question. How or if i can get inside my webmethod the request payload. – Stephan Feb 13 '17 at 09:44
0

I had similar requirement where I need to save data into DB once method is invoked. I had used ThreadLocal with LoggingInInterceptor and LoggingOutInterceptor. For example in LoggingInInterceptor I used to set the message into ThreadContext and in webservice method get the message using LoggingContext.getMessage() and in LoggingOutInterceptor I used to removed the message(NOTE: Need to be careful here you need to explictly remove the message from thread context else you will end up with memory leak, and also incase of client side code interceptors get reversed.

public class LoggingContext {

    private static ThreadLocal<String> message;

    public static Optional<String> getMessage() {
        return Optional.ofNullable(message.get());
    }

    public static void setMessage(final String message) {
        LoggingContext.message = new ThreadLocal<>();
        LoggingContext.message.set(message);
    }

}
Karthik Prasad
  • 9,662
  • 10
  • 64
  • 112
0

Not an answer to this question but i achieved to do my task by using JAXB in the end and do some manipulations there.

Stephan
  • 696
  • 15
  • 37