I have an axis java web service, which I use for inserting and receiving data from database. As far as I know, constructor of web service is called only when client connects, and when it disconnects, a "destructor" is called. So every time a client connects to receive or insert data, I need to run method connectToDatabase(). How can I connect only once, when web service is started, and when client connects simply insert/receive data? Is there any special way to do it in Eclipse?
You need to create an object which will be instantiated when your application first starts up. To do that you can use spring and expose your web service implementation class as a spring bean. Than create some king of object which will have a method connectToDatabase(), call that method in this object's constructor or specify it as an init method and declare this object in spring configuration. When application is being deployed spring creates that object for you and call this method only once.
To expose axis web service as spring bean do the following:
In axis server-config.wsdd file specify this:
<service name="YouServiceName" provider="java:SPRING" style="wrapped" use="literal">
Attribute provider="java:SPRING" tells axis to that the implementation class is exposed as spring bean.
Hope this helps.
Related
I'm using Eclipse Juno to create a Web Service Client for consuming a WSDL SOAP web service.
It generated 2 packages, one with the web service name and another with "org.tempuri.dataset_ISI_xsd".
Inside the first package there are some classes like:
1- ServiceName
2- ServiceNameProxy
3- ServiceNameService
4- ServiceNameServiceLocator
5- ServiceNameSoapBindingStub
I'd like to know wich class should I use to call the web service methods and how to obtain the values returned by the method.
Thanks in advance
Instantiate the xxxProxy class, call the setEndpoint() method passing the url of the web service host, then call the method matching the name of the web service. The return type of the method will depend on the definition of the web service.
I have created a my-services-portlet in which i have AbcService, which I am calling from my templates like this
#set ($VeloToolsService = $serviceLocator.findService('my-services-portlet, 'com.mycompany.services.AbcServiceLocalService'))
#set ($article = $AbcService.getArticle($list))
$journalContentUtil.getContent($article.groupId, $article.articleId, 'view', $themeDisplay.language-id, $xmlRequest)
Now due to new requirement, i need to call the same service from another custom mvc portlet. I am not able to the service handle for the service. what is the proper way to get the service handle? so that i can call my existing service from the portlet.
copy the AbcService-service.jar file from first portlet to tomcat/lib/ext folder, restart liferay, and you get access to the service classes.
See http://www.liferay.com/de/community/forums/-/message_boards/message/4585610 the answer from Mika Koivisto.
I have a webapp on one Glassfish server (front-end) and an EJB 3.1 app (back-end) on another Glassfish server. The webapp communicates with the EJB 3.1 via remote invocation.
I would like to pass context data (user data i.e.) without having to define it as an input parameter of each business operation.
I have one idea, but not sure it will work: use a ThreadLocal to store data, but the ThreadLocal will only be available on one server (meaning JVM) => use the InvocationContext object and create interceptor to add user data to the ContextData Map.
What do you think about it? Any other ideas are more than welcome! ;-)
UPDATE
After first answer, I googled it a little bit and found the annotation #CallerPrincipal.
How can I set this object before the remote invocation?
The container will already handle this so you don't have to code it yourself.
In your EJB, you can access the EJBContext, which has a getCallerPrincipal() method which will give you the callers identity.
After playing around with example SOAP application Calculator from NetBeans, I began making my own app, using some third-party WSDL's as service models.
I managed to successfully create a web service classes from this WSDL, unfortunately, when I try to inject this service into my servlet (called ClientServlet), I got 500 error
"javax.servlet.ServletException: Error instantiating servlet class clients.ClientServlet".
The service interface methods are defined in Interface class MyServiceInterface. Don't ask me why it is that way - this service is made by third party.
When I comment out this annotation, and subsequent field declaration, then it works (but I can't use this service).
My code snippet:
#WebServiceRef(wsdlLocation="url/to/wsdl/of/my/service.wsdl")
public MyServiceInterface service;
Of course, I tried to do this without dependency injection, by direct creation of the instance of this class:
service1 = new MyService().getMyService();
MyService.java was created during importing a service from WSDL. GetMyService() method should return instance of the class that is implementing MyServiceInterface. But instead, Java throws me
exception at javax.xml.ws.Service.getPort(Service.java:92)
I am using Apache Tomcat 7.0 and Netbeans 7.0 IDE. What I should do now?
SOLVED - I just made it from scratch using GlassFish 3.1 server.
I am using the JAX-WS "WebService" annotation on a class to expose its "WebMethod"s as a web service. The class is denoted as the servlet class handling calls to "/MyService".
As essentially a servlet, I would expect an instance of this class to be created once and to basically be a singleton. I have code in the constructor of this class to create an EntityManagerFactory for assignment to a member variable. What I'm seeing is that the constructor is being called for every client request to the web service. This is not good.
Does anyone know what's going on here? Does anyone understand what I'm trying to ask? :)
Thanks.
As essentially a servlet, I would expect an instance of this class to be created once and to basically be a singleton.
It's up to container. You cannot rely on it.
Create a real singleton -- a simple Java class -- which does all the heavy lifting, and call it from the servlet.
Your topic mentions a SLSB, which I assume is "Stateless Session Bean". In Java EE 5 you can create web services either from a Stateless Session Bean, or you can annotate a class and the runtime will publish it as a webservice when deployed in a compliant web container.
In either case, neither of these are Servlets per se, and don't follow a Servlet lifecycle.