We are using jaws:client to consume a web service. We have inFaultInterceptor that captures soap faults for further processing. But this inFaultInterceptor is not being invoked for http errors like 404 or ConnectException. We configured interceptors to jaws:client. Can we write any interceptor that captures these http exceptions? Is there any better way to capture them? All we want is to take the control back when such exception/error occurrs.
Note: we cannot catch them in web service code due to some restrictions.
You can use a FaultListener added to CXF Bus. The listener will capture the http exceptions allowing you to execute your code before they are raised to invoking method.
ClientProxy.getClient(jaxWSClientProxy).getBus().getProperties().put("org.apache.cxf.logging.FaultListener",new CxfFaultListenerImpl());
public class CxfFaultListenerImpl implements FaultListener{
public boolean faultOccurred(final Exception exception,final String description,final Message message) {
//return false to avoid standard CXF logging of exception
return false;
}
}
Related
I have a gRPC server written in C++ and I would like to trace or log all RPC calls to the server, including arguments and responses, if possible.
The Go gRPC implementation has the very helpful concept of an Interceptor that can be attached to a client or a server. The interceptor gets access to not only the metadata, but also to the arguments/responses. For the C++ API I cannot find anything similar.
What about https://grpc.github.io/grpc/cpp/classgrpc_1_1experimental_1_1_interceptor.html ?
The only usage reference I could find is this SO question: C++ grpc::experimental:interceptor how to return status and message from custom interceptor
EDIT: in matter of fact, I think this is a better resource - https://github.com/grpc/grpc/blob/7bf82de9eda0aa8fecfe5edb33834f1b272be30b/test/cpp/end2end/server_interceptors_end2end_test.cc
I think you can query the request & response messages from the methods argument of the interceptor overridden method Intercept(grpc::experimental::InterceptorBatchMethods* methods), see available methods and properties here: https://grpc.github.io/grpc/cpp/classgrpc_1_1experimental_1_1_interceptor_batch_methods.html
I have developed web service using Apache CXF and now I want to deal with exception handling mechanism. Is there any way to configure it like some general listener (aspect, interceptor, whatever...) waiting for any runtime exception. and when it occurs will send my custom ResponseType message to user. This custom message is, it's clear, type from XSD scheme.
It is good to define fault for each operation you expose. Avoid throwing run time exception instead handle it in service itself.
Working with Apache Camel for EIP, I have an Apache CXF Web Service Endpoint which when called, will put requests into an MQ queue. Requests in that MQ queue are processed asynchronously where, responses are then generated and placed into a response MQ queue. The Apache CXF Web Service collects a request's response from the response MQ queue which it then writes to the Exchange's out channel for the calling client to receive.
Is it possible to configure my web service so that it can detect if a client is still connected when it is trying to send the asynchronous response back to it? And when this detect occurs, to route the response to another Camel route?
A use case scenario would be for example where the client makes a call to the web service but disconnects after 5 seconds of not receiving a response from the web service. And later, when the web service processes the request and fails to send the response to the no longer connected client, it re-routes the response to, for example, an smtp route.
* UPDATE *
Having read various online documentation and forum posts, I have my service configured as follows:
<camelContext xmlns="http://camel.apache.org/schema/spring" handleFault="true">
<routeBuilder ref="aServiceRoute" />
</camelContext>
and in my AServiceRoute route, I have configured my route as follows:
#Override
public void configure() throws Exception {
onException(Exception.class).process(new Processor() {
public void process(Exchange exchange) throws Exception {
log.debug("caught Exception A!!!");
}});
from(cxfUri)
.onException(Exception.class).process(new Processor() {
public void process(Exchange exchange) throws Exception {
log.debug("caught Exception B!!!");
}}).end()
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
// do something..
}
})
.to(ExchangePattern.InOut, mqUri);
For my first test, I force an Exception throw in the process where the // do something.. comment is. When I run this test, I see the log "caught Exception A!!!" which is great.
For my second test, I basically run the test scenario I have described in this post. When I run this test, I see a cxf stacktrace logged:
=09-05-14 12:25:32 [WARN ] org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://camel.apache.org/cxf/jaxws/provider}DefaultPayloadProviderSEIService#{http://cxf.component.camel.apache.org/}invoke has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
but none of my route's onException() methods are called.
What am I missing? Do I need to place the onException() method somewhere else in service's route?
Thanks in advance, PM.
The Dead Letter Channel will offer the behaviour you need: https://camel.apache.org/dead-letter-channel.html
I am working on an application that I want to use to catch a SOAP request when it goes into the CXFServlet. There is some processing I need to do to the SOAP envelope on the server side, before the CXFServlet processes it.
I have been presuming that the SOAP envelope, once it reaches the server side, is one of the parameters in the HTTPServletRequest object. But looking at what comes in (using a debugger, of course), I cannot find it.
Can someone tell me where the SOAP request goes when a client sends it to the server? I know that the client is sending the request using an HTTP POST, and I know that the server is using information in the request in order to access the appropriate web service method, then placing any return values from the method into a SOAP response and returning it to the client. What I need to know is where where does the CXFServlet (or one of its filters) look in order to get the SOAP information? Is it somewhere in the parameters? In the servlet context? Does a filter process the SOAP information before it gets to the CXFServlet? How can I get that envelope and do things to it before the web service method is called?
Someone please advise...
Do you want to access the original request ? If yes the actual request or response object itself can be accessed using the WebServiceContext object.
First, declare a private field for the WebServiceContext in your service implementation, and annotate it as a resource
#Resource
private WebServiceContext context;
Then, within your implementing methods, you can access the MessageContext, HttpServletRequest, and HttpServletResponse as follows:
MessageContext ctx = context.getMessageContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
For more info about WebServiceContext see the following url :
http://docs.oracle.com/javase/6/docs/api/javax/xml/ws/WebServiceContext.html
If you need to intercept the request before it is ever processed by the CXFServlet, you should look at developing a Servlet Filter.
If you just want to process the SOAP message before CXF does, you can likely use a CXF Interceptor. The phases noted in the documentation indicate the points you can intercept the message. Depending on what you want to do/change, you may need to play around with the phases.
The source for CXF's SoapHeaderInterceptor or SoapActionInInterceptor would be good places to start looking at how to work with the SOAP message.
I have a WCF service (.NET 4) hosted in IIS. My service contract has one method with:
[FaultContract(typeof(string))]
My service implementation for that method validates input parameters and may throw an exception like this:
if (string.IsNullOrWhiteSpace(siteName)) { throw new FaultException("siteName is required."); }
The consumer program of this service is a .NET 2 console application. In this app I generated the webservice proxy by right clicking "References" and "Add web reference".
When I try to call the service method from the client app, by sending an invalid siteName, I get back a 503 Service Unavailable exception, instead of a FaultException with the custom error message.
How can I make the FaultException, with the custom error message, propagate to the client program?
UPDATE:
The exception I get in the client application is this:
System.ServiceModel.ServerTooBusyException:
The HTTP service located at
http://www.example.com/services/myservice.svc
is too busy. ---> System.Net.Web
Exception: The remote server returned
an error: (503) Server Unavailable.
at
System.Net.HttpWebRequest.GetResponse()
at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.WaitForReply(TimeSpan
timeout) --- End of inner exception
stack trace ---
The problem was being caused by a custom HTTP module in our web project. So it was not exactly a WCF problem, but a problem specific to our solution. Thanks!