Wildfly: web service deployed but unavailable - java

Problem description:
I want to deploy a web service through Wildfly and it gets deployed, but I cannot access it through a web browser.
This is what I do:
I run standalone.sh
I deploy the project using mvn clean package wildfly:deploy
Then I try to access my webservice through a web browser at http://localhost:8080/lab-ear/Hello?wsdl but I get only: "404 - Not Found"
Fragment of maven logs while deploying.
Here are logs from Wildfly server when it gets initialized.
And here Wildfly logs during deploy.
Other details:
I've done another project where the web service worked, but there were other problems, so I started everything from scratch.
This image is the comparison of structures of these two projects. On the left the old project and on the right the new project.
The important thing is that in the new project I don't get the web directory.
Maybe related problem:
Wildfly : application deployed but not running
Also, is it required to use Intellij IDEA in such projects?
EDIT
In my EJB module I have a class Hello in package pl.edu.agh.soa
I tried to change from this:
#Stateless
#WebService
public class Hello {
...
to:
#Stateless(name = "Hello")
#WebService(name = "HelloService")
public class Hello {
...
But it also doesn't work.

I was able to get a simple "HelloWorld" type JAX-WS service running with just the code:
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
#WebService
#SOAPBinding(style = SOAPBinding.Style.RPC)
#Stateless
public class HelloWorld {
#WebMethod
public String sayHello( String name ) {
return "Hello " + name;
}
}
From this I'm able to access the URL http://localhost:8080/<web-app-name>/HelloWorld?wsdl. This is in Wildfly 18.
The issue is that you don't specify a #WebMethod. While the class is marked correctly there isn't anything to "run" in it.
Additionally, while it does work with the #Stateless EJB annotation that isn't required for JAX-WS but may be required for your code.

Intellij IDEA is not required at all.
I think your issue is the missing web directory. Without WEB-INF/web.xml the app server won't know what it is supposed to serve.

Problem solved. I think I had unnecessarily changed too many dependencies' versions in pom.xml files.
Also, in main pom.xml file only <version.wildfly.maven.plugin> needed upgrading from 1.0.2.Final to 2.0.2.Final, but earlier I had also changed other plugins' versions.

Related

How to cleanly undeploy Spring Boot/Jersey war in tomcat

Consider a very simple Spring Boot/Jersey application setup:
Generate a fresh Spring Boot application using Initializr and select the Jersey dependency (in my case, I prefer the Gradle setup).
Add simple Controller and Configuration classes:
JerseyConfig.java
package com.example.unload;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.context.annotation.Configuration;
#Configuration
public class JerseyConfig extends ResourceConfig {
JerseyConfig() { register(TestController.class); }
}
TestController.java
package com.example.unload;
import org.springframework.stereotype.Component;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
#Component #Path("test")
public class TestController {
#GET public String test() {
return "test";
}
}
Run the war task and deploy the WAR to Tomcat (8.5 in my case).
Whenever I want to undeploy (e.g. for re-deployment) the WAR, I get the following error message
Oct 23, 2017 8:13:11 AM org.apache.catalina.startup.ExpandWar deleteDir
FATAL: […\apache-tomcat-8.5.20\webapps\unload-0.0.1-SNAPSHOT\WEB-INF\lib] could not be completely deleted. The presence of the remaining files may cause problems
The culprit is the jersey-server-2.25.1.jar in the lib directory, to which apparently some classloader must have a reference. I also cannot manually delete the file, because Java holds a lock on it.
Interestingly, after manually executing a GC run (externally through jvisualvm), I am able to delete the jersey-server.jar.
So, I suspect that a stream is not properly closed (but does get closed during finalization).
Of course, manually performing a GC run is not an option in a production environment.
I tried to call System.gc() in the contextDestroyed callback of the ServletContextListener, but this gets called to early when there are still live references.
I am also aware of the antiResourceLocking option in the context.xml file, but this creates copies of the whole WAR content in a temp directory, without ever removing it (which might be the job of a cron job). However, this feels more like a work-around and not a productive solution.
A third possible option is to extract all Spring, Jersey and related dependencies and move it to the Tomcat's shared lib directory, but I prefer to bundle all necessary dependencies to ease deployment for customers.
What other options do I have, and what is the root cause?
I have not found any reference to a bug in neither Tomcat, Spring, nor Jersey.
I could reproduce this issue with Jersey 2.26 and jersey-hk2 2.26.

Expose an EJB session bean as JAX-RS using Eclipse and Jboss EAP 6.2

I have EJB project and try to reused session bean as Rest WebService by adding annotation.
The following is what I am doing:
1) extends application to
#ApplicationPath("resources")
public class QMWSApplication extends Application
{
}
2) add annotation to the bean
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
#Path("/ws")
#Stateless
#LocalBean
public class TestWS {
#GET
#Path("/test")
#Produces("text/plain")
public String getTest()
{
3) Then configure the EJB project as customized adding JAS-RS facet to the project.
Then on project explore, I can see there is URI under JAX-RS web service.
But after I add the the final EAR to JBoss server (EAP6.2), and test on the browser, I always get 404 error. I am sure URL is right since, on the project browser, I left click the rest full GET and the web service tester on eclipse has same URL and also get 404 ERROR. Anything wrong?
I have put up an example for this at https://github.com/alexcpn/rest_in_sessionbean
Tested with JBOSS AS 7.1.1. Note that a war file is needed in the ear, with a web.xml . This is using JBOSS inbuilt RESTEasy.

netbeans 7-8, inject of remote ejb

Hi, I have an EJB project called "service-ejb" with this:
#Stateless
#Remote(ServiceRemote.class)
public class Services implements ServiceLocal, ServiceRemote {
[...business code...]
}
the I have the local interface, in the same project:
#Local
public interface ServiceLocal { }
and the remote interface, in a class library project called "service-lib":
#Remote
public interface ServiceRemote {
public boolean checkIfOk();
}
I can deploy it without problem, alone or in a java EE application. The point is that I don't understand how to tell NetBeans that I wish to call that beans from another application. For example I have another java EE project with a war component, where inside a servlet I wrote:
#EJB
private ServiceRemote serviceTest;
but of course it will fail compiling, so I tried with:
InitialContext ic = new InitialContext();
ServiceRemote serviceTest = (ServiceRemote) ic.lookup("ServiceRemote");
with no luck... Where in NetBeans I can tell it to use the "service-lib" as a reference? I don't want it to be added as library and then deployed with the ear, I only want NetBeans to compile correctly the code.
Sorry if the question sound silly, but I've read the documentation and I don't understant what I'm missing...
--- edit ---
I'll try to be more clear. "service-ejb" reference "service-lib", so I've deployed "service-ejb" to glassfish. Correctly, I have:
glassfish_applications_directory $ find -name "service*"
./__internal/service-ejb
./__internal/service-ejb/service-ejb.jar
./service-ejb
./service-ejb/com/tecytal/components/email/beans/Service.class
./service-ejb/com/tecytal/components/email/interfaces/local/ServiceLocal.class
./service-ejb/service-lib.jar
Then I open a java EE project, let's call it "myEngine" with a war module "myEngine-war". I've tried to add to "myEngine-war" a reference to "service-lib", of course, and in this case it compile well. The point is that I can do everything, tell to netbeans NOT to package the "service-lib" with the war, but when I deploy "myEngine" I get:
glassfish_applications_directory $ find -name "service*"
./myEngine/lib/service-lib.jar
./__internal/service-ejb
./__internal/service-ejb/service-ejb.jar
./service-ejb
./service-ejb/com/tecytal/components/email/beans/Service.class
./service-ejb/com/tecytal/components/email/interfaces/local/ServiceLocal.class
./service-ejb/service-lib.jar
I DON'T want to have TWO service-lib.jar in my server, one in the service-ejb and one in myEngine, I don't understand how I can use a remote ebj in netbeans telling to him NOT TO deploy the same lib 3214899213 times :)
I recommend to add the remote service interface and all classes it references (including exceptions) in a separate jar. Then in the other 2 projects declare a dependcy to this jar.
I don't want it to be added as library and then deployed with the ear
I recommed to add only the service-lib contain the interface etc as a library and deploy it with the ear, not the whole service-ejb containing the implementation.

how to make Url in web service so that i can directly Invoke hello world

package com.hcl.test.ws;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
#Path("/hello")
public class HelloWorld {
#GET
public String hello() {
return "Hello This is RestFull Web Service/";
}
}
This is my code and working Perfectly but i want deploy its war file in server. currently i am invoking like this in eclipsed[http://localhost:8080/SecondrestFullClient/sampleHelloWorldProxy/TestClient.jsp] but i want to deploy it in server lcaolhost:8089 server so that every one can use from this please help ..
You can wrap it into a war either using a build tool like ant or maven, or if you're using Eclipse just right click on the project and go to "Export - Web - War File".
Then, you should install a local copy of Tomcat on your host. Change the settings.xml file so it runs on 8089 rather than the default 8080 and you should be able to invoke the service as you mention above.

How do I create a non-EJB super simple web-service .war for Java in Eclipse?

I have been attempting to create a super simple web-service (non-SOAP wsdl Server) within Eclipse Java EE (Juno) using Java 1.6. I want the web-service war to be as simple as possible, as in this simple (first reply in the thread).
IOW, I want the war file to just have the class I have defined (which includes the #WebService and #WebMethod annotations) and possibly a web.xml file which can then be deployed in Eclipse Java EE to the JBoss 6.0 server I have set up.
I must be missing some simple step somewhere. Each time I have tried, I either cannot get the web-service to deploy, or Eclipse wants to auto-generate and add a huge number of useless classes to the deployment.
I have Eclipse Java EE set up and I created a File -> New-> Dynamic Web Project and call it ProjectHelloService. I then create a single class in the project under Java Resources/src in its own package, ws.simple. The class looks like this:
package ws.simple;
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService
public class HelloService
{
#WebMethod
public String sayHello(String name)
{
return "Hello, " + name;
}
}
I then start up the JBoss server and "Add" the project to JBoss. I see the "...deploy, ctxPath=/ProjectHelloService" message indicating that my project has deployed. However, when I go to the default JBoss page -> JBoss Web Services Console -> View a list of deployed services, I see "There are currently no endpoints deployed ". When I dig around and try to see what was deployed in JBoss's server/default folder, I cannot find anything in the deploy folder.
Again, I must be missing some step somewhere. For example, I don't see a .war (or even .jar) file being generated, in Eclipse nor in the JBoss deploy folder. However, I am not deeply versed in the nuances of how Eclipse works with JBoss 6.0, so I might be missing some configuration subtlety here.
Is there something simple I can do to get a super stupid simple .war file to deploy to the Eclipse contained JBoss 6.0 so that I can see my web-service? And since JBoss is able to do all the auto-file generation automatically from the annotations in the .war file, I don't want Eclipse to do all the extra file stub generation crap. That's CORBA old school style, and makes for a much less manageable project (at least for the area I am working in right now).
And I don't suppose there is some way that I can have the above in Eclipse while having the convenience of the Netbeans approach to creating and managing Java web-services. If there is, I sure would like to know what it is.
Thank you for any guidance and/or assistance you can over here.

Categories