Hi, I am new to Jboss seam but I am having a great time learning it.
I am trying to use seam components with a very simple web service and I keep receiving:
java.lang.IllegalStateException: No application context active
Here is my code and this error happens when i call Component.getInstance.
@Stateless
@WebService(name = "SampleService", serviceName = "SampleService")
public class SampleService {
@WebMethod
public DefaultWebServiceResponse runDbScript(String username, String password,String env,
String database, String script)
{
DefaultWebServiceResponse response = new DefaultWebServiceResponse();
Queries queries = (Queries) Component.getInstance("queries");
List<Users> list = queries.getUsers(username, password);
if (list.size() == 0)
{
response.setDescription("User/password combination does not match");
response.setReturnCode("-1");
return response;
}
// return response
response.setDescription("Just a stub");
response.setReturnCode("0");
return response;
}
}
And the queries Component:
@Name("queries")
public class Queries implements QueriesLocal{
@In
EntityManager entityManager;
public Queries()
{
}
@SuppressWarnings("unchecked")
public List<Users> getUsers(String username, String password)
{
List<Users> matchedUsers = entityManager.createQuery(
"from Users where username= " + username +
" and password = " + password
).getResultList();
return matchedUsers;
}
}
I have also added standard-jaxws-endpoint-config.xml to META-INF folder. The web service without seam works well and so does the rest of the user interface. My only issue is that I cannot use seam components inside the web calls.
Since this is a web service call, do I need to do anything else to enable seam contexts to work?