register server wide javax.ws.rs.client.ClientRequestFilter on JBoss EAP 7 - jax-rs

Is it possible to register a javax.ws.rs.client.ClientRequestFilter server wide on JBoss EAP 7? I would like to intercept all outbound JAX-RS calls to dynamically add some context information in HTTP headers.
For JAX-WS calls I was able to do this with https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/developing_web_services_applications/#jax_ws_handler_chains. I can't find any documentation on a similar mechanism for JAX-RS.
Or alternatively, is there maybe another way to intercept outbound HTTP calls in general?

For a per server solution, according to Using HttpHandler class in Undertow "you need to package your handler(s) into a module, and configure custom-filter in undertow subsystem."
The module.xml example and undertow configuration has been given as well as filter source code!
Update
There's an example of using the HTTPExchange here though I dont really care much for that site. SO also has this slightly related example - it does look like it can work similarly to the JAX-WS Handlers/Interceptor How to properly read post request body in a handler
Another good example file upload using httphandler I know they're different that dealing with JAX-RS but still may apply.

I implemented it by creating a module with the following contents:
package be.fgov.kszbcss.tracer.jaxrs;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
public class TracerResteasyClientBuilder extends ResteasyClientBuilder {
#Override
public ResteasyClient build() {
return super.build().register(TracerJaxRsClientRequestFilter.class);
}
}
/META-INF/services/javax.ws.rs.client.ClientBuilder
be.fgov.kszbcss.tracer.jaxrs.TracerResteasyClientBuilder
And registering it as a global module on JBoss EAP.

Related

can't find my url service on jax-rs and wildfly

I have this service
#ApplicationPath("/services") public class MyRestEasyApplication extends Application {
Packeged package bitsexcel.ws.resteasy.services; My project is named RsJavaWeb and run in this url http://localhost:8080/RsJavaWeb/ on Wilfly Server
I have not web.xml descriptor with nothing except <welcome-file-list>
I can't find my service in any url
I tried with:
http://localhost:8080/RsJavaWeb/services/person/1
http://localhost:8080/RsJavaWeb/ ?
And ever more but I can't find the service
Find the context root of your application (you can see it from WildFly UI console).
Then you should send requests at http://localhost:8080/{context-root}/services/...

Request not hitting spring boot embeded server through tomcat and browser

Am trying to hit my rest API in spring boot with the embeded server configured through browser and postman, but the request doesn't hit the server and am getting 404-not found am pretty new to springboot , please help me in this as in what to check further so that i can test my rest API
This could be due to couple of reasons
Try the following
Ensure the port you are specifying is correct
Ensure the end point you are specifying exist
Ensure the request you are sending is of correct REST action type (GET,POST etc)
Ensure your controller class is available in the same package in which Application class (with #SpringBootAnnotation) exists, else you will have to use #ComponentScan to make sure your controller class is scanned and endpoints available to receive traffic
Most likely, above should help :) If not, you'll need to describe what is done in the application so far

Mule: How to prevent WS Consumer generating headers in the request?

I'm using WS Consumer component to call an external Web Servcie and
I'm looking for a way to prevent generation of a SOAP header in the request.
I've found how to do this when using cxf component explicitly:
<cxf:configuration enableMuleSoapHeaders="false"/>
and then same in <cxf:jaxws-client ...
But I can't figure out how to achieve the same when using WS Consumer.
So, can someone pls advice?
Thank you,
Ok, I've found the answer by myself.
Basically, WS Consumer (v3.7) doesn't have an attribute similar to the enableMuleSoapHeaders from the cxf component.
So, you'll need to code the logic in java.
First, you need to code your own CXF interceptor that would go through the message and remove the unnecessary headers.
Then, you need to create a cxf configuration file (the default name is cxf.xml) and put it into the mule project classpath.
Once this is done, Mule will call the interceptor for every cxf message processed and remove the headers.
For more info about coding and configuring cxf interceptor look at the apache documentation here.

How to invoke MobileFirst adapters with curl and SOAP?

Good day,
We have the requirement to call a MobileFirst Adapter via curl and SOAP, ommiting authentication.
An example how to do it with curl and application/x-www-form-urlencoded looks like this, but we also require to invoke the adapter using SOAP.
curl -XPOST -d 'adapter=PushAdapter&procedure=sendNotifications&parameters=["[\"UserA\",\"UserB\"]", "Pushed.you"]' http://localhost:10080/application/invoke
The reason is, we want to trigger sending PushNotifications through a network zone that only allows SOAP.
We are open to different suggestions, like implementing a new JavaAdapter (not JS), implementing an extra WebService, or anything that pops up which could fulfil the requirement in an acceptable way.
I hope someone can come up with an idea how to call Adapters via SOAP, ommiting authentication.
Thank you,
gizmore
---- Edit ---
I added a new Java Adapter, like the video from Hasan suggests.
Thank you very much for that hint :)
There i added a WebService like this:
#WebService
#Path("/soap")
#OAuthSecurity(enabled=false) // Disable the imfAuthentication :)
public class ExternalPushService {
#POST
#Path("/push")
#WebMethod(action="push")
public String push(#WebParam(name="name") String name) {
return name + "ABC";
}
}
I can now do HTTP POST Requests to the http://localhost:10080/app/adapters/PushBridge/soap/push Endpoint, but the SOAP is not parsed.
Instead i get the complete Envelope in the "name" parameter.
If i do a SOAP call to PushBridge/soap, i get 405 Method not allowed.
Does someone have an idea, how i can get SOAP working out of the box there?
Answer is: NO
when you adding #WebService in your java adapter this the warring facing:
Problem description:This annotation requires a web service project. Convert the Java project to a web project targeting the specified runtime environment
SOAP base service are based on the JAX-WS specification.
but
Java adapters are based on the JAX-RS specification.
https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/server-side-development/java-adapter/

Jboss 7.1.1 - Jackson ContextResolver<ObjectMapper> works only on one deployment

I have two rest webapps I want to deploy on Jboss 7.1.1. server.
Rest requests in both apps produces and consumes Json. I use jackson provider to serialize and deserialize objects.
Now, I need custom ObjectMapper configurations for each webapp.
So to resolve this problem I added #Provider classes implementing ContextResolver. One for each project. Fe. One of my class looks like that:
#provider
#Produces(MediaType.APPLICATION_JSON)
#Consumes(MediaType.APPLICATION_JSON)
public class JacksonConfig implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper;
public JacksonConfig()
{
objectMapper = new ObjectMapper();
objectMapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
}
#Override
public ObjectMapper getContext(Class<?> objectType) {
return objectMapper;
}
}
It works well when I deploy only one of this projects on jboss. When I try to deploy both, only first initialized project use defined objectMapper. Other one never calls getContext method from ContextResolver class. What could I do wrong?
EDIT!:
After a lot of trials I decided to change method of parsing json from jackson to staxon. I hoped at least this method will work well. But not... Serialization works perfectly on both deployed applications. But again, somehow jboss decided to use jackson instead of staxon in deserialization process. Again always application which I call first after deployment works well. But Second one using jackson (no idea why...) which calls exceptions. Always...
Is there any problem with Jboss? Probably I'm just doing something wrong but I have no idea where. Anybody has idea where should I look?
Looks like I found solution for this problem.
It was known issue of resteasy, that can be removed by build-in option:
To solve this problem I just had to add param to web.xml of my projects:
<context-param>
<param-name>resteasy.use.deployment.sensitive.factory</param-name>
<param-value>false</param-value>
</context-param>
I found this solution in Resteasy jira. It's really strange for me that there is no info in any jboss or resteasy related documentation...