Is a servlet inside a portlet required to make the portlet as a web service? - web-services

I have few questions with respect to portlets and servlets. This may be a continuation of
my previous question.
I m trying to create a portlet which should act also as a web service. I dont know Why,
but the client requires it this way. I negotiated with the client that I can make a
separate web service application using simple jersey servlet... but cannot convince.
I have the following doubts:
A portlet by itself cannot represent independently to the outside world. If that is
the case then what is the benefit in making a portlet as a webservice than not making a
complete webservice project with just servlets?
By web searches, I came across few code sample which can make a portlet as a
webservice. These sample codes suggested me to create a portlet, in the web.xml include the jersey-servlet and servlet container to make the portlet as a web service. Though it might work(I m trying hard to make a working codebase) but why to include a servlet container inside the portlet container which is already residing inside a servlet container. Sounds confusing? The following image can convey by doubt:
In this the liferay is a the servlet which is visible to the browser first. This has
multiple portlets in it. If I am making a portlet as a web service then I have to make it
visible to the browser, so I m including a servlet inside the portlet(Its my assumption
according to the sample code from web). This is like taking a round trip to touch my nose.
I really dont understand why this architecture is like that. The following points which I
guess is sensible for making a portlet as web service are:
(i) If I make a servlet(a separate project) for web service then (working as a liferay developer in the team) we cannot claim this as a liferay project.
(ii) If the web service is a portlet then I can have inter-portlet communication. In case of servlet it cannot(if I m not wrong).
Please suggest.

I think this can drive you to what you need. A portlet can be called in a EXCLUSIVE mode, where no portal or portlet content are generate in the response. So you can produce whatever "HTML" or data you need as a response.
Im researching and starting with Restful, but it seams like a request/response HTML communication. The main difference is the annotation that map an HTML to a Class and methods in standard modes. In liferay you can assign an URL to your portlet. It can produce a behaviour like the one in Restful.

Related

Does the existence of a .wsdl file mean files must be generated?

When I'm tasked with dealing with connecting to web services, I've always found the appropriate .wsdl file, ran WSDL2Java.bat, and incorporated those Java files into my Java project. Then I've successfully completed my project that needs to access data via web services.
My question is, are there other ways to use the .wsdl file to access web services? ( I'm not talking about creating classes for different languages ). For example, I have documentation describing one company's web services. The examples it shows in it's documentation are essentially dumps of HTTP Post requests. Is this "web services"? It looks to me that the .wsdl file is merely used as a reference to make the correct Post requests. I could just make text templates and plug in the right values, and send them out, right? I really feel like I'm missing something here.
Am I a web-services illiterati?
To call a SOAP web service over HTTP you just need to send it a properly formatted XML with a POST request. That's it! How you build the request is irrelevant as long as it conforms to the SOAP protocol and the payload corresponds to a proper web service operation that exists on the particular web service you are calling.
But how do you know how to build the proper payload?
The web service needs to have some sort of documentation otherwise you don't know what to put inside the XML. The documentation can be whatever you like as long as people can use it to build valid requests. WSDL fits this criteria but has an extra advantage: you can feed it to a tool that generates code. That code knows how to handle all the SOAP details and exposes objects and methods to your application.
What would you prefer? Generating code from the WSDL in a few minutes and be able to call whatever operation on the web service or, build the requests and parse the responses by hand and spend hours or days doing so. What would your boss or company prefer? :)
It looks to me that the .wsdl file is merely used as a reference to make the correct Post requests. I could just make text templates and plug in the right values, and send them out, right?
Right! But you also have to consider your productivity as an employee in one case as opposed to the other.

Invoking servlet from Java GUI application?

I know that similar questions have been asked before, but I would like to know if you can actually call a Servlet to do some work made on an EJB module, and then return the data to the standalone Java GUI application.
The requirement of the project says that both a standalone Java GUI client application, and a web client application should access a Servet to do their work, that is update and retrieve data from a database.
Does it make sense to use servlet for the GUI client to access the EJB, or why not access the EJB directly from the stand alone GUI application without invoking the Servlet at all.
Yes, you could call a servlet which in turn calls an EJB.
But you can call an EJB directly from a stand-alone application as well. If your servlet returns HTML markup (content type "text/html" - for human beings), you will have to parse it (requires effort) to get the same result. Every time the markup changes, your client has to be changed as well.
Even if there is a firewall in between (= direct RMI is not possible), you can use "RMI over http(s)", and there is a HTTP based naming service as well (JBoss offers this functionality).
On the other hand, if you mean a servlet which implements a web service which returns XML or JSON, it's a valid approach, especially if clients from other languages (C++ for example) are involved. Another advantage is that you can read the result using a browser (no need for a special RMI client). In that case have a look at available tutorials to implement a webservice in Java

SOAP Web Service basics

am new on WS.
some simple questions in my mind, please try to solve it.
i did a demo WS for Calculator on calculator(), where it has one UI where i enter values for it, internally pass it to WS. Ok i got answer/output. but if i want to create only webservice which take/give xml data or just give xml data. how can i create it.
i found some WS URL's about some fame company. is it used by using by opening Connection. how they define this URL? am using MyEclipse10 when i went to create new WS, needed to use Java Bean class for create it. ok, if i create myWS url then how it ll get call? because it is JavaBean?
and if just want to create WS then i need not required to create New WS client?
i dont know it is simple or may be foolish question, when i walk on WS i stop here. i feel like , without basic knowledge started to build it.
please, clear it.
Thanx.
MyEclipse (as well as Eclipse, IBM D Developer, etc) let you create a Java Web service server in one of two ways:
Bottom up Java Bean: you supply a bean, it turns it into a WSDL (and generates the corresponding stub code)
Top down WSDL: you supply a WSDL, and it generates the corresponding stub code
When a company creates a web page, they set up a web server and publish some HTML pages on it.
When a company publishes a WSDL, they also set up a web server ... and publish an XML WSDL on it.
The URL you go to in order to read a WSDL is just an ordinary HTTP web server, that happens to be serving an XML WSDL at that location.
The WSDL specifies where the service can be found, and what operations and data types the service uses. A WSDL you create, or a WSDL that's published by some other company.
'Hope that helps

Restful service in .NET with WADL instead of WSDL

I used WCF to create a restful web service in .NET, by means of a .svc file. The web application automatically produces a WSDL file. AFAIK, the WADL is more natural for a restful web service.
How could I create a restful service in .NET (preferably with wcf) that produces a WADL description?
Note An answer like "RTFM" is accepted, as long as you indicate a suitable manual/tutorial.
This is an old question but having consumed restful services with WADLs they do offer some value. You can import them straight into SOAPUI and it will build a test suite for you automatically. Secondly they tend to contains all the required XSDs for XML based services and are useful for automatically building serialisable classes that your endpoints accept and receive.
Looks like REST Describe & Compile should do the trick.
On the WADL developer site Marc Hadley
maintains a command line tool named
WADL2Java. The ambitious goal of REST
Describe & Compile is to provide sort
of WADL2Anything. So what REST
Describe & Compile does is that it:
Generates new WADL files in a completely interactive way.
Lets you upload and edit existing WADL files.
Allows you to compile WADL files to source code in various programming
languages.
Forgive me for answering a question with a question, but do you really want to do REST? REST really has no need for things like WADL.
Update:
The "hypermedia constraint" (aka HATEOAS) dictates that the user agent discovers content based on links embedded in previously retrieved content. It really is unnecessary to have a separate document that describes all the available content.
Imagine using a web browser to go to a site and instead of going to the home page and navigating from there, you are presented with a page which is a list of all the URLs on the site. You must then looks through the list of available urls, choose the one you are interested in and copy it into the address bar.
WADL is effectively you list of site urls. You just don't need it if your main content is linked together.
Linking content instead of using a WADL "site map" has other advantages. The available links can be dynamic based on particular data values in the content. This capability can vastly reduce the complexity of clients, because the client no longer needs to host the logic to decide when it is allowed to follow a link.

How to create a web service load test using Visual Studio 2010?

Is there a way to test a Web Service using VS2010 like it's used to test a web site?
For a web site I can create a set of WebTestRequest objects that emulate the loading and the parsing of a web page from the test and then, implementing the GetRequestEnumerator I can yield results to the load test so that the execution time and payload of any single page could be evaluated by the test runner and published in my test run reports.
I would like to do the same for a test using web service call so that each time I call the web service (there is some logic in calling it, like logging in, getting a security token and pass a proper formatted XML document to the web service method) I can yield the result to my test runner and evaluate it.
Is there a way to do it or do I need to implement a specific class inheriting from the WebTestItem abstract class?
Regards
Massimo
Yes, it is possible to test Web Services using Web Performance Tests in Visual Studio 2010 Ultimate.
Here's a couple of useful links:
How to: Create a Web Service test (MSDN)
How to: Web Service Load Testing Using VSTS 2010 (Blog)
As a starting point, you can use a web proxy tool like Fiddler to intercept the HTTP requests made to the Web Services, copy the contents of the SOAP envelopes in the Web Performance Tests and then tweak them accordingly based on the test scenario you want to simulate.
This doesn't quite answer your question as it's a 3rd party tool, but SOAP UI is a great piece of (free) software for load testing web services, whether your own or someone else's. You can run individual requests, or do a bunch of different load tests.
We've used it for one service that uses credentials, so I'm sure it will work fine for your scenario.