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
Related
This is with respect to a JAXWS webservice. In a library (jar), besides many other classes, I have all the classes generated by wsimport, and the implementation class.
Two separate (EAR) applications depend on this library for different reasons.
In one application, I would like the webservice to be not started (not available), in the other application I would like the webservice to be up and running.
I did not write any Java code explicitly to start the webservice. I think, since the implementation class has #WebService annotation, and so, the environment automatically makes the webservice available.
If instead there is a way to manually start (publish) the webservice, and not use the automatic means, then we can do the manual publishing/starting in one of the application where it is desired.
Any ideas?
In my mind a webservice is a service that create a link between some applications. What I want to do is calling a c++ program installed on a server into a webservice.
However I have found how to call a webservice in a c++ program but that's not what I am looking for.
How do you call a c++ code into a webservice ( I am using VS2013 btw) and is it relevant to do that.
So my question is : How do you call a c++ code into a webservice ( I am using VS2013 btw) and is it relevant to do that.
A web service is a service accessible remotely, which publishes several "endpoints".
Each endpoint corresponds to a function call (possibly implemented in C++).
To call a webservice endpoint, you must serialize the input parameters of the endpoint in a format accepted by the web service (in practice, this usually means generating a SOAP/XML document that contains the values of the parameters), then sending the serialized document to the server. The server then de-serializes the parameters, calls the function, serializes the result, and sends it as a response.
Webservices publish their endpoints (their accessible/callable APIs) in another XML standard, called WSDL, and public web services are usually listed in a public directory.
For this you will need a networking library usable in C++ (see gSoap), or an implementation of your own, on top of a networking library (see boost::asio).
It depends on in which language your web service is coded.
If it is PHP, see the function system to run another programme that you can code in any language you want (including C++ then).
If it is C/C++ on Linux, see the functions fork/exec's to create a new process and run another programme in that new process.
If it is C#, see this tutorial on Process.Start.
If it is Python, see the subprocess package from the standard library.
Anyway, if your web service is in C++ and that the code you want to execute is in the same programme, you can just do a function call in your web service's method.
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.
I am building a prototype hybrid app with a Flex3 RIA client and backend Axis2 in Java on Tomcat 6. As this is a prototype, and given that I keep options open for factoring in other client types, I'm using a plain old SOAP service between client and server, rather than any Flex-specific technologies like BlazeDS
Although there is much debate about the need for stateful behaviour on the backend for an RIA, I need to consider the possibility of maintaining transport-level sessions between client and server. From reading the docs for both Axis2 and Flex, this appears to involve
(a) setting scope="transportsession" in services.xml, and
(b) ?what? in Flex
Can anyone help with (b)?
The webservice client classes are being generated in Flex Builder using the WDSL introspection wizard, so unless I refactor this, I only have access to the methods thus exposed.
I have found zero examples of the above online, and the FLex documentation leaves something to be desired in this area.
All help appreciated.
D
This is bit old article . but may be useful.
transportsession : This session is managed using transport cookies, and the lifetime is equal to the lifetime of the underline transport.
http://wso2.org/library/2060
I just asked a question about whether it was possible to write a web-page-checking code and run it from free web server, and one supporter answered and said that it was possible only if I run "a web service" as simple script won't do that. He also suggested that I used Google App Engine service. I wonder what does it mean to write a "web service" and how is it different from writing a script?
A web service essentially provides the capability of RPC (Remote Procedure Calling) on top of the protocol of the web (HTTP). A URL implements an API which accepts a set of function arguments and returns a value. Different approaches are used to implement this RPC mechanism on top of HTTP protocol. XML-RPC defines a simple mechanism to specify the arguments and response using XML. SOAP is a much advanced version of XML-RPC. JSON-RPC lets you specify the procedure arguments and return values using JSON (JavaScript Object Notation).
Several programming languages come with built-in support for developing and working with web services. For example in Python, xmlrpclib provides the client side functionality of XML-RPC protocol. The XmlRpcServer library in Python makes it very easy to develop an XML-RPC based web server. Web services are interoperable in the sense that the client and server can be easily implemented in different programming languages and they don't need to worry about the details of each other.
Web services are different from other RPC mechanisms like COM/CORBA/JAVA's RMI. These RPC mechanism use binary data for exchange of arguments and results. The web services uses text oriented protocols like XML/JSON to implement the RPC protocol. Hence they are heavier from the perspective of communication overhead. They are still very good for development of loosely coupled systems. One big advantage they have is the fact that they are not tied to a specific programming language.
By "web service" one normally refers to a service available through HTTP protocol. The protocol sitting on top of HTTP can vary (XML, SOAP, JSON etc.).
But of course one can "complicate" the definition at will :-)
This is example of web service: http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate
When you scroll down you will see you can supply two parameters and get result back. Webservices can support different methods of communication. You can communicate with it using XML, SOAP, or HTTP GET/POST.
So web-service is a special type of script which main function is to expose method to public use (you can set access permissions a well), perform calculations on server-side and return output.