Print Inbound and outbound Payload logs jersey REST API And Spring - java

I am using Spring with Jersey REST API for REST webservices.
I want print the inbound and outbound Payloads (XML Requests Data) to log file/console.
Is there any way todo this.
Thanks

LoggingFilter can help you with that. You need to provide an instance of this filter to JAX-RS runtime - by default the entity is not printed. See code samples is Registering Resources and Providers in Jersey 2 to see how to register your logger (I am using LoggingFilter in these samples).

Related

SPRING WS - route based on path

shall be possible to implement a soap webservice in Spring using #Endpoint annotation and route all message that are sent to a specific endpoint path to the same method?
I need the "behavior" already in place with #PayloadRoot or #SoapAction but "based" on endpoint path of the request.
Thanks in advance for support.

Moving ClientFilter from Jersey to Jersey 2

I am trying to migrate the usages of Jersey Client in my codebase from com.sun.jersey.client to org.glassfish.jersey.client.
In multiple parts of the codebase I am creating classes that inherit from ClientFilter and override the handle method.
What is the replacement of ClientFilter in Jersey 2 and how should I change the places I use it?
See Jersey docs section Client Filters. Basically there are ClientRequestFilter and ClientResponseFilter. The former is called before the request goes out and the latter is called on the incoming response. See also this post for more info on the flow.

Spring Cloud: How to define default fallback for Hystrix in Zuul gateway?

I am using Spring Cloud Brixton.M3 and Spring Boot 1.3.0.RELEASE. I am sort of new in this (especially in Spring Cloud). I have created Registry Server (i.e. Eureka instance), Config server and Gateway.
As per my requirement I am intercepting each request hitting the gateway in one of my Filter to extract required information from Header and based upon that I am throwing exception or forwarding / verifying that request using Feign Client. Some time hystrix throw HystrixRuntimeException when it couldn't reach out to respective services or because of any other issues.
So What I want is:
Provide default fallback method for every forwarding request, so that I can read and process it accordingly.
Global Exception handling other than #ControllerAdvice since I am not providing any custom #HystrixCommand and Controller to call services (AOP based solution ?).
Is it possible to intercept every failed request and retry them for certain number of times ? Internally it might be happening but can I override this functionality and handle each failed request either because of TimedOutException or because of HttpConnectionPool exception ?
Update
Is it a good practice to provide own routing in Zuul gateway ? using #RestController and #HystrixCommand together ? (I think its a bad idea, because over the period of time we will end up with lots of controllers and hence actual use of intelligent routing wouldn't work as expected)
Currently there is an open issue for fallbacks with feign. There is also an open issue for fallbacks with zuul.

Camel Cxf: How can I change the namespace of my incoming message?

I have to change the namespace of the incoming messages to our webservice.
The consumer route looks like the following:
from("cxf:/myservice?serviceClass=myServiceClass")...
I've tried to add somehow an interceptor to this(parameter properties.in, properties.inInterceptors?), but I don't get it how to configure it to my route.
We are not configuring our cxf endpoints in spring so I have to solve it with additional parameters to the route.
I think an interceptor with the transformation feature mentioned in the cxf documentation is the right solution, but I was not able to configure it correctly.
How can I add an interceptor to the route?
Or is there another way to change the namespace of the incoming message?
kind regards,
soilworker
I've found a solution:
It is possible to say something like from(endpoint), so I've created an instance of CxfEndpoint and there I can set the cxfEndpointConfigurer.
In this configurer I can add an interceptor which removes the namespace(see transformation feature of cxf).
Maybe it also works somehow with the from(uri) syntax, but I don't know how.

Spring 3 JSON with MVC

Is there a way to build Spring Web calls that consume and produce application/json formatted requests and responses respectively?
Maybe this isn't Spring MVC, I'm not sure. I'm looking for Spring libraries that behave in a similar fashion to Jersey/JSON. The best case would be if there was an annotation that I could add to the Controller classes that would turn them into JSON service calls.
A tutorial showing how to build Spring Web Services with JSON would be great.
EDIT: I'm looking for an annotation based approach (similar to Jersey).
EDIT2: Like Jersey, I am looking for REST support (POST,GET,DELETE,PUT).
EDIT3: Most preferably, this will be the pom.xml entries and some information on using the spring-js with jackson Spring native version of things.
In case other ppl get here later:
http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/
was the most useful link for me. That finally made me understand the model (after less than a day of searching).
You can certainly have controllers that return a View which is in JSON output. Take a look at the Spring-JSON project.
To consume requests in JSON I would assume you would just want a controller to pass a request parameter off to a JSON library which could parse the data?
There is no pre-packaged way to do what you want as Jersey is nicely integrated with Spring via the Jersey-Spring API so there's really no reason to re-invent the wheel.
Check this one out
Adding support for JSON and XML views
Source code for Spring Finance Manager
Since spring-mvc 3.0 official support for Ajax remoting with JSON is provided as part of Spring MVC. This includes support for generating JSON responses and binding JSON requests using the Spring MVC #Controller programming model.
see here
This feature is now part of Spring since version 3.0. You can simply use the #ResponseBody annotation to specify that you want the return value from your request handler methods to be serialized to JSON and sent as the response body. See http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/
It seems that DWR framework looks very close to what you want to get.
You can configure Spring MVC interceptors through handler mappings and then use the mappings to transform the returning data to JSON. The handler configuration can be done in xml (no need to recompile), and this can be completely transparent to the rest of the application.
It's fairly easy to annotate controllers with some annotation, and then hook up the BeanFactory bootstrap process to register the controllers within some handler mapping process.
I have used this approach to transform the result from spring controllers into GWT RPC calls.
You can also use Spring AOP to intercept controller method calls and unwrap/wrap the requests from/to JSON.

Categories