I'm trying to publish a simple java web service using tomcat. Referring to below screenshot, I have HelloWorld.java which is service interface and its HelloWorldImpl.java implementation class.
Also I've created web.xml and sun-jaxws.xml.
When I right click the project, select Run As and then Run on Server, I get 404 error message as shown in bottom of screenshot.
The URL which internal browser tries to reach is http://localhost:8081/MySqlConnect/ where MySqlConnect is project name. Note that I'm using 8081 as port number.
I also tried http://localhost:8081/HelloWorld/hello, but it didn't worked.
I have also provided the code for all files below.
I'm not able to understand where am I going wrong? Any help appreciated.
HelloWorldImpl.java
package com.mycompany.service;
import javax.jws.WebService;
#WebService(endpointInterface = "com.mycompany.service.HelloWorld", serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {
#Override
public String sayGreeting(String name) {
return "Greeting " + name + "!";
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
sun-jaxws.xml
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint name="HelloWorld" implementation="com.mycompany.service.HelloWorldImpl"
url-pattern="/hello" />
</endpoints>
Edit 1
Log-cat
INFO: Starting Servlet Engine: Apache Tomcat/7.0.33
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.NoClassDefFoundError: javax/xml/ws/soap/AddressingFeature$Responses
java.lang.NoClassDefFoundError: javax/xml/ws/soap/AddressingFeature$Responses
Caused by: java.lang.ClassNotFoundException: javax.xml.ws.soap.AddressingFeature$Responses
Edit 2
As suggested here, I downloaded all libraries and place in tomcat lib folder but now I get this error in log:
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.NoSuchMethodError: com.sun.xml.ws.assembler.TubelineAssemblyController: method <init>()V not found
java.lang.NoSuchMethodError: com.sun.xml.ws.assembler.TubelineAssemblyController: method <init>()V not found
If I add all libraries to project and then try to run it, I get following error:
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: com.sun.xml.ws.util.ServiceConfigurationError: com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator: Provider com.sun.xml.ws.transport.tcp.policy.TCPTransportFeatureConfigurator is specified in jar:file:/C:/Apache-Tomcat-7/lib/webservices-rt-2.1-b16.jar!/META-INF/services/com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfiguratorbut could not be instantiated: java.lang.ClassCastException
com.sun.xml.ws.util.ServiceConfigurationError: com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator: Provider com.sun.xml.ws.transport.tcp.policy.TCPTransportFeatureConfigurator is specified in jar:file:/C:/Apache-Tomcat-7/lib/webservices-rt-2.1-b16.jar!/META-INF/services/com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfiguratorbut could not be instantiated: java.lang.ClassCastException
Note this: com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfiguratorbut could not be instantiated: java.lang.ClassCastException
The correct url is http://localhost:8081/MySqlConnect/hello as MySqlConnect is the name of your context and hello the web service url.
Also its a webservice so to access it properly you can make a SOAP call.
But the root cause is your web application is not starting due to unable to find class javax.xml.ws.soap.AddressingFeature$Responses.
Have you added right dependencies? Search in those dependencies if this class exists. Response is a inner class of AddressingFeature.
Related
We have a Java SOAP service running on Wildlfy & Java 8 currently. We are migrating from Wildfly 10 to 26, java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64
Running into all kinds of issues.
Below is my web.xml
<display-name>SearchWS</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- <listener><listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class></listener> -->
<servlet>
<servlet-name>SolrSearchWS</servlet-name>
<servlet-class>com.solr.service.SolrSearchWS</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SolrSearchWS</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
when i try to deploy my web service, i get the following in my log file
2022-12-07 11:30:06,133 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."SearchWS-0.0.1-SNAPSHOT.war".undertow-deployment.UndertowDeploymentInfoService: org.jboss.msc.service.StartException in service jboss.deployment.unit."SearchWS-0.0.1-SNAPSHOT.war".undertow-deployment.UndertowDeploymentInfoService: Failed to start serviceorg.jboss.msc#1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1731)org.jboss.msc#1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
org.jboss.threads#2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1363)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.IllegalArgumentException: UT010009: Servlet SolrSearchWS of type class com.solr.service.SolrSearchWS does not implement javax.servlet.Servletio.undertow.servlet#2.2.19.Final//io.undertow.servlet.api.ServletInfo.(ServletInfo.java:98)
org.wildfly.extension.undertow#26.1.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.createServletConfig(UndertowDeploymentInfoService.java:749)
org.wildfly.extension.undertow#26.1.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.start(UndertowDeploymentInfoService.java:312)
org.jboss.msc#1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
org.jboss.msc#1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
... 6 more
2022-12-07 11:30:06,141 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."SearchWS-0.0.1-SNAPSHOT.war".undertow-deployment.UndertowDeploymentInfoService" => "Failed to start service
Caused by: java.lang.IllegalArgumentException: UT010009: Servlet SolrSearchWS of type class com.solr.service.SolrSearchWS does not implement javax.servlet.Servlet"}}
Any help will be greatly appreciated.
regards
preet
We have tried many different combinations of files in POM. Nothing seems to help
I am trying to create a web service in a web application on netbeans 8.2 (server-tomcat 8.0.27.0) which can connect to a database on postgres and read a table named "test". i have this code in download.java (web service in a package called serve)
Download.java
#WebService(serviceName = "download")
public class Download {
Connection con=null;
private DataSource getJdbcPostgres() throws NamingException, SQLException {
Context c = new InitialContext();
DataSource ds=(DataSource) c.lookup("java:comp/env/jdbc/postgres");
con=ds.getConnection();
return ds;
}
#WebMethod(operationName = "download")
public String download(#WebParam(name = "username")String username, #WebParam(name = "id")String id) throws ClassNotFoundException, SQLException {
String sql = "select * from test where id="+id;
Class.forName("org.postgresql.Driver");
PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
ResultSetMetaData rsmd=rs.getMetaData();
rs.next();
return "";
}
}
here's my context.xml file (in META-INF)
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/service2">
<Resource name="jdbc/postgres" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/postgres"
username="someusername" password="somepassword" maxTotal="20" maxIdle="10"
maxWaitMillis="-1"/>
</Context>
and here's web.xml (in WEB-INF):
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>download</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>download</servlet-name>
<url-pattern>/download</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
clean and build command is successful but it doesn't deploy on apache tomcat server
error message (output when I tried to deploy it):
Checking data source definitions for missing JDBC drivers...
Undeploying ...
undeploy?path=/service2
OK - Undeployed application at context path /service2
In-place deployment at D:\NetBeansProjects\service2\build\web
Deployment is in progress...
deploy?config=file%3A%2FC%3A%2FUsers%2FTRAINE%7E3%2FAppData%2FLocal%2FTemp%2Fcontext1366288511044657094.xml&path=/service2
FAIL - Deployed application at context path /service2 but context failed to start
D:\NetBeansProjects\service2\nbproject\build-impl.xml:1094: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 2 seconds)
when i tried to change server to GlassFish 4.1.1, it says:
Severe: WSSERVLET11: failed to parse runtime descriptor:
com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator
serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
Caused by: com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator
serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
Severe: Exception while loading the app
Severe: Undeployment failed for context /service2
Severe: Exception while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.apache.catalina.LifecycleException: javax.servlet.ServletException:
com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to
parse runtime descriptor: com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
I am a newcomer to this field so plz help me if im wrong somewhere or missing something!
I don't know why it happened but I just put try-catch instead of throws and it is getting deployed!
#WebMethod(operationName = "download")
public String download(#WebParam(name = "username")String username, #WebParam(name = "id")String id) {
try {
String sql="select * from test";
Connection conn=myDatasource.getConnection();
PreparedStatement pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
}
catch (SQLException ex) {
Logger.getLogger(connect.class.getName()).log(Level.SEVERE, null, ex);
}
return "someString";
}
Can anyone suggest why didn't it work earlier? Although my problem is solved yet I'm curious to know what was wrong with 'throws Exception'!
P.S. I'm running it on GlassFish 4.1.1 this time
I am learning GWT by following their StockWatcher tutorial. After trying a few things on my own, I got this exception on a servlet:
Feb 28, 2013 7:55:00 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: jetty-6.1.x
Feb 28, 2013 7:55:00 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: EXCEPTION
java.lang.ClassNotFoundException: com.google.gwt.sc2.server.GreetingServiceImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:213)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
This is the web.xml file where I am configuring the servlet:
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.google.gwt.sc2.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/bikeapp/greet</url-pattern>
</servlet-mapping>
I think I'm missing something really basic, but I don't know what. Can anyone help please?
I assume you are using eclipse so please check the setting of Default output folder. it should be inside WEB-INF/classes while compile project.
I encountered the same problem. The reason was that i created project using GPE (Google Plugin for Eclipse) and tried to follow GWT in action book. But my version of GPE creating a lot of staff insted of just basic project infrastructure. So, if you change your web.xml to
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
</web-app>
everything should work fine.
Did a lot of search, but no luck.
I'm trying to make a 'hello world' app which integrates Jersey and Google App Engine.
In Eclipse, I created a 'Web Application Project' and added Jersey JAR to the build path.
Then I modified web.xml and it looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.example.myJersey</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
In the package 'com.example.myJersey' I have HelloWorldResource.java, here is an excerpt:
// The Java class will be hosted at the URI path "/helloworld"
#Path("/helloworld")
public class HelloWorldResource {
// The Java method will process HTTP GET requests
#GET
// The Java method will produce content identified by the MIME Media
// type "text/plain"
#Produces("text/plain")
public String getClichedMessage() {
// Return some cliched textual content
return "Hello World";
}
}
When I click run, I get this error:
INFO: Successfully processed C:\Users\upelsin\wtf-rest\war\WEB-INF/web.xml
фев 02, 2012 5:05:16 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: failed Jersey Web Application: java.lang.IncompatibleClassChangeError: Implementing class
фев 02, 2012 5:05:16 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: failed com.google.appengine.tools.development.DevAppEngineWebAppContext#1aa58969{/,C:\Users\upelsin\wtf-rest\war}: java.lang.IncompatibleClassChangeError: Implementing class
фев 02, 2012 5:05:16 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: failed JettyContainerService$ApiProxyHandler#6d26b88a: java.lang.IncompatibleClassChangeError: Implementing class
фев 02, 2012 5:05:16 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Error starting handlers
java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
at com.sun.jersey.api.core.servlet.WebAppResourceConfig.init(WebAppResourceConfig.java:102)
at com.sun.jersey.api.core.servlet.WebAppResourceConfig.<init>(WebAppResourceConfig.java:89)
at com.sun.jersey.api.core.servlet.WebAppResourceConfig.<init>(WebAppResourceConfig.java:74)
at com.sun.jersey.spi.container.servlet.WebComponent.getWebAppResourceConfig(WebComponent.java:672)
at com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:414)
at com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:581)
at com.sun.jersey.spi.container.servlet.WebServletConfig.getDefaultResourceConfig(WebServletConfig.java:87)
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:703)
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
EDIT:
Maybe there is a misconfiguration in web.xml. Looks like Jetty doesn't like Jersey's servlet class.
I would appreciate any kind of help.
I recently put together a project template on GitHub combining Jersey and Guice for AppEngine. It may help to compare with a running app.
Jersey requires Java 1.6. Is this what the Google App Engine runs on? Maybe your Google App instance is configured to run on an earlier Java version.
Look at this:
http://code.google.com/p/googleappengine/wiki/WillItPlayInJava
Make sure that you run Jersey 1.5 and configure as required in the doc. Also, are you using other libraries? Those may create a classloading conflict?
Trying to set up a new spring project and im having this issue where I get this error (HTTP Status 404 - Servlet newspring is not available) when I navigate to a page that I expect to get routed through to a controller.
web.xml
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
So I looked in the tomcat logs and I see this exception:
SEVERE: Error loading
WebappClassLoader delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader#a1807c
org.springframework.web.servlet.DispatcherServlet
java.lang.ClassNotFoundException:
org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149)
but the supposedly missing class is actually present in the spring-webmvc.jar which is present in the WEB-INF/libs(at tomcatfolder/webapp/newSpring/WEB-INF/libs).
Is it unable to look here ?
Assuming I read correctly, the folder should be /WEB-INF/lib, not /WEB-INF/libs - note the lack of s at the end!