-
1. Re: Resteasy header in custom composer don't work - i think ?
mageshbk Jan 21, 2014 7:56 AM (in response to l.sroka)You might have hit this issue:
Which version are you using?
-
2. Re: Resteasy header in custom composer don't work - i think ?
l.sroka Jan 21, 2014 9:23 AM (in response to mageshbk)SY version 1.1.0 with eap 6.1
I have also try:context.setProperty("Access-Control-Allow-Origin", "*").addLabels(new String[] { EndpointLabel.REST.label() }); // also HTTP tested
super.mapTo(context, target);
-
3. Re: Re: Resteasy header in custom composer don't work - i think ?
mageshbk Jan 21, 2014 9:55 PM (in response to l.sroka)You will need to add the header filter in the config like this
<resteasy:contextMapper class="com.example.switchyard.rest_switchyard.MyTestComposer" includes=".*"/>
or like this
<resteasy:contextMapper class="com.example.switchyard.rest_switchyard.MyTestComposer" includes="test-my-head"/>
regards,
Magesh
-
4. Re: Re: Re: Resteasy header in custom composer don't work - i think ?
l.sroka Jan 22, 2014 3:11 AM (in response to mageshbk)Thanks for advice but i still don't get this header in my response.
I have added as following :<resteasy:binding.rest>
<resteasy:contextMapper class="com.example.switchyard.rest_switchyard.MyTestMapper" includes=".*" />
<resteasy:interfaces>com.example.switchyard.rest_switchyard.RestJson</resteasy:interfaces>
<resteasy:contextPath>test</resteasy:contextPath>
</resteasy:binding.rest>
And in MyTestMapper:
public class MyTestMapper extends RESTEasyContextMapper {
@Override
public void mapTo(Context context, RESTEasyBindingData target) throws Exception {
super.mapTo(context, target);
target.addHeader("test-my-head", "lol");
}
}
Also i have try:
context.setProperty("test-my-head", "lol").addLabels(new String[]{EndpointLabel.HTTP.label()}); super.mapTo(context, target);
Here is my header response (plain text from chrome-console) without my eg. "test-my-head"
- HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: application/json Transfer-Encoding: chunked Date: Wed, 22 Jan 2014 07:54:24 GMT
What am I doing wrong ?
-
5. Re: Resteasy header in custom ContextMapper don't work - i think ?
l.sroka Feb 4, 2014 5:01 AM (in response to l.sroka)bump, bump
Hello Magesh, did you test it with my example ?
Sorry to bother, but your answer is very important for me and my team.Thanks...
-
6. Re: Resteasy header in custom ContextMapper don't work - i think ?
trohovsky Feb 4, 2014 1:08 PM (in response to l.sroka)Hi Lukasz,
just guessing, but doesn't work this?
context.setProperty("test-my-head", "lol", Scope.MESSAGE);
super.mapTo(context, target);
Tomas
-
7. Re: Re: Resteasy header in custom ContextMapper don't work - i think ?
mageshbk Feb 4, 2014 9:35 PM (in response to l.sroka)Oops! Missed the notification that you have replied earlier. In JAX-RS, to propagate a header, you should be working with Response object and set the header there. Similarly, in SwitchYard in order for the headers to propagate, you need to design you REST interface methods with a Response as return value.
@GET @Produces(MediaType.APPLICATION_JSON) public Response fetchAll(); @GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON) public Response fetchJson(@PathParam("id") String id); @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response addJson(ContractJson c); @PUT @Path("{id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response updateJson(ContractJson c, @PathParam("id") String id);
-
8. Re: Resteasy header in custom ContextMapper don't work - i think ?
l.sroka Feb 5, 2014 3:35 AM (in response to mageshbk)I didn't notice this return type Response in any doc.
Thank you.