Microserivce Using Spring Boot to Consume SOAP - java

I need to create a REST service that first consumes SOAP. What would the best way to go about this?
I would like to use Spring Boot to create a microservice, but I have a few questions for those with experience:
What other architectures or technologies should I look into using
(with spring boot)?
Is there a standard technology stack for this?
Are there pitfalls I should be aware of?

What other architectures or technologies should I look into using (with spring boot)?
My answer is if you just want to simply provide RESTful service
without Spring Cloud, then I think you can refer to following 2
tutorials on Spring official website to achieve this:
Building a RESTful Web Service
Consuming a SOAP web service
Is there a standard technology stack for this?
Currently, I will suggest you to use Spring Boot as your first choice. Because these are rich resources on the web and it does reduces much effort in development.
Are there pitfalls I should be aware of?
If you finally choose Spring Boot, please be familiar to its components, you can start from Guides to realize how it works. Or you may mix up Spring Boot with tradition Spring framework.

There are similar cases in our project and we did it with spring components. As far as i understood, you want to open a REST endpoint which most probably accepts json object and you want to make a soap web service request within that request then you want to return a response containing information from the soap response. To make a soap request, you can use spring web services - WebServiceTemplate. It will marshall your object to xml and make soap request for you. Of course you can use some other web service frameworks like apache cxf which may best fit for some special cases, but i would first try to use a framework which is from spring family while using Spring. You should set timeout values on webservicetemplate object to not wait too long if the external system is not working well or you have some problems with the network. Because it directly affects your systems performance. Also here, i suggest you to implement circuit breaker pattern to make your system more robust. You should always isolate your systems performance from other systems that you integrate and in this scenario you can do this by doing the things explained above.

As per my knowledge , you should use Spring boot application with Maven build.
In order to send a REST call to SOAP web service and get back a JSON Response ,you need to follow all of this steps in order :
Business Logic : Mapping the JSON fields such as headers, query-param , body variables to XML Request mandatory fields (either using pojo classes or object-mapper) Reason : Since the SOAP end point will only accept XML Request.
Service Broker Logic : Import "org.springframework.web.client.RestTemplate" and use
**ResponseEntity<String> responseEntity=RestTemplate.exchange(endPointURL, HttpMethod.GET/POST/PUT/DELETE, HttpEntity/headers, uriVariables)**
**endpointURL** -- SOAP End point URL ,that the REST service has to consume.
**HTTPMethod** -- Method Type such as GET ,PUT ,POST ,DELETE etc.
**HTTPEntity** -- Soap requires for mandatory sender/headers/{a}.Make sure that you set your header name and value as key-Valye pair in HTTP headers.
**uriVariables** -- (Object... urivariables) such as String.class ,Integer.class
You should also put the **connectTimeout** ,**isSSLDisabled**,**responseCached** elements while generating request to restTemplate.
responseEntity.getBody() is the XML response after un-marshalling.It can be extracted by using mapper.
XML_BaseResponse response=mapper.readValue(responseEntity.getBody(), XML_BaseResponse.class);
Business Logic : Extract necessary field from XML_BaseResponse and using setter's or getter's functions,set the mandatory fields in the response.
baseResponse.setName(xml_baseResponse.getPersonsName());
baseResponse.setAddress(xml_baseResponse.getAddress());
baseResponse.setCity(xml_baseResponse.getcityName());

Related

Which is best/performance putting wrapper top of SOAP service or creating new REST full service?

All services are running in SOAP. for now they client asking us to provide a REST service.
I have two options
Write a wrapper for existing SOAP services to provide REST full services
Brand new REST full service.
Which is better (in performance perspective)?
A single service usually has better performance than a service and a proxy (wrapper).
However SOAP and REST (with JSON) services are approximately equal in performance, you'll come to see that in parsing/serializing XML and JSON to objects representations (with jackson or JAXB), the object creation is the most demanding part, not reading JSON or XML format. The overall impact on performance is probably lower than 5 percent - a single core can usually top 50 mb/s in parse/serialize capacity.
The above also implies that if you already have a very optimized SOAP backend, probably going with the proxy is the right choice.
Moving from SOAP to REST you should use a tool like swagger (OpenAPI) to define the service in as much detail as the SOAP service. Note that REST services also can use XML, but probably that is not what your client is expecting.
Definitely Writing a new Rest web service would be the better choice because
Rest is light weight due to statelesness(due to HTTP protocol).No state is maintained.hence keep ur resources free.
You don't require a schema as you need for soap webservice.Thus serializing and deserializing is also not required.Thus makes performance far better
Testing a rest service would be easy for you.
Even rest is supported to develop an App on the based of REST API you have developed if u require in future.
Rest supports multiple data excahnge formats for ex : json,text etc.
Rest can be easily integrated with high-end frameworks like Spring etc.
You may use better documentation for your service via Swagger for Rest to keep knowledge about your service for business understanding.

Trace transactions end to end over distributed applications systems

Is there a way to trace transactions end to end over distributed applications system using Spring AOP or AspectJ, without changing the existing codes? The web service interactions between applications may be RMI, SOAP or REST? I am looking for a general approach and just want to know if it possible using Spring AOP and AspectJ.
Yes, it is possible with AspectJ, but there is no easy "cooking recipe" or "template for dummies". You need a custom solution. In order to concretely answer your question I would have to see your code. Another guy from India lately asked me the same, maybe he works on the same project as you.
The general approach is to transfer state between client and server by injecting a unique parameter (something like a transaction ID) into the request and using it on the server. Both client and server should be aspect-enabled. This should be possible via RMI, SOAP and REST, provided you find a place where to inject an additional parameter. In RMI and SOAP this could be an existing general-purpose key-value dictionary for optional parameters, in REST it could be a header field or a request parameter.

Service details in case of Java REST web services

I am new to web services in Java.
In SOAP web services, we have wsdl that tells us about the services like the operations etc. but in REST, we don't get wsdl.
So, my question is if someone wants to know the service details, then how that can be found in case of REST web services.
SOAP introduced WSDL to describe services, which can automatically be discovered and integrated with a mechanisms like UDDI. In reality SOAP is used just as hardcoded RPCs. If you use REST, many details like exceptionhandling, operation types, idempotency are handled using well known HTTP mechanisms. The only thing you need to know is the payload encoding. If you use XML, you may use XSDs to describe the services, if you use JSON you need to handle this on your own (its a lot simpler). The structure of your URLs should be designed so its intuitive enough, to be described in a one paged readme file.
To cut a long answer short: WebServices were so complicated you need a lot of boilerplating, REST services should be so simple, that a developr does not have to redefine and redocument the basics.
With REST there is no single established way to achieve this yet, however there are couple of options emerging:
Swagger http://swagger.wordnik.com/ - Inspects annotations in your source code (supports web frameworks JAX-RS annotations, Spring annotatins, Play2) and generates a JSON document describing your APIs. This JSON document can be displayed as an interactive web page as end user documentation using swagger-ui.
Json Home https://datatracker.ietf.org/doc/html/draft-nottingham-json-home-02 - Specification for a JSON document that describes your RESTful APIs
WADL http://en.wikipedia.org/wiki/Web_Application_Description_Language

Best way for handle Read HTTPRequst post data on Restful api

What is the best way of save data using Restful web service without using Ajax? As a example I need to add a new Customer to the database using submit button.
What is the best way of transfer data format (text,json,xml) ?
How to read POST or GET data from HttpRequest object?
If you can please give me a example in java .
Thank you
I think you need to separate the concepts a bit. A "Restful Web Service" is a web service designed using REST principals, whereas AJAX is a set of technologies used often on the client side for asynchronous requests to multiple resources (without fully reloading the page). The web service really shouldn't care how the HTTP request is generated, just the contents of the HTTP request.
Now if you're concerned about writing a rest service in Java, I would highly recommend looking into JAX-RS and the reference implementation Jersey. There are lots of examples of how to get up and running. You can use MessageBodyReader implementations are to convert data from the HTTP request entity into Java objects.
Obviously this is not the only way to get started with writing a Restful web service in Java, but is one way.
It's very definitely worth your time to carefully study Richardson and Ruby's RESTful Web Services to learn the REST architectural style. In addition to #ach_l's recommendation to use Jersey, take a look at the Restlet Java framework, which is completely wonderful.

Implementation of web service

I just want to implement a service in java that will:
take some arguments, then search the database
return the JSON object of the fetched data
I need help to identify the ways through which I can implement this thing.
e.g. Suppose I am getting the name of the book as argument I want to render.
On service part, I have to fetch book data and convert it to JSON and write/return to response.
I was looking at the Apache Axis2 but I am not sure that I am going in the right direction.
So, pls help.
Need guidelines not implementation.
Thanks
I would suggest using JAX-RS based services which would be ideal for your scenario as you want json data. These are pretty easy to get started with. Jersey is a widely used frameworks. Also see RESTEasy.
If you are returning the data in JSON then you probably don't need to implement a full web service, which uses XML for both the request and the response.
A normal dynamic web application (written as a Java Servlet) will be able to read request parameters in the HTTP payload and return a JSON-encoded HTTP response.
However you need to consider your clients; if they are only able to access web services then you need to forget about a JSON response and simply objectify the response. However if the clients can access web resources without issue then go with the servlet approach.
If you need to go with web services then look at the Metro 2 framework.
One way to do this is to keep it standards-based.
If you are using the JEE5/6 framework, your best bet would be to go with JAX-WS - comes built-in with the JSE too (if I remember correctly)
You really just have to annotate a POJO with #WebService to achieve this.
Regarding creating a JSON response, a good bet is to stick with the implementation from http://code.google.com/p/google-gson/ ; simple and straightforward
Axis2 can handle/support the webservice related part, iaw, transforming java objects into JSON and vice-versa and providing an easy-to-use API for the communication part.
Hibernate or JPA could be useful for database related tasks, although it might be easier to just use JDBC to send some simple SQL commands to the database (especially if the database already existst).

Categories