• Post Reply Bookmark Topic Watch Topic
  • New Topic

deploy webservice which access application level object  RSS feed

 
Joe Blant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I wish to develop webservice using axis which access application level object,which live as long as application life time. I want to access ServletContext, so i write my web service class as Servlet ....

//loader servlet to load application object
import javax.servlet.*;
import javax.servlet.http.*;

public class Loader extends HttpServlet{
public void init(ServletConfig conf){
Integer counter = new Integer("0");
conf.getServletContext().setAttribute("cnt",counter);
System.out.println("::::::::::::::::::::::: sucessful!");
}
}

.......
//in web.xml
<servlet>
<servlet-name>Loader</servlet-name>
<servlet-class>Loader</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

...

//here is web service file "CounterWebService.jws"
import javax.servlet.*;
import javax.servlet.http.*;

public class CounterWebService extends HttpServlet{
ServletContext context;
public void init(ServletConfig conf){
context = conf.getServletContext();
}

public String getCounter(String str){
Integer counter = (Integer)context.getAttribute("cnt");
if(counter==null) return "Dont get application object";
counter = new Integer(counter.intValue()+1);
context.setAttribute("cnt",counter);
return String.valueOf(counter.intValue());
}

}

and when i call http://localhost:8080/axis/CounterWebService.jws
tomcat command display the following error
- The class javax.servlet.ServletConfig is defined in a java or javax package an
d cannot be converted into an xml schema type. An xml schema anyType will be us
ed to define this class in the wsdl file.

I'd like to know we can access applcation level object from web service? If then how to access it.


Thanks in advance
kaze
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web services are not implemented as servlets in Axis. If you look at the JWS deployment example, you'll see that it's just a regular Java class with public methods that get exposed as WS operations.

By the way, is your name really "ka ze"? I'm asking because we have a policy on screen names here at JavaRanch, and it states that it must consist of a first name, a space, and a last name, and not be obviously fictitious. If yours does not conform with it, please take a moment to change it, which you can do right here.
 
Joe Blant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Ulf Dittmer,

When i try this kind of web service in WebSpere Application Developer IDE, it also fails. Are there any other ways to deploy web service like this?

Thanks,
Kami Kaze
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kami Kaze",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with display names get deleted, often without warning

thanks,
Dave
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JWS is a WS deployment method particular to Axis - it wouldn't work the same way in WebSphere. Have you been able to get the JWS example I linked to up and running? Once you have that working, you should be able to rewrite your code along the lines of that example.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!