Web.xml not compiling correctly - java

I recently tried to convert an Eclipse, Google Appengine Project from java7-java8 since GAE has stopped supporting java7 (or will do in the near future).
The project was working fine before starting the conversion. I am now getting this error when trying to run the project locally:
java.lang.IllegalStateException: Multiple servlets map to path: /api/add-batch-shelfsurvey: ApiShelfSurveyBatchServlet,com.imobdev.figjam.ApiShelfSurveyBatchServlet
This is the entry in web.xml for that servlet:
<servlet>
<servlet-name>ApiShelfSurveyBatchServlet</servlet-name>
<servlet-class>com.imobdev.figjam.ApiShelfSurveyBatchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ApiShelfSurveyBatchServlet</servlet-name>
<url-pattern>/api/add-batch-shelfsurvey</url-pattern>
</servlet-mapping>
This is the start of the web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
I've double and triple checked /api/add-batch-shelfsurvey path is unique in web.xml but I still get this error.
The servlet mentioned in the error message changes but none of them have multiple mappings to one path.
I've found these threads that seem similar but aren't actually related:
https://github.com/dropwizard/dropwizard/issues/2107
https://bugs.eclipse.org/bugs/show_bug.cgi?id=479865
I don't know if it's relevant but this is my appengine-web.xml file:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<threadsafe>true</threadsafe>
<url-stream-handler>urlfetch</url-stream-handler>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
<property name="appengine.file.encoding" value="US-ASCII"/>
</system-properties>
<sessions-enabled>true</sessions-enabled>
<runtime>java8</runtime>
</appengine-web-app>

It is because the path
/api/add-batch-shelfsurvey
might have been registered before try to check all
<servlet-mapping>
sections in web.xml and if you have any
#WebServlet annotations then check urlPatterns={"..."}
If you have two definitions at the same time app server will not know which is the right one.

I've managed to get the project to run on the localhost and upload and run on Google App Engine. Unfortunately I don't know exactly what the problem was.
These are the steps I took:
-Removed the /* from all in web.xml file.
-Changed between version 2.5 xsd and 3.1 xsd several times, running the project on localhost each time.
-Changed back to 2.5 xsd and changed all back to ending in /*
Project then compiled and ran fine on both localhost and appengine. If anyone knows anything more about why this might happen please let me know.

Related

JasperException: Absolute uri cannot be resolved

I have been getting the following JasperException when trying to use an XML schema for my web.xml, instead of the deprecated DOCTYPE declaration:
HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core
cannot be resolved in either web.xml or the jar files deployed with this
application
If I use this web.xml, the application compiles:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
However, if I use this web.xml, I get the JasperException:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>CourseManagementJDBC</display-name>\
</web-app>
Any idea why only a deprecated format would work?
NOTE: This is for a Maven project, and the JSTL dependency has been correctly declared, as well as the tag library in the JSP:
pom.xml:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
JSP:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
They're all correct; what gives?
I finally came upon the solution. By default, for some reason (and I'd like to know why), Maven generates a Dynamic Web Module as version 2.3. DTD was of course the standard for Servlet 2.3 and was probably unable to parse or evaluate my XML-based web.xml file.
I'm still not 100% clear as to why changing web.xml to XSD caused the JasperException with respect to JSTL, though I think it has something to do with JSTL being integrated with JSP at some point after Servlet 2.3 - someone please correct or elaborate on this if possible.
See this: https://stackoverflow.com/a/4928309/2879303
Now for the solution:
Right-click on your Maven project and select Properties
Navigate to Project Facets and untick Dynamic Web Module. Apply
changes.
From the version drop-down box, select the latest version (as of
writing, this is 3.1). Re-select Dynamic Web Module. Apply changes.
Right-click on your Maven project and select Maven -> Update
Project.
Your project should now be able to correctly interpret a web.xml
with an XSD declaration.

JNDI name not found - how to use JNDI in WCM workflow plugin?

I'm using Rational Application Developer 8.5 to develop a custom workflow action plugin for IBM Web Content Manager (WCM) in WebSphere Portal 7.0.
The plugin needs to get a JDBC data source with JNDI, but all my attempts to do so produce this error:
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
A data source named "jdbc/wcmbulletins" is defined in the WebSphere Application Server.
Here's the java code to get the data source:
javax.naming.InitialContext ctx=new javax.naming.InitialContext();
javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/wcmbulletins");
The RAD project contains the following XML files only. There's no "persistence.xml" or any other files I've seen mentioned in similar SO questions.
There are also some JSP files referenced by WCM JSP components. The JSP files have no connection with the plugin and don't use JNDI or JDBC.
ibm-web-bnd.xml:
<web-bnd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
version="1.0">
<virtual-host name="default_host"/>
<resource-ref name="jdbc/wcmbulletins" binding-name="jdbc/wcmbulletins"/>
</web-bnd>
ibm-web-ext.xml:
<web-ext
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">
<jsp-attribute name="reloadEnabled" value="false"/>
<jsp-attribute name="reloadInterval" value="10"/>
<reload-interval value="3"/>
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="true"/>
</web-ext>
plugin.xml:
<plugin id="com.company.wcm.CompanyWCMPlugins"
name="Company WCM Plugins"
version="1.0.0"
provider-name="Company Name Australia">
<extension
point="com.ibm.workplace.wcm.api.CustomWorkflowActionFactory"
id="CompanyWorkflowActionFactory">
<provider class="com.company.wcm.workflow.CompanyWorkflowActionFactory"/>
</extension>
</plugin>
web.xml:
<web-app id="WebApp_ID" version="2.5"
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/web-app_2_5.xsd">
<display-name>CompanyWCM_JSPs</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>
<resource-ref id="ResourceRef_1377568155870">
<description/>
<res-ref-name>jdbc/wcmbulletins</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
What do I need to make the JNDI lookup work?
What happens if you change the code to bypass the resource reference and use the name jdbc/wcmbulletins instead?
Also - at what scope is the DS defined? If at cluster level try the name cell/persistent/jdbc/wcmbulletins and see what you get.
Lastly - there is always the WebSphere naming trace. You can enable them via Naming=all, re-run your app, and check trace.log for insight as to what might be going on.
Hope this helps,
ScottH
From my experience, wcm plugins are somewhat independent from the web-application they are contained in (they are more related to OSGI or so). For example during server startup plugins are instantiated, before the web-application itself is, so it might not even be possible to reliably lookup resources from the web-app.

issues deploying a JAVA application to weblogic 11g

I have a simple JSP/Servlets application. The app is already deployed to the server and is running at say URL http://www.servername:7001/myapp1/jsp/login.jsp. I have made some substantial changes to the code and I redeployed it as myapp2 in the server. However if I try to access it at this URL,,say http://www.servername:7001/myapp2/jsp/login.jsp, this gives me a "resource not found error". Is the URL mapped to the application somewhere? What do I need to do to access the newly deployed project. I do not want to remove the old project till I am sure the new one works properly
You probably need to specify a context root. There are a couple of places this might appear.
1) Inside your EAR file in META-INF/application.xml, e.g.:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
id="Application_ID" version="5">
<display-name>myapp2</display-name>
<module>
<web>
<web-uri>myapp2.war</web-uri>
<context-root>/myapp2</context-root>
</web>
</module>
</application>
2) In the WAR file, in WEB-INF/weblogic.xml, e.g.:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-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 http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<wls:weblogic-version>10.3.2</wls:weblogic-version>
<wls:context-root>myapp2</wls:context-root>
</wls:weblogic-web-app>

Why, when working with Web Fragments to I get a "Premature End of File" error

I created 2 maven projects, a web application fxserver2 and a web library SleepyFox.
I then created a src/main/resources/META-INF/web-fragment.xml file in SleepyFox that I'd like to be automatically "included" into my fxserver web.xml
Unfortunately, I'm getting an error that looks like this:
24-Jan-2012 19:38:50 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor fxserver2.xml from /Users/sparkyspider/Tomcat/apache-tomcat-7.0.12/conf/Catalina/localhost
24-Jan-2012 19:38:50 org.apache.tomcat.util.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 1 column 1: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
and then
24-Jan-2012 19:38:50 org.apache.catalina.startup.ContextConfig parseWebXml
SEVERE: Parse error in application web.xml file at jndi:/localhost/fxserver2/WEB-INF/lib/SleepyFox-0.9.jar!/META-INF/web-fragment.xml
org.xml.sax.SAXParseException: Premature end of file.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
The second error seems to indicate that the correct file is indeed being read, but I have no idea why its giving me a premature end of file error.
I included my fxserver2 web.xml
<?xml version="1.0"?>
<web-app>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
And also my SleepyFox web-fragment.xml
<web-fragment>
<listener>
<listener-class>com.foxbomb.fxserver2.ApplicationContext</listener-class>
</listener>
</web-fragment>
Any advice greatly appreciated.
I think you need to mention the web-app_3_0.xsd schema in your main web.xml which also loads web-common_3_0.xsd automatically. This common schema has elements like session-config>
<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_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
The first error makes it look like /Users/sparkyspider/Tomcat/apache-tomcat-7.0.12/conf/Catalina/localhost/fxserver2.xml either can't be found or is empty. (The "line 1 column 1" bit is what makes me think it's empty.) Make sure that file is present, has content, and has appropriate access rights so that it can be read.

Duplicate fragment name ERROR Jetty Maven Plugin

I run the jetty-maven-plugin 8.0.0M2. Works fine after startup (mvn jetty:run) . If I change a source the plugin tries to hot deploy but gets stuck because of the following error
Duplicate fragment name: PrimeFaces for jar:file:/C:/path/to/project/webroot/WEB-INF/lib/primefaces-2.1.jar!/META-INF/web-fragment.xml and jar:file:/C:/path/to/project/webroot/WEB-INF/lib/primefaces-2.1.jar!/META-INF/web-fragment.xml
It worked fine with plugin version 7.2.0. I was upgrading because I needed el-api 2.2.
Any ideas? Thanks
Marcel
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
...
<webAppConfig>
...
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
...
</webAppConfig>
...
</configuration>
</plugin>
I think we should fight the cause instead of hiding the problem. I.e. avoid duplicate fragments. In my case fragments with the same name came from different versions of Spring, so to solve the issue I had to manage my project's dependencies properly. Analyze by the error message where are the duplicates and think whether you really need both of them or is it a dependency conflict.
If you tried Stephen Connolly's fix and you are still are having issues, you may just need to modify a your web.xml slightly to get "allowDuplicateFragmentNames" to work.
In your WEB-INF/web.xml, look for the tag (should be at the top), and modify atributes to match these values:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true"
..
>
<web-app version="3.0" 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/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" metadata-complete="true">
reference : http://forum.broadleafcommerce.org/viewtopic.php?f=13&t=2145
I had a hard time getting rid of the error. My mistake was that I used two different configuration tags with the same meaning:
<webApp>...</webApp> which I had already in my configuration and then copying <webAppConfig>...</webAppConfig> from the solution above. As I finally found out, webAppConfig is an alias for webApp. After getting rid of the alias and moving all configuration into the <webApp> section the error disappeared.
It looks to me as if one uses both, then the only the content from one section is used and the other one is ignored or reset.

Categories

Resources