Webservice unavailable when packaged in EAR - java

We have a webservice which is included in an ejb-jar within an ear. That jar is then deployed to a JBoss 7.2.0.Final instance.
According to this JBoss documentation using webservice annotations on the session bean should be sufficient.
Thus the webservice looks like this:
#WebService(name = "TestWS", targetNamespace="http://test.com/ws")
#WebContext(contextRoot="/test-ws", urlPattern="/*", transportGuarantee="NONE", secureWSDLAccess=false)
#Stateless
public class TestWS
{
#WebMethod
public String sayHello()
{
return "hello";
}
}
When the ear is deployed exploded everything works fine. The problem is, when deploying the packaged ear (.ear-file) the service doesn't seem to be available.
Management console displays this information in both cases:
Context: test-ws
Type: JAXWS_EJB3
WSDL Url: http://localhost:8080/test-ws?wsdl
During startup the following is logged in both cases:
[org.jboss.ws.cxf.metadata] (MSC service thread 1-4) JBWS024061: Adding service
endpoint metadata: id=TestWS
address=http://localhost:8080/test-ws
implementor=com.test.TestWS
serviceName={http://test.com/ws}TestWSService
portName={http://test.com/ws}TestWSPort
annotationWsdlLocation=null
wsdlLocationOverride=null
mtomEnabled=false
...
[org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-9) Setting the server's publish address to be http://localhost:8080/test-ws
When the ear is exploded opening http://localhost:8080/test-ws?wsdl retrieves the wsdl, when the ear is packaged, I get the following result:
JBWEB000065: HTTP Status 404 - /test-ws
JBWEB000309: type JBWEB000067: Status report
JBWEB000068: message /test-ws
JBWEB000069: description JBWEB000124: The requested resource is not available.
Any ideas what might be missing?

I too faced this in many projects. Any one of the below ways might work :)
1.) Package a WAR within the EAR and have web.xml which will give a kick-start to your webservices
2.) Try to load the jar in META-INF/application.xml which will perfectly include your JAR file.
The application.xml will look like this
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
<display-name>project-name</display-name>
<module>
<java>your_jar_file_name</java>
</module>
</application>

Related

jaxws and apache cxf and glassfish 5 error: java.lang.IllegalStateException: The lifecycle method [finalizeConfig] must not throw a checked exception

I saw this and other similar questions before and their solution didn't solve my problem because Glassfish 5 had a lot of changes.
I'm running a soap web service and getting this error:
java.lang.IllegalStateException: The lifecycle method [finalizeConfig] must not throw a checked exception. Related annotation information: annotation [#javax.annotation.PostConstruct()] on annotated element [public void org.apache.cxf.transport.http_jetty.spring.JettyHTTPServerEngineBeanDefinitionParser$SpringJettyHTTPServerEngine.finalizeConfig() throws java.security.GeneralSecurityException,java.io.IOException] of type [METHOD]
at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:503)
at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:423)
at org.glassfish.web.deployment.archivist.WebArchivist.postAnnotationProcess(WebArchivist.java:317)
at org.glassfish.web.deployment.archivist.WebArchivist.postAnnotationProcess(WebArchivist.java:68)
at com.sun.enterprise.deployment.archivist.Archivist.readRestDeploymentDescriptors(Archivist.java:397)
at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:372)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:247)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:256)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:217)
at com.sun.enterprise.deployment.archivist.ApplicationFactory.openArchive(ApplicationFactory.java:137)
at org.glassfish.javaee.core.deployment.DolProvider.processDOL(DolProvider.java:183)
at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:207)
at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:73)
at com.sun.enterprise.v3.server.ApplicationLifecycle.loadDeployer(ApplicationLifecycle.java:857)
at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(ApplicationLifecycle.java:797)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:354)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:195)
...
I'm using Glassfish 5.1.0 and using Apache cxf 3.3.5 and my IDE is Eclipse EE Version: 2019-12 (4.14.0)
I downloaded Apache CXF binary distribution and added in to eclipse CXF runtime.
This is my web service class:
package com.web.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService(targetNamespace = "localhost:8080")
public class Service {
#WebMethod public String greet(String name) {
return "Hi," + name;
}
}
The org.apache.cxf.transport.http_jetty.spring package causes problems when deployed to Glassfish. You need to remove that from the CXF binary distribution.
Please try the following steps:
First remove the original binary distribution from your project in Eclipse.
Then you need to open the binary distribution with some archive tool (maybe the operating system you are using contains something already) and navigate to the lib folder in the archive. Delete the file cxf-rt-transports-http-jetty-*.jar.
Then add the changed binary distribution to your project like you did before with the original binary distribution.
Maybe this will already be sufficient. If not, there is another step you can try.
It is more or less the same solution that you linked already. However, I am not sure if Glassfish 5.1 will still accept the sun-web.xml file. It should be named glassfish-web.xml nowadays.
So create the file glassfish-web.xml with following content:
(if you already have that file, only add the <class-loader delegate="true"/> line to it)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
<class-loader delegate="true"/>
</glassfish-web-app>
Put the file into the WEB-INF folder of your WAR file.

Weblogic SOAP service deployment errors reporting two ports in war when there is only one

I have a weblogic server with a cluster of two SOA servers.
I am deploying a servlet to this server with a SOAP servlet created with the JDeveloper wizard (Create Java Web Service from WSDL -> Java EE 1.5, with support for JAX-WS Annotations)
It is deployed as a standalone application.
During the development of the application I have changed the WSDL in various ways including changing the port name.
I have gone into the weblogic interface, deleted the previous instalisation and re-deployed through JDeveloper. I get the following error message:
[08:44:59 PM] weblogic.management.DeploymentException: Error encountered during prepare phase of deploying WebService module 'RJMTestBannerAdapter.war'. Two port in the callBannerService(WebserviceDescriptionBean) has the same name {http://ic.ac.uk/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Banner/V1/APIJavaAdapter/BannerAPIJavaAdapterWsdl}callBanner.
It is complaining that there is two ports in the application with the same name. But there isn't.
I have inspected the .war file that JDeveloper produces
The WEB-INF/web.xml has a single entry for the service
The WEB-INF/weblogic.xml is also correct and just specifies the context-root.
I have determined that somewhere in the weblogic servers there must be something with the end point that is not being cleared away when I delete the application.
I have checked the weblogic console user interface, gone through the list of web applications and services and confirmed it is not there.
Does the weblogic server have a deployment plan file or something simular it is picking up while deploying? If so where would this deployment plan be?
I don't think it is important but here is my web.xml:
<?xml version = '1.0' encoding = 'UTF-8'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>callBanner</servlet-name>
<servlet-class>ic.ac.uk.ic.rjmtest.banner.adapter.gen.main.Main_ptImpl12</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>callBanner</servlet-name>
<url-pattern>/callBanner</url-pattern>
</servlet-mapping>
</web-app>
Also this is the weblogic.xml that appears in the war file. (It is not in my project but JDeveloper must generate it)
<?xml version = '1.0' encoding = 'UTF-8'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<context-root>RJMTestBannerAdapter</context-root>
</weblogic-web-app>
I have also inspected the WSDL and there is only a single port.
I finally found the answer.
When I used JDeveloper to regenerate the classes for the service I must have changed the name somehow. This resulted in new java being built.
As I didn't delete the classes or deploy directory the old ones were still there in my war file. So I was trying to deploy two even though my .java files didn't reflect this.
Deleting the classes and deploy directories then recompiling resolved the issue.
This post might be useful for anyone else who hits this error!

WildFly9.0 - adding web service access

I am migrating my RESTful web application from GlassFish4.1 to WildFly9.0 for the first time.
Initially, I suffered deployment issues due Jersey dependencies. To overcome that problem, I simply replaced said project dependencies with RESTEasy equivalents inside of the pom.xml file. In doing so, my application became deployable -- and according to (WildFly_base)/standalone/log, and the applications themselves -- are working as expected.
Additionally, I added a jboss-web.xml configuration file to my WEB-INF folder:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "http://www.jboss.org/j2ee/dtd" "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">
<jboss-web>
<context-root>myprojectstart</context-root>
</jboss-web>
The hello-world page can be reached # http://ipaddress:8080/myprojectstart.
... however, I cannot view my web services # http://ipaddress:8080/myprojectstart/getData, just like I could when using GlassFish-4.1.
So; what am I missing?
Note: I use #annotations like:
#ApplicationPath("/*")
#Path("/getData")
No seperate .xml business here
I don't think RestEasy supports * in ApplicationPath. If you remove that it should work fine.

Not able to deploy EJB in WebLogic server 12c

I have created a EJB, created a jar of it( containing required ejb-jar.xml and weblogic-ejb-jar.xml files).
when i add this jar to weblogic server 12c, using admin console, i get following issue-
Issues were encountered while parsing this deployment to determine module type. Assuming this is a library deployment.
Due to this my ejb is not shown in jndi tree view. So I am not able to do my jndi lookup. Please rectify my error.
ejb-jar.xml-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar id="ejb-jar_ID">
<display-name>ProductManager</display-name>
<enterprise-beans>
<session>
<ejb-name>Product</ejb-name>
<home>rohit.ProductHome</home>
<remote>rohit.ProductRemote</remote>
<ejb-class>rohit.ProductBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<ejb-client-jar>ProductManagerClient.jar</ejb-client-jar>
</ejb-jar>
weblogic-ejb-jar.xml-
<?xml version=“1.0? encoding=“UTF-8??>
<weblogic-ejb-jar
xmlns=“http://www.bea.com/ns/weblogic/90? xmlns:j2ee=“http://java.sun.com/xml/ns/j2ee” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd”>
<welogic-enterprise-bean>
<ejb-name>Product</ejb-name>
<jndi-name>Product</jndi-name>
<stateless-session-descriptor></stateless-session-descriptor>
</welogic-enterprise-bean>
</weblogic-ejb-jar>
Contrary to what you seem to be thinking, the ejb-jar.xml and weblogic-ejb-jar.xml files are not required. As primary deployment descriptors they are ancient artifacts from 2004.
Your ProductHome class should also be removed if you value your sanity. This is an EJB2 artifact that's completely and utterly unnecessary this time of age.
To get started with EJB, all you need is a POJO with an #Stateless annotation:
#Stateless
public class ProductBean {
// ...
}
Jar this up and deploy it. That's all. You don't have to explicitly name your bean (it will get a name) and you certainly don't have to declare its existence in some XML file.
The ejb-jar.xml is mandatory when deploying an application as a jar file. The correct place to put it is in the META-INF in the jar.
Yes, annotations are definitely nice and easier to maintain. Try this by leaving the ejb-jar.xml minimal.
I always package my applications in EAR with the jars inside. In this case an application.xml file is needed.
It sounds like the container does not recognize the jar as an application. Check the position of the ejb-jar.xml or use EAR packaging.
Oracle recommends that even standalone EJBs be packed as an EAR file. The EJB descriptors should be inside the META-INF of the ejb-module.
See this link for the EAR structure for more details.
http://docs.oracle.com/cd/E24329_01/web.1211/e24368/splitcreate.htm#i1103260

ClassNotFoundException deploying webservice on Weblogic 10.3 with Hibernate

I have a project with a EJB implementing a JWS Webservice, like this:
#Stateless
#Remote(WebServiceTest.class)
#WebService(
serviceName="TestService",
name="TestName"
)
public class WebServiceTestImpl implements WebServiceTest {
#Override
#WebMethod(operationName="hello")
public String hello() {
return "Hello World!";
}
}
I deploy and test this perfectly on WebLogic 10.3 using a simple EAR project. Now I need to use Hibernate on my project, so from previous experiences I know that I have to use Antrl from Hibernate and not from the container, so I create a weblogic-application.xml in the EAR project:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application ...>
<wls:prefer-application-packages>
<wls:package-name>antlr.*</wls:package-name>
</wls:prefer-application-packages>
</wls:weblogic-application>
Now when I deploy the EAR I get this error:
Unable to deploy EJB: WebServiceTestImpl from test-1.0.0-SNAPSHOT.jar:
***** ASSERTION FAILED *****
at weblogic.ejb.container.deployer.EJBModule.prepare(EJBModule.java:467)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:507)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:149)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: test.WebServiceTestImpl_zd33dy_WSOImpl
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:280)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:253)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:177)
Truncated. see log file for complete stacktrace
How can I solve this? If I don't put Antlr in wls:prefer-application-packages Hibernate will not work, and if I put it I cannot deploy the webservice...
Weblogic somehow keeps precompiled versions of EJBs even though you do a new/update deployment.
this works for me with wls 10.3.5:
within the server directory of your domain (e.g. in my case /home/myUser/apps/bea/domains/myDomain/servers/AdminServer) there is a subfolder "cache/EJBCompilerCache". Stop your weblogic instance and remove the contents of this subfolder. Restart weblogic and everything will work :-)
I'm not sure if this is the same bug, but there is a known bug in Weblogic 10.3.0-2 that causes a problem when using JaxWS with an EJB v 2.x. But I'm getting a near identical error when I put the #WebService annotation on an EJB v 3.0 on Weblogic 10.3.1. The error is loading what looks like the supposedly generated local stubs that Weblogic creates, and its happening on Weblogic 10.3.0, 10.3.1, 10.3.2, and 10.3.3. (yes, I really have them all deployed ;)
I had this problem deploying session bean and then trying to convert it to web service. WebLogic seems to cache session beans somehow.
There are several solution to this:
- Rename slsb.
- Comment #Stateless and #Remote annotations, deploy application, uncomment annotations, redeploy again.
- Bounce WebLogic.

Categories