Am new to web services. I have a spring bean in which i have used Transactional annotation for DB operations.
Now I need to expose one of the method in the bean as a service.
The method parameters are Hashmap and a POJO (like JPA entity) object. return type is HashMap.
What is the best way to implement it.
Directly exposing the bean using Axis2.
Using Spring-Ws with CXF.
Writing a new method in a new wrapper class which accepts Strings as parameters.
(These string are actually as required by the original Map and POJO ).
And by setting these strings as properties and objects in POJO and Map respectively, as required by original method.
The Third method wont work in my case as the Map will contains several arraylists which needs to be stored in DB.So I have to use Map only.
Shall I go with SOAP or RESt.
Already two web services were provided using Axis2 in our project by old team.
We are using spring 3 (as core container and for ORM), Hibernate template, Tomcat 6.
Well, that question is best answered by yourself. We can only give hints here which framework and technology might work out best for you. In order to give any hint, we'd need some more information about your project.
SOAP and REST, for example, are two essentially different technologies. The SOAP protocol must use XML as information medium and can use literally any transport medium, e.g. HTTP, E-Mail, JMS, etc. Using SOAP, the contract, which is the WSDL specification, between a service endpoint and a client is the interface description. The REST protocol can use any information medium, e.g. JSON, XML, YAML, etc., but is limited to the HTTP protocol as transport medium. Here, the HTTP methods like DELETE, GET, POST are the interface description.
You said, you're actually using AXIS2. If your experiences with that framework are good enough, I would recommend to use it further. CXF is simply another Web Service Framework which cannot be used together with Spring-WS (but it can be used with the Spring Framework). Here, I would consider that each framework has its caveats and needs some time to learn.
Related
I am currently looking at redeveloping a web service that is currently written in .Net. I would like to port it across to Java using a CXF, Spring, Hibernate and Maven stack.
The WSDL for the service is already available and is well formed so I would like to reuse rather than redeveloping the interface. This will also mean that the clients will not require significant changes in order to use the new service.
I would like to use a JAX-WS type approach to developing the web service, similar to the Java-first approach at http://cxf.apache.org/docs/writing-a-service-with-spring.html. The only difference being that I would like to follow a contract-first approach and ensure that the exact WSDL is used.
Has anyone attempted this before? Are there any good guides online that I can refer to?
I am actually not seeing in your question what is stopping you from developing it with WSDL first approach.
Check my answer here, for the tutorials you need.
I guess its pretty straight forward (The WS stack part)
1.Create the Implementation stubs using WSDL (contract)
2.Create Client using WSDL
* implement methods using your own logic and syntax
both 1&2 is supported by CXF.
good guides here
and here
I understand that you can describe your REST webservice while using WSDL.
Is this a good idea if you don't use WCF? Is there a better way to allow service discovery and bind your request/response to certain types?
If you use json you can use SMD and JSON-Schema but what if you use XML or YAML?
EDIT:
I have found this specification for WADL.
How widely used is it?
The Http Accept header and Content Type headers are there to allow a client to dynamically request and respond to different types. Statically describing what those types are in some kind of description file like WSDL would be unnecessarily limiting.
The use of hyperlinks within the returned representations allows for incremental service discovery. This allows the service discovery to be dynamic based on a whole range of factors.
The use of a global static service discovery document like WSDL or WADL is really not the optimum solution with a REST service.
I am a noob to web services world. I need to develop a login validator module and expose it as a service. I want it to be service independent, i.e I should have the option of exposing it as a SOAP service or REST service in the future.
What pattern should I follow ? Sorry if I am unclear in my requirements, I can clarify as per need.
Thanks !!
Edit : I am using Eclipse as an IDE and Jersey libraries. I am not into any framework, simply using the MVC pattern. I find a lot of difference between SOAP ann REST methods, so I want my methods to be implementation independent - i.e I should be easily able to use my method through a SOAP or REST service call as per need. What should I do for maximum flexibility ?
Picking a good MVC framework and understanding how to use it properly can help ensure that your feature is "service independent". Most of the documentation I've read for good frameworks suggest that you keep your business logic separate from your controller.
If you read the documentation for the tools that you use, and ensure that there is a layer between your business logic and your controllers, then that will make the job of switching from SOAP to REST or some other protocol much, much easier.
Since you mentioned you're using Eclipse in your comment below, I'm assuming you are using or are willing to use Java:
Restlets
http://www.restlet.org/
Spring 3.0 REST
http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/
Develop your service as a POJO. Make sure to respect staless pattern.
Create an EndPoint class for each publication type you require (Soap, Rest, EJB, JMS, what ever)
Use appropriate standard to expose your EndPoint. For Soap and Rest the JAX-WS api and implementations can do it for you using java annotations on your EndPoint.
That's it !
I published an orchestration in Biztalk as a webservice. Does anyone know how I can use XML serialization or something to load XML from a file and "convert" it to the messagetype the webservice expects? How do people usually use this webservices? I try to avoid using untyped messages since I use both XML and flatfile, and have read that it could mean trouble.
Well, I guess generally the idea of web services is that you add a web reference to them, which would generate a set of proxy classes you could use to interact with the web service.
You don't normally have to worry about serialising xml files to and from the web service formats, the generated code will do it for you.
If you do wish to, however, to work of XML, you could use .net serialisation to deserialise an xml file into the generated proxy type (as well as serialise any response you're getting).
Here's a basic example of how to deserialise xml into a class instance, you can then pass this instance into the method in the generated proxy.
System.Xml.Serialization.XmlSerializer xser = new System.Xml.Serialization.XmlSerializer(typeof(<generated request type here>));
xser.UnknownAttribute += new System.Xml.Serialization.XmlAttributeEventHandler(xser_UnknownAttribute);
xser.UnknownElement += new System.Xml.Serialization.XmlElementEventHandler(xser_UnknownElement);
xser.UnknownNode += new System.Xml.Serialization.XmlNodeEventHandler(xser_UnknownNode);
xser.UnreferencedObject += new System.Xml.Serialization.UnreferencedObjectEventHandler(xser_UnreferencedObject);
<generated request type here> request = (<generated request type here>)xser.Deserialize(<xml stream here>);
I hope that makes sense
You question is bit confusing. You started off with saying you published an orchestration as web service, but raised the question about consuming it.
If you are talking about published web service:
The web service generated by BizTalk Web service Wizard is not different from a web service you would have written in .NET. Based on the message type you orchestration is expecting and how your structured the operation in the wizard. The Wizard would have auto generated a webservice for you with WSDL and schemas (there will be some BizTalk specific bits inside, but you don't need to worry about the implementation).
You consumers (independant of platform) should be able to consume that web service without any major issues.
If you are trying to consume a web service from Orchestration
Have a look at this paper http://msdn.microsoft.com/en-us/library/ms935219(BTS.10).aspx
I have build plenty of SOAP webservices, but am building a REST webservice for a specific project, and I was wondering what people used for a 'WSDL' for REST services or if it is even needed.
You can try Swagger(now OpenAPI) which allows to describe REST services using a JSON open standard.
REST really only uses the HTTP verbs (GET,PUT,POST,DELETE) on a resource. All operations on a resource are supposed to be represented that way. POST is used as a catch all for when you can't express your business logic in a way that fits into the other three. That is why there isn't really a WSDL for a REST service since you only ever have 4 methods on the resource. Note that the Zend Framework REST library isn't really RESTful and is more of a plain old XML (POX) service.
While Sam's correct that RESTful web applications don't need a direct analog to WSDL, there is an XML vocabulary that's useful for describing RESTful web apps: WADL, or Web Application Description Language. At my company we primarily use WADL to define a spec for a given service that we want to build - we don't generally use it programmatically. That said, the WADL home page includes some Java tools for code generation, and Restlet, the Java REST framework, includes a WADL extension for dynamically wiring applications based on WADL and dynamically generating WADL based on a wired application. I'm a fan of WADL, and recommend that you check it out.
Actually it's possible to use WSDL for that but it should be v 2.0 - see "Describe REST Web services with WSDL 2.0" article.
You can supply an XSD if you are using XML in your REST service.
Or just examples of the XML, should be enough to work things out for simple data structures anyway.