JBoss WebServices and EJB - web-services

My application should show a list of stuff over RESTful WebServices.
This list of stuff is generated via an EJB which is deployed in JBoss AS 6 in a .jar.
My question is, how do I get this list of stuff in order to show it via Web Services?
If I try to inject #EJB in the stateless bean annotated with #WebService, and try to invoke the method that generates the list, I get an error saying that #EJB cannot be resolved (or imported). (fixed it, needed to modify maven dependencies).
Now I get a NullPointerException when I call the supposedly injected EJB...
I am using the webapp archetype from Maven, which contains an EAR, a JAR and a WAR.
I am at a total loss here, been trying to figure this for almost a week.
Thanks in advance!
--EDIT-- code and typo fixed
This is my stateless bean which SHOULD be exposed as a WebService (according to:
http://www.adam-bien.com/roller/abien/entry/restful_calculator_with_javascript_and )
#Stateless
#Path("/MyRESTApplication")
public class HelloWorldResource {
#EJB
private TestBean testBean;
#GET()
#Produces("text/plain")
public String sayHello(String name) {
return testBean.doMoreStuff();
}
}
the doMoreStuff() function simply returns "HELLO!".

Related

Axis2 Faulty Pojo Web Service

I have created a pojo as below.
package demo;
public class HelloWorld {
public String sayHello(String name) {
return "Hello " + name;
}
}
I placed it in axis2 war and opened
http://localhost:8080/axis2/services/listServices.
Axis 2 is indicating it as faulty service
Faulty Services
<TOMCAT-DIR>\webapps\axis2\WEB-INF\pojo\demo\HelloWorld.class
But when I remove package declaration statement and place it on below location, everything works fine
<TOMCAT-DIR>\webapps\axis2\WEB-INF\pojo\HelloWorld.class
Now there are two possibilities
Package declaration is not allowed in pojo (and I don't believe this).
I am missing something.
Can anyone guide me?
In the book "Apache Axis Web Services, 2nd Edition", author described that when exposing a pojo class as a web service by dropping in into pojo folder, pojo class must be defined in default package.
When pojo class is defined some package, following link is helpful.
http://axis.apache.org/axis2/java/core/docs/pojoguide.html
Thanks to shashankaholic for sharing this link.

Access EJB 3.0 as an EJB and as a web service on Websphere 7

I want to deploy an EJB 3.0 stateless bean to WAS7 so I can access it as an EJB through a local interface and also as a jax-ws web service.
My bean looks as following:
#Stateless
#WebService
public class UserManagerImpl implements UserManager {
public UserManagerImpl() {
}
#WebMethod
public String getName(){
return "UserName";
}
}
The problem is that if I package it into an EJB-JAR and deploy, it doesn't work as a web service on WAS-7.
The only working configuration for me is if I put the EJB-JAR into a EAR and put this EJB-JAR to a WAR that is also in the EAR, like this:
EAR/
|--EJB-JAR
|--WAR/
|WEB-INF/lib/
|EJB-JAR
So my bean is duplicated.
Is there any problem with this design? If so, is there a better solution?
If your application contains #WebService annotated EJBs, then you need to process the EAR with the endptEnabler tool shipped with WebSphere before deploying it. Note that this doesn't apply to #WebService annotated classes in Web modules.

Is it possible to define a servlet filter for a stateless ejb webservice, on GlassFish 3.1

I want to export a Web-Service which was implemented as a stateless EJB. I know that these WebServices were hanled by the EJB Container, when they are annotated as #Stateless + #Webservice. Is it possible to route all incoming requests to this Webservice through a Servlet-Filter.
The Servlet-Filter works when my Java-Class is annotated #Stateful and #Webservice, or just #Webservice. But not in conjunction with #Stateless. Anyway to register a Servlet Filter for an EJB Webservice?
Many thanks!
Adem
UPDATE:
Solved this problem, by annotating WebService Class with
#WebService
#RequestScoped
Filter works only in this constellation and acting as Stateless class for WebService consumer.
Lifecycle Callbacks : You can have a method with #PostConstruct annotation which gets called after the container has initialized the bean.
Interceptor : You can have a interceptor class which gets invoked when applied at bean class/method level by annotation #Interceptors(ProcessMonitor.class).
Note : I haven't tried it in conjunction with #Webservice.

Java EE 6 WebService and CDI injection

This is a clarification question I've got from a Java EE 5 migration. I'm currently developing a Java EE 6 web service packed in a WAR file, and I would like to know if it's possible to use CDI on it. I've seen some examples using the #Stateless annotation, which it's not possible to do in a WAR (as far as I know).
Current implementation:
#WebService
public class MyService{
#Inject
HelloTeller teller:
#WebMethod
public String sayHello(){
teller.sayHello();
}
}
Note: The other approach would be to create an ejbModule specifically for this web-service.
In EE6, you should be able to use a SLSB as JAX-WS endpoint in a war. You can inject EJBs, request scoped and application scoped beans from CDI.

Calling a web service from struts application

Would anyone be able to tell me how I can call a webservice in my struts application?
Well, I can think of several ways to do this depending on the web service. Most IDEs have ways to auto-generate webservice clients. I would probably create a java library package that which wraps the service client and provides an interface for your Struts application to invoke the client methods from within your Struts action class.
For example, if the service has a method getPerson(), I would create a remote DAO class that invokes the web service getPerson() method:
public class PersonServiceInterface{
public Person getPersonFromService(){
// web service calls to retrieve person object
return person;
}
}