RE: How to access payload from REST 404 reply in cxfrs?

2015-11-10 Thread Steve Huston
I got this working... thank you to Sergey and Kalyan for your assistance. After 
following your trails around and learning some more, I found that the main 
issue was that I had defined the return type for my REST operation as String, 
so Camel was dutifully converting to that and I did not have a Response to get 
the code from. After I changed the return type from String to Response, things 
started working.

If it appears that I've got something confused still, I'm happy to hear about 
it. 

-Steve

> -Original Message-
> From: Steve Huston [mailto:shus...@riverace.com]
> Sent: Monday, November 02, 2015 6:36 PM
> To: users@camel.apache.org
> Subject: Re: How to access payload from REST 404 reply in cxfrs?
> 
> Thanks again, Sergey. I was able to register the provider using:
> 
>   class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
> 
> Then use it via:
> 
>  
> 
> However, it looks like there is no content available via the exception. Using
> the code:
> 
>InvocationTargetException exception =
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> InvocationTargetException.class);
>NotFoundException orig = (NotFoundException)(exception.getCause());
>CrewServiceDeniedError err =
> orig.getResponse().readEntity(CrewServiceDeniedError.class);
>logger.error("Incoming response: ", err.getReason());
>   logger.error("Incoming response (plain):",
> orig.getResponse().readEntity(String.class));
> 
> I get output at runtime:
> 
> [Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR
> my.module.ExceptionProcessor - Incoming response:
> [Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR
> my.module.ExceptionProcessor - Incoming response (plain):
> 
> So I'm back to wondering where the original payload from the REST 404
> response is. It gets logged from Camel as:
> 
> ID: 2
> Response-Code: 404
> Encoding: ISO-8859-1
> Content-Type: application/json
> Headers: {Accept=[application/json], breadcrumbId=[ID-Steves-MacBook-
> Pro-local-55129-1446506823854-1-7], content-type=[application/json],
> OriginalHeader=[{name=VerifyEmployeeRequest, version=1, scac=rraa,
> timeSent=null, uuid=abcd-1234}], pin=[1234], reason=[INIT],
> Server=[Jetty(9.2.11.v20150529)], transfer-encoding=[chunked], User-
> Agent=[Apache CXF 3.1.2]}
> Payload: { "employeeID": "bad-name", "reason": "id not found"
> }
> 
> 
> Thanks very much for any insight,
> 
> -Steve
> 
> > On Nov 2, 2015, at 3:52 PM, Sergey Beryozkin 
> wrote:
> >
> >
> > As I said you will need to register a JAXRS provider capable of
> > converting it, though I'm not sure right now what the syntax is with
> > cxfrs:bean:webService, looks like from
> > http://camel.apache.org/cxf-bean-component.html
> >
> > it is something like
> > cxfrs:bean:webService?providers=#jackson
> >
> > Cheers, Sergey
> > On 02/11/15 18:02, Steve Huston wrote:
> >> Thank you very much for your quick help, Sergey!
> >> I tried your solution and now get the following exception:
> >>
> >> [Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR
> >> org.apache.cxf.jaxrs.utils.JAXRSUtils - No message body reader has
> >> been found for class my.class.path.CrewServiceDeniedError,
> >> ContentType: application/json
> >>
> >> The code I have is:
> >>
> >>InvocationTargetException exception =
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> InvocationTargetException.class);
> >>NotFoundException orig =
> (NotFoundException)(exception.getCause());
> >>CrewServiceDeniedError err =
> >> orig.getResponse().readEntity(CrewServiceDeniedError.class);
> >>
> >> I created this class for the payload:
> >>
> >> public class CrewServiceDeniedError {
> >>
> >>private String employeeID;
> >>private String reason;
> >>
> >>public String getEmployeeID()
> >>{ return employeeID; }
> >>public void setEmployeeID(String id)
> >>{ employeeID = id; }
> >>
> >>public String getReason()
> >>{ return reason; }
> >>public void setReason(String r)
> >>{ reason = r; }
> >> }
> >>
> >> -Steve
> >>
> >>> On Nov 2, 2015, at 11:24 AM, Sergey Beryozkin 
> wrote:
> >>>
> >>> Hi
> >>> If you can access NotFoundException then what you can do next is to
> >>> do
> >>>
> >>> ErrorInfo errorInfo =
> >>> exception.getResponse().readEntity(ErrorInfo.class)
> >>>
> >>> where ErrorInfo is a custom class capturing a JSON error response,
> >>> you'd also need to register Jackson or other provider to get it
> >>> converted. Or read it as String.class and parse manually
> >>>
> >>> HTH, Sergey
> >>> On 02/11/15 16:15, Steve Huston wrote:
> >>>> I put this up on stackoverflow... if you have cxfrs expertise, could you
> please read this?
> >>>>
> >>>> How to access payload from REST 404 response in Camel cxfrs?
> >>>> http://stackoverflow.com/q/33445686/240342?sem=2
> >>>>
> >>>> Thanks,
> >>>> -Steve
> >>>>
> >>>
> >>
> >
> >
> > --
> > Sergey Beryozkin
> >
> > Talend Community Coders
> > http://coders.talend.com/



Re: How to access payload from REST 404 reply in cxfrs?

2015-11-03 Thread Steve Huston
Thank you for the idea, Kalyan, but that didn’t work.

Is it true that there’s no access to the payload one it’s touched? I can see 
the payload if no exception is thrown (e.g., a normal 200 response).

Thanks,
-Steve

> On Nov 3, 2015, at 1:56 AM, calyan.bandi  wrote:
> 
> Hi,
> 
> I am not sure if its works, but you can try enabling the option streamCache
> on the route from which the web service is invoked. When using cxfrs
> component with trace/debug enabled the payload (stream) received from server
> is flushed once it is displayed - be it in logs or in your application. In
> order to preserve it you can enable stream caching on the route.
> 
> Thanks,
> Kalyan
> 
> 
> 
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/How-to-access-payload-from-REST-404-reply-in-cxfrs-tp5773325p5773336.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



Re: How to access payload from REST 404 reply in cxfrs?

2015-11-03 Thread calyan.bandi
Hi,

I am not sure if its works, but you can try enabling the option streamCache
on the route from which the web service is invoked. When using cxfrs
component with trace/debug enabled the payload (stream) received from server
is flushed once it is displayed - be it in logs or in your application. In
order to preserve it you can enable stream caching on the route.

Thanks,
Kalyan



--
View this message in context: 
http://camel.465427.n5.nabble.com/How-to-access-payload-from-REST-404-reply-in-cxfrs-tp5773325p5773336.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How to access payload from REST 404 reply in cxfrs?

2015-11-02 Thread Steve Huston
Thanks again, Sergey. I was able to register the provider using:

 

However, it looks like there is no content available via the exception. Using 
the code:

   InvocationTargetException exception = 
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
InvocationTargetException.class);
   NotFoundException orig = (NotFoundException)(exception.getCause());
   CrewServiceDeniedError err = 
orig.getResponse().readEntity(CrewServiceDeniedError.class);
   logger.error("Incoming response: ", err.getReason());
logger.error("Incoming response (plain):", 
orig.getResponse().readEntity(String.class));

I get output at runtime:

[Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR 
my.module.ExceptionProcessor - Incoming response: 
[Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR 
my.module.ExceptionProcessor - Incoming response (plain):

So I’m back to wondering where the original payload from the REST 404 response 
is. It gets logged from Camel as:

ID: 2
Response-Code: 404
Encoding: ISO-8859-1
Content-Type: application/json
Headers: {Accept=[application/json], 
breadcrumbId=[ID-Steves-MacBook-Pro-local-55129-1446506823854-1-7], 
content-type=[application/json], OriginalHeader=[{name=VerifyEmployeeRequest, 
version=1, scac=rraa, timeSent=null, uuid=abcd-1234}], pin=[1234], 
reason=[INIT], Server=[Jetty(9.2.11.v20150529)], transfer-encoding=[chunked], 
User-Agent=[Apache CXF 3.1.2]}
Payload: { "employeeID": "bad-name", "reason": "id not found” 
}


Thanks very much for any insight,

-Steve

> On Nov 2, 2015, at 3:52 PM, Sergey Beryozkin  wrote:
> 
> 
> As I said you will need to register a JAXRS provider capable of converting 
> it, though I'm not sure right now what the syntax is with
> cxfrs:bean:webService, looks like from
> http://camel.apache.org/cxf-bean-component.html
> 
> it is something like
> cxfrs:bean:webService?providers=#jackson
> 
> Cheers, Sergey
> On 02/11/15 18:02, Steve Huston wrote:
>> Thank you very much for your quick help, Sergey!
>> I tried your solution and now get the following exception:
>> 
>> [Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR 
>> org.apache.cxf.jaxrs.utils.JAXRSUtils - No message body reader has been 
>> found for class my.class.path.CrewServiceDeniedError, ContentType: 
>> application/json
>> 
>> The code I have is:
>> 
>>InvocationTargetException exception = 
>> exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
>> InvocationTargetException.class);
>>NotFoundException orig = (NotFoundException)(exception.getCause());
>>CrewServiceDeniedError err = 
>> orig.getResponse().readEntity(CrewServiceDeniedError.class);
>> 
>> I created this class for the payload:
>> 
>> public class CrewServiceDeniedError {
>> 
>>private String employeeID;
>>private String reason;
>> 
>>public String getEmployeeID()
>>{ return employeeID; }
>>public void setEmployeeID(String id)
>>{ employeeID = id; }
>> 
>>public String getReason()
>>{ return reason; }
>>public void setReason(String r)
>>{ reason = r; }
>> }
>> 
>> -Steve
>> 
>>> On Nov 2, 2015, at 11:24 AM, Sergey Beryozkin  wrote:
>>> 
>>> Hi
>>> If you can access NotFoundException then what you can do next is to do
>>> 
>>> ErrorInfo errorInfo = exception.getResponse().readEntity(ErrorInfo.class)
>>> 
>>> where ErrorInfo is a custom class capturing a JSON error response, you'd 
>>> also need to register Jackson or other provider to get it converted. Or 
>>> read it as String.class and parse manually
>>> 
>>> HTH, Sergey
>>> On 02/11/15 16:15, Steve Huston wrote:
 I put this up on stackoverflow... if you have cxfrs expertise, could you 
 please read this?
 
 How to access payload from REST 404 response in Camel cxfrs?
 http://stackoverflow.com/q/33445686/240342?sem=2
 
 Thanks,
 -Steve
 
>>> 
>> 
> 
> 
> -- 
> Sergey Beryozkin
> 
> Talend Community Coders
> http://coders.talend.com/



Re: How to access payload from REST 404 reply in cxfrs?

2015-11-02 Thread Steve Huston
Thanks again, Sergey. I was able to register the provider using:

  

However, it looks like there is no content available via the exception. Using 
the code:

InvocationTargetException exception = 
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
InvocationTargetException.class);
NotFoundException orig = (NotFoundException)(exception.getCause());
CrewServiceDeniedError err = 
orig.getResponse().readEntity(CrewServiceDeniedError.class);
logger.error("Incoming response: ", err.getReason());
logger.error("Incoming response (plain):", 
orig.getResponse().readEntity(String.class));

I get output at runtime:

[Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR 
my.module.ExceptionProcessor - Incoming response: 
[Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR 
my.module.ExceptionProcessor - Incoming response (plain):

So I’m back to wondering where the original payload from the REST 404 response 
is. It gets logged from Camel as:

ID: 2
Response-Code: 404
Encoding: ISO-8859-1
Content-Type: application/json
Headers: {Accept=[application/json], 
breadcrumbId=[ID-Steves-MacBook-Pro-local-55129-1446506823854-1-7], 
content-type=[application/json], OriginalHeader=[{name=VerifyEmployeeRequest, 
version=1, scac=rraa, timeSent=null, uuid=abcd-1234}], pin=[1234], 
reason=[INIT], Server=[Jetty(9.2.11.v20150529)], transfer-encoding=[chunked], 
User-Agent=[Apache CXF 3.1.2]}
Payload: { "employeeID": "bad-name", "reason": "id not found” 
}


Thanks very much for any insight,

-Steve

> On Nov 2, 2015, at 3:52 PM, Sergey Beryozkin  wrote:
> 
> 
> As I said you will need to register a JAXRS provider capable of converting 
> it, though I'm not sure right now what the syntax is with
> cxfrs:bean:webService, looks like from
> http://camel.apache.org/cxf-bean-component.html
> 
> it is something like
> cxfrs:bean:webService?providers=#jackson
> 
> Cheers, Sergey
> On 02/11/15 18:02, Steve Huston wrote:
>> Thank you very much for your quick help, Sergey!
>> I tried your solution and now get the following exception:
>> 
>> [Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR 
>> org.apache.cxf.jaxrs.utils.JAXRSUtils - No message body reader has been 
>> found for class my.class.path.CrewServiceDeniedError, ContentType: 
>> application/json
>> 
>> The code I have is:
>> 
>> InvocationTargetException exception = 
>> exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
>> InvocationTargetException.class);
>> NotFoundException orig = (NotFoundException)(exception.getCause());
>> CrewServiceDeniedError err = 
>> orig.getResponse().readEntity(CrewServiceDeniedError.class);
>> 
>> I created this class for the payload:
>> 
>> public class CrewServiceDeniedError {
>> 
>> private String employeeID;
>> private String reason;
>> 
>> public String getEmployeeID()
>> { return employeeID; }
>> public void setEmployeeID(String id)
>> { employeeID = id; }
>> 
>> public String getReason()
>> { return reason; }
>> public void setReason(String r)
>> { reason = r; }
>> }
>> 
>> -Steve
>> 
>>> On Nov 2, 2015, at 11:24 AM, Sergey Beryozkin  wrote:
>>> 
>>> Hi
>>> If you can access NotFoundException then what you can do next is to do
>>> 
>>> ErrorInfo errorInfo = exception.getResponse().readEntity(ErrorInfo.class)
>>> 
>>> where ErrorInfo is a custom class capturing a JSON error response, you'd 
>>> also need to register Jackson or other provider to get it converted. Or 
>>> read it as String.class and parse manually
>>> 
>>> HTH, Sergey
>>> On 02/11/15 16:15, Steve Huston wrote:
 I put this up on stackoverflow... if you have cxfrs expertise, could you 
 please read this?
 
 How to access payload from REST 404 response in Camel cxfrs?
 http://stackoverflow.com/q/33445686/240342?sem=2
 
 Thanks,
 -Steve
 
>>> 
>> 
> 
> 
> -- 
> Sergey Beryozkin
> 
> Talend Community Coders
> http://coders.talend.com/



Re: How to access payload from REST 404 reply in cxfrs?

2015-11-02 Thread Sergey Beryozkin


As I said you will need to register a JAXRS provider capable of 
converting it, though I'm not sure right now what the syntax is with

cxfrs:bean:webService, looks like from
http://camel.apache.org/cxf-bean-component.html

it is something like
cxfrs:bean:webService?providers=#jackson

Cheers, Sergey
On 02/11/15 18:02, Steve Huston wrote:

Thank you very much for your quick help, Sergey!
I tried your solution and now get the following exception:

[Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR 
org.apache.cxf.jaxrs.utils.JAXRSUtils - No message body reader has been found 
for class my.class.path.CrewServiceDeniedError, ContentType: application/json

The code I have is:

 InvocationTargetException exception = 
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
InvocationTargetException.class);
 NotFoundException orig = (NotFoundException)(exception.getCause());
 CrewServiceDeniedError err = 
orig.getResponse().readEntity(CrewServiceDeniedError.class);

I created this class for the payload:

public class CrewServiceDeniedError {

 private String employeeID;
 private String reason;

 public String getEmployeeID()
 { return employeeID; }
 public void setEmployeeID(String id)
 { employeeID = id; }

 public String getReason()
 { return reason; }
 public void setReason(String r)
 { reason = r; }
}

-Steve


On Nov 2, 2015, at 11:24 AM, Sergey Beryozkin  wrote:

Hi
If you can access NotFoundException then what you can do next is to do

ErrorInfo errorInfo = exception.getResponse().readEntity(ErrorInfo.class)

where ErrorInfo is a custom class capturing a JSON error response, you'd also 
need to register Jackson or other provider to get it converted. Or read it as 
String.class and parse manually

HTH, Sergey
On 02/11/15 16:15, Steve Huston wrote:

I put this up on stackoverflow... if you have cxfrs expertise, could you please 
read this?

How to access payload from REST 404 response in Camel cxfrs?
http://stackoverflow.com/q/33445686/240342?sem=2

Thanks,
-Steve








--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/


Re: How to access payload from REST 404 reply in cxfrs?

2015-11-02 Thread Steve Huston
Thank you very much for your quick help, Sergey!
I tried your solution and now get the following exception:

[Camel (rraaCamelContext) thread #2 - seda://from_rraa] ERROR 
org.apache.cxf.jaxrs.utils.JAXRSUtils - No message body reader has been found 
for class my.class.path.CrewServiceDeniedError, ContentType: application/json

The code I have is:

InvocationTargetException exception = 
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
InvocationTargetException.class);
NotFoundException orig = (NotFoundException)(exception.getCause());
CrewServiceDeniedError err = 
orig.getResponse().readEntity(CrewServiceDeniedError.class);

I created this class for the payload:

public class CrewServiceDeniedError {

private String employeeID;
private String reason;

public String getEmployeeID()
{ return employeeID; }
public void setEmployeeID(String id)
{ employeeID = id; }

public String getReason()
{ return reason; }
public void setReason(String r)
{ reason = r; }
}

-Steve

> On Nov 2, 2015, at 11:24 AM, Sergey Beryozkin  wrote:
> 
> Hi
> If you can access NotFoundException then what you can do next is to do
> 
> ErrorInfo errorInfo = exception.getResponse().readEntity(ErrorInfo.class)
> 
> where ErrorInfo is a custom class capturing a JSON error response, you'd also 
> need to register Jackson or other provider to get it converted. Or read it as 
> String.class and parse manually
> 
> HTH, Sergey
> On 02/11/15 16:15, Steve Huston wrote:
>> I put this up on stackoverflow... if you have cxfrs expertise, could you 
>> please read this?
>> 
>> How to access payload from REST 404 response in Camel cxfrs?
>> http://stackoverflow.com/q/33445686/240342?sem=2
>> 
>> Thanks,
>> -Steve
>> 
> 



Re: How to access payload from REST 404 reply in cxfrs?

2015-11-02 Thread Sergey Beryozkin

Hi
If you can access NotFoundException then what you can do next is to do

ErrorInfo errorInfo = exception.getResponse().readEntity(ErrorInfo.class)

where ErrorInfo is a custom class capturing a JSON error response, you'd 
also need to register Jackson or other provider to get it converted. Or 
read it as String.class and parse manually


HTH, Sergey
On 02/11/15 16:15, Steve Huston wrote:

I put this up on stackoverflow... if you have cxfrs expertise, could you please 
read this?

How to access payload from REST 404 response in Camel cxfrs?
http://stackoverflow.com/q/33445686/240342?sem=2

Thanks,
-Steve





How to access payload from REST 404 reply in cxfrs?

2015-11-02 Thread Steve Huston
I put this up on stackoverflow... if you have cxfrs expertise, could you please 
read this?

How to access payload from REST 404 response in Camel cxfrs?
http://stackoverflow.com/q/33445686/240342?sem=2

Thanks,
-Steve