What is the best way to confirm that these consumed services are actually up and running before I actually try to invoke its operation contracts? I want to do this so that I can gracefully display some message to the customer to give him/her a more pleasant user experience. Thanks.
I created an IsAvailable method that checked all of my underlying dependencies for my service. My client would call this method before doing anything else with my service. If it returned true, my service was available for use.
We also put intermediaten checks to rollback any changes if one of the underlying dependencies was not able at the time of the transaction.
Example:
Here is a simple example of how my IsAvailable is used by the client:
IsAvailable code
[WebMethod]
public bool IsAvailable()
{
bool EverythingUpAndRunning = true;
try
{
string TestConnectionString = WebConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(TestConnectionString);
sqlConnection.Open();
sqlConnection.Close();
sqlConnection.Dispose();
}
catch(Exception ex)
{
EverythingUpAndRunning = false;
}
return EverythingUpAndRunning;
}
The client code:
MyWebService proxy = new MyWebService();
if(proxy.IsAvailable)
{
//if true, you can use the other available methods in the service
}
I wouldn't consider myself a part of the SO Community but I have been in this situation before and it was simple exception handling around the service calls. If you're in control of the services, than you can put up a status method that returns it's current state. If the network is down and you can't even hit the service than you'll have to handle that with some exception handling but you could get a status back if the parent service is unable to use it's child services.
If you're following SO though, my own opinion here, you shouldn't be concerned with the consumed service consuming other services.
Related
We want to have the fail back mechanism in case of any failure to publish event to Pub/Sub. I am using "ListenableFutureCallback" to know message published successfully or not. In case of failure, it is just throwing exception and I need event details to post it to internal messaging service. How do I get event details in onFailure() method.
I am using Spring Integration.
Below is piece of code.
Listener:
#Component
public class PubSubOperationListener implements ListenableFutureCallback<String> {
private static Logger LOGGER = LoggerFactory.getLogger(PubSubOperationListener.class);
#Override
public void onFailure(Throwable throwable) {
LOGGER.error("Failed to publish the message and details : {}",throwable);
// Logic to process it using different approach.
}
#Override
public void onSuccess(String s) {
LOGGER.info("Message published successfully.");
}
ServiceActivator:
PubSubMessageHandler pubSubMessageHandler = new PubSubMessageHandler(pubSubTemplate, testTopic);
pubSubMessageHandler.setPublishCallback(pubSubOperationListener);
return pubSubMessageHandler;
Please suggest if there is different approach to do same.
Currently, it's not possible because Spring Cloud GCP simply delegates to the Pub/Sub Publisher in the client library.
However, when we wrap the Future provided by the Publisher in Spring Cloud GCP, we can potentially include the original message there and other metadata. This would be a feature request that should be filed here.
Our application integration flow is defined as splitter -> ws gateway -> aggregator
The splitter splits request into a list of account numbers; so that for each account number a web service call is initiated and the responses from multiple web service calls are aggregated in the aggregator.The channel between splitter and ws gateway is defined with dispatcher "commonj WorkManagerTaskExecutor" so that each webservice call is initiated parallelly in different threads.
If at least some of the web service call responds properly; even if all other calls result in SoapFault; we need to handle the scenario by using the data from the successful responses with a warning message quoting the error message from the fault response.
The issue is that resolveFault() method of FaultMessageResolver defined in the ws gateway does not return anything and the control never reaches the aggregator if at least one of the parallel web service call fails. Is there any way to handle such a scenario.
You can inject SoapFaultMessageResolver to the <int-ws:outbound-gateway> (fault-message-resolver). This one has pretty simple code:
public void resolveFault(WebServiceMessage message) throws IOException {
SoapMessage soapMessage = (SoapMessage) message;
throw new SoapFaultClientException(soapMessage);
}
So, you failed WS invocation will end up with an Exception.
Add <int-ws:request-handler-advice-chain> to your <int-ws:outbound-gateway> and place there an instance of ExpressionEvaluatingRequestHandlerAdvice. specify its errorChannel and do some agnostic logic in that sub-flow and send some specific message to your aggregator. Don't forget to carry sequenceDetails headers with that messages.
Having all messages in group aggregator will be able to release is as normal one.
In the end you can analyze result List for errors and normal responses.
I have a Jax-WS service that needs to call out to another JAX-WS service with a CXF client. Because this client requires additional WS-* features, such as WS-Trust, I create a new CXF bus.
private void startupBus()
{
// if the bus is already active, shut it down to pick up any endpoint changes
if (bus != null) {
bus.shutdown(false);
}
bus = BusFactory.newInstance().createBus();
// Add logging interceptors to log messages to and from the services it calls
...
inBusLog.setPrettyLogging(true);
outBusLog.setPrettyLogging(true);
bus.getInInterceptors().add(inBusLog);
bus.getOutInterceptors().add(outBusLog);
bus.getInFaultInterceptors().add(inBusLog);
bus.getOutFaultInterceptors().add(outBusLog);
BusFactory.setThreadDefaultBus(bus);
...//create service proxy with this bus, setup STS client parameters, etc
}
Both my bus and my service proxy are static instances, and because I want to modify my parameters externally, this method re-runs once per day.
I'm seeing a memory leak, however, when this service stays up and running for a few days. Its relatively slow, so I cannot pinpoint if its something to do with my bus/proxy rotation logic, or if its elsewhere.
Is there any additional cleanup that needs to be done on the proxy( such as a java.io.Closable.close? ) or am I incorrectly configuring/managing my CXF bus instance?
Maybe it will be useful for the future
https://docs.jboss.org/author/display/JBWS/Apache+CXF+integration#ApacheCXFintegration-BusselectionstrategiesforJAXWSclients
try {
Service service = Service.create(wsdlURL, serviceQName);
MyEndpoint port = service.getPort(MyEndpoint.class);
//...
} finally {
BusFactory.setThreadDefaultBus(null);
// OR (if you don't need the bus and the client anymore)
Bus bus = BusFactory.getThreadDefaultBus(false);
bus.shutdown(true);
}
I'm creating my client/server application intercommunication with ServiceStack, and is working great, but I need also to access an external SOAP web service.
I tried to use the Soap12ServiceClient to access it, but I couldn't find any example, and then I went the add service reference WCF way that actually worked, but creating a ton of code.
Is it possible to use Soap12ServiceClient in the same easy way I use JsonServiceClient to send a message/request and receive the message/response? If so, can you help or point me to a sample?
I'm not sure where you're stuck as all of ServiceStack's C# Service Clients implement the same IServiceClient so they can be used in the same way. Here is an example of all of ServiceStack's built-in C# Service Clients calling the same Hello World service:
[TestFixture]
public class HelloWorldServiceClientTests
{
public static IEnumerable ServiceClients
{
get
{
return new IServiceClient[] {
new JsonServiceClient(Config.ServiceStackBaseUri),
new JsvServiceClient(Config.ServiceStackBaseUri),
new XmlServiceClient(Config.ServiceStackBaseUri),
new Soap11ServiceClient(Config.ServiceStackBaseUri),
new Soap12ServiceClient(Config.ServiceStackBaseUri)
};
}
}
[Test, TestCaseSource("ServiceClients")]
public void HelloWorld_with_Sync_ServiceClients(IServiceClient client)
{
var response = client.Send<HelloResponse>(new Hello { Name = "World!" });
Assert.That(response.Result, Is.EqualTo("Hello, World!"));
}
}
Although SOAP works similar to any other C# client, it's un-common to use it in this way because if you're able to use a generic C# SOAP service client you're also likely able to use any of the other service clients which are all faster, more resilient and more versionable than SOAP - which has effectively has no redeeming quality over the other formats other than its ability to generate client proxies which you said you don't want to do anyway.
If you're undecided which endpoint or format you should use I recommend reading my Interview on InfoQ which discusses the disadvantages of SOAP and the benefits of using the other formats.
I am implementing a Spring MessageListener that is listening to a JMS Queue to process messages containing XML.
My bean ProposalSOAListener will be processing about 5 or more XML messages from the queue. My code is below.
Is there a way to specify different methods on this class to handle different XML messages?
public class ProposalSOAListener implements MessageListener {
public void onMessage(Message message) {
if (message instanceof TextMessage) {
try {
System.out.println(((TextMessage) message).getText());
} catch (JMSException ex) {
throw new RuntimeException(ex);
}
}
else {
throw new IllegalArgumentException("Message must be of type TextMessage");
}
}
} // end of ProposalSOAListener class
There's a bunch of architectural questions begged by your question. Do you want this mesasge listener to do the work, or hand it off to another component? Are there transactional considerations at play? Do you have memory constraints - i.e. do you want streaming based XML processing or not? Do
The good news is that you have a lot of the pieces to this puzzle available to you within Spring.
A simple next step would be to use Spring Object XML Marshalling (OXM), choose one of the techniques, and wire the marshaller into your listener bean.
See http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/oxm.html
Another technique would be to use the Spring ApplicationEvent interface, read the messages coming in off the queue and publish them internally to listeners of the specific types. That could be used in combination with the above object marshalling.
Last but not least, if this is SOAP web services - you can take a look at Spring WS, it uses the similar message containers to pull messages off the wire, marshall them, and invoke a spring ws endpoint (ie. the service interface that satisfies that interface contract).
http://static.springsource.org/spring-ws/sites/2.0/reference/html/server.html#d4e907
Spring Integration project is highly recommended for this kind of a problem. Essentially you will have to implement a jms inbound gateway to get your message in. You can then transform this to an object at this point, then route the message to the appropriate service-activator component, which can map to your instance and method.