Tomcat websocket echo app - java

I am fairly new to websockets and am pulling my hair out. I am using the echo app as a template. I have created a project in eclipse called echo and have placed the source for EchoAnnotation.java and EchoEndpoint.java (http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/) in the appropriate place.
I have also created an echo.xhtml file and placed it there as well (http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/echo.xhtml?view=log).
I had to find the web.xml here: Tomcat 8 Examples: Missing Configuration Step and am using this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_3_0.xsd"
version="3.0">
<welcome-file-list>
<welcome-file>echo.xhtml</welcome-file>
</welcome-file-list>
</web-app>
I run my ant build script to turn this into examples.war and deploy it to my tomcat 8 webaps directory. I hit this URL: http://localhost:8080/examples/echo.xhtml and the page comes up.
the problem is that as soon as I click connect, I get a message indicating the server closed the connection.
Did I miss a setup step?
Just found that someone else is having the exact same problem: How to make Tomcat 8 websocket example works?

the problem is that as soon as I click connect?
Where is your click button?

I went back to the download file for tomcat 8.05 and pulled the examples webapp out of the tarball and that is working fine. I'll just start playing with that.

Related

How to redirect application path in wildfly?

Excuse me, I'm new to this. I have developed an application with maven, and when I run the application in my wildfly it opens the following path: "127.0.0.1:8080/myapp-1.0.0" and everything runs perfect, but I simply want that:
x.x.x.x/ point to: x.x.x.x:8080/myapp-x.x.x
I do not know if it is a configuration in standalone.xml as it redirects or something more complicated.
If you only have a single web application, the simplest way is to have jboss-web.xml file in your web application. Put a file like:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="10.0"
xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd">
<context-root>/</context-root>
</jboss-web>
in your WEB-INF directory. This will make your application run at the / context. Note that this isn't redirection - it's permanently there. Additionally, if you have many webapps running on your Wildfly server they will all need a unique context root.

Websphere liberty profile error: 404 SRVE0190E

What could be the reason for the error: Error 404: SRVE0190E: File not found: /SimpleServletPath
I am deploying in websphere liberty profile server.
I can't reach my admin console login page
I can reach my welcome page on my websphere liberty profile server but can't do so after creating a servlet. That's when the above 404 error comes up.
There are similar posts online that advice to change com.ibm.ws.webcontainer.invokefilterscompatibility=true . I can't find how to set this parameter because I can't hit the websphere admin console login.
I installed websphere through eclipse marketplace.
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" 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_3_0.xsd">
<display-name>ServletExplore</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app
By default, your app's context root will default to the name of the application. You can change it (including setting it to /) by looking at the server on the Servers tab and editing its configuration. You can make changes in the GUI or directly in the server.xml.
If your app is called my app, I suspect localhost:9080/myapp/SimpleServletPath is where your servlet is currently living.
You are probably using annotation #WebServlet in your servlet, but you have web.xml file. Remove web.xml file from your project and run again.

What controls the first part of a Tomcat app's URL?

I'm upgrading an old web app (was Tomcat 5 and JSF 1). I'm pretty new to Tomcat.
URLs into the app are all like this: "http://localhost:8181/app/esp/..."
But, currently the only way I can get the request through to the app is to use a URL like this: "http://localhost:8181/esp/esp/...".
So, how and where do I need to configure this "/app"? (Bear in mind this was working fine in the previous version).
My current environment is Eclipse Kepler, Tomcat 7 and JSF 2. Tomcat starts fine from Eclipse and will display an html page with "Run as server", for example: "http://localhost:8181/esp/esp/logout.html"
But this page has a link to "http://localhost:8181/app/esp/main" which results in a message "HTTP Status 404 - /app/esp/main - The requested resource is not available." If I overwrite the "app" with "esp" the request is handled.
My web.xml (stripped down by now) is like this:
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
ESP
<servlet>
<display-name>ESPServlet</display-name>
<servlet-name>ESPServlet</servlet-name>
<servlet-class>ch.eds.esp.controller.ESPServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ESPServlet</servlet-name>
<url-pattern>/esp/main/*</url-pattern>
</servlet-mapping>
Server.xml defines a Context in a Host, like this:
<Host appBase="webapps" debug="0" name="localhost" unpackWARs="true">
<Context reloadable="true" path="/app" />
</Host>
So, to cut a long story short, a URL like this ".../esp/esp/mypage..." works, and a URL like this ".../app/esp/mypage..." doesn't. And the second form is the way it needs to work.
But why? And how?
Following David99World's suggestion below, I tried changing these things.
In Eclipse I changed the "Web Project Settings/Context Root" from "esp" to "app". This produced no change when trying to "run on server" from Eclipse.
I tried exporting a WAR file from my project (using "Export...) to either a esp.war or a app.war. Putting them into /webapps and clearing away the previous stuff and restarting Tomcat.
If I use esp.war, then the usual 404 happens.
If I use app.war, I have a folder structure /webapps/app/esp etc. And requesting "http://localhost:8181/app/esp/main" seems to give an interesting result. It first redirects to "http://localhost:8181/app/esp/login.jsp" which then results in an exception "bean exceptionHeaderBean not found within scope".
So, some good progress (I'll go find that bean).
But how to get the same result from inside Eclipse?
I don't want to keep exporting a war to do each little incremental test.
Ah! You need to modify the Context Root (as noted above) - and then you need to (on the servers tab of Eclipse) "publish to server". Just stopping and starting are not enough.
Change the war file name that builds from app to esp, the first location after localhost:8080 is the deployed war application.

Spring template MVC project fail to run out of box, STS2.8.1 on linux 64bit

Unable to run spring template project on STS. Where to check it?
There is a spring template with STS. But, it failed on an old STS, and failed on a freshly installed STS-2.8.1, nothing changed but give a project name and top package to start the project.
No mapping found for HTTP request with URI [/you/home.htm] in DispatcherServlet with name 'appServlet'
And it seems all configured in web.xml, and servlet-context.xml :
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Can we believe the contextConfigLocation setting must be ok? Why it can not get the handler?
The correct url for the Home controller is <server>/<applicationName>/ (not `.../home.html").
So for example it the Projects name is "test" and you use a Tomcat, then the urls is: http://localhost:8080/test/
And I fond a second problem, but I can not reproduce it
I have tryed the "Spring MVC Template" my own and get stucked with exaxtly the same output.
I was reading the code and configuration again and again, and did not find any mistake, because there is no.
After I modified the HomeController
public HomeController() {
logger.info("init home");
}
It starts suddenly working! -- So I think it was a Eclipse referesh Problem. (Just try to clean and republish the project)
You may try this:
First stop the server if it is running.
Expand src Tree and
Select src/main/webapp
Right click it
From Popup Menu select Build Path
Select 'Use As Source Folder' option
Now try to run the project again

Why is creating Servlets in Eclipse breaking my web.xml?

Being somewhat lazy, I was rather happy to find that I could create a new servlet source code by going New -> Servlet, instead of going New -> Class and then editing the class into a servlet.
However, I have discovered that every time I create a new servlet in Eclipse, Eclipse modifies my web.xml.
Specifically, it modifies the top element to:
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
id="WebApp_ID" version="2.4">
(Linebreaks mine.)
This doesn't seem necessarily bad, but then it modifies various sub-elements by putting "javaee:" in front of their name, to indicate that these elements belong in that namespace.
For example, it changes
<display-name>ShowLifecycles</display-name>
to
<javaee:display-name>ShowLifecycles</javaee:display-name>
After which eclipse then complains about all the elements it modified, giving me notations like:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'javaee:display-name'. One of '{"http://
java.sun.com/xml/ns/j2ee":description, "http://java.sun.com/xml/ns/j2ee":display-name, "http://java.sun.com/xml/ns/
j2ee":icon, "http://java.sun.com/xml/ns/j2ee":distributable, "http://java.sun.com/xml/ns/j2ee":context-param, "http://
java.sun.com/xml/ns/j2ee":filter, "http://java.sun.com/xml/ns/j2ee":filter-mapping, "http://java.sun.com/xml/ns/
j2ee":listener, "http://java.sun.com/xml/ns/j2ee":servlet, "http://java.sun.com/xml/ns/j2ee":servlet-mapping, "http://
java.sun.com/xml/ns/j2ee":session-config, "http://java.sun.com/xml/ns/j2ee":mime-mapping, "http://java.sun.com/xml/ns/
j2ee":welcome-file-list, "http://java.sun.com/xml/ns/j2ee":error-page, "http://java.sun.com/xml/ns/j2ee":jsp-config, "http://
java.sun.com/xml/ns/j2ee":security-constraint, "http://java.sun.com/xml/ns/j2ee":login-config, "http://java.sun.com/xml/ns/
j2ee":security-role, "http://java.sun.com/xml/ns/j2ee":env-entry, "http://java.sun.com/xml/ns/j2ee":ejb-ref, "http://
java.sun.com/xml/ns/j2ee":ejb-local-ref, "http://java.sun.com/xml/ns/j2ee":service-ref, "http://java.sun.com/xml/ns/
j2ee":resource-ref, "http://java.sun.com/xml/ns/j2ee":resource-env-ref, "http://java.sun.com/xml/ns/j2ee":message-
destination-ref, "http://java.sun.com/xml/ns/j2ee":message-destination, "http://java.sun.com/xml/ns/j2ee":locale-
encoding-mapping-list}' is expected.
To make matters worse, when I use find and replace to delete all to "javaee:" which litters the file, Eclipse still complains about these even though they are no longer there. I must copy and paste the entire remaining file on top of itself to make these complaints go away.
I am sure Eclipse is trying to be useful, anticipating some desire or need for this namespace. How can I do either one of two things:
Make it stop doing this?
Take advantage of whatever it is trying to do, and make it work for me instead of against me?
I have never seen this before, but this indicates that your Eclipse project is really messed up. At least the web.xml root declaration makes no utter sense. It look like a mix of Servlet 2.4 and 2.5 specifications. Maybe Eclipse is getting confused because the root namespace (xmlns) is pointing to the Servlet 2.4 one (with j2ee URI) while the web project itself is set as Servlet 2.5 or newer (which should be using the one with javaee URI).
Also, when your web project is set to Servlet 3.0 during creation, by default no web.xml will be generated by Eclipse because of the new Servlet 3.0 annotations like #WebServlet, #WebFilter, etc.. which makes the web.xml superfluous. When you create new servlets by New > Servlet, Eclipse will already autogenerate those annotations. Probably you've attempted to create the web.xml yourself based on misinformation.
I'd suggest to backup some code if necessary, throw the whole project away and create a new one with the proper settings and do not touch the web.xml root declaration.
Assuming that you're using the latest Eclipse version, Helios SR1 for Java EE developers, rightclick Eclipse's Project Explorer, choose New > Dynamic Web Project and just fill the project name and keep everything default. Click Next until the last step and then tick Generate web.xml deployment descriptor checkbox to let Eclipse generate one. The root declaration should then look like this:
<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_3_0.xsd"
id="WebApp_ID" version="3.0">
I was having a similar issue. I brought a web app over from an old Tomcat 6/Java 6 to Tomcat 7/Java 7. I copy and pasted existing web.xml body into the new 3.0 web.xml. Everything was fine until I added a servlet that had init-param, display-name, description and load-on-startup paramters. Eclipse flagged these params as broken with an "invalid content found at...". Thanks to stackoverflow, I found that load-on-startup had to come after init-params but only a RTFM for how they knew. My other params were still flagged as broken. This is what the web.xml header looked like when it was broken:
<?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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
I changed the dtds to ns/j2ee and web-app_2_5.xsd, and Ecliupse stopped complaining. But its 2014 and we'll be moving to Tomcat 8 soon. So I dug in hard and found the docs for . In web-app 3.0 the parameters have to be in this order:
jee:descriptionGroup = any combo of 3 params: description, display-name, icon
servlet-name
chose 1: servlet-class or jsp-file
n number of init-params
load-on-startup
options: enabled, asynch-supported, run-as, security-role-ref, multipart-config
Once I put my params in order, Eclipse was happy with ns/javaee and web-app_3_0.xsd.
Move "display-name" as the first element under "servlet" tag, the validation error should go away.
Make sure the web.xml file starts with the tag followed by the tag
<?xml version="1.0" encoding="UTF-8"?>
In my case I had DOCTYPE tag and removing the DOCTYPE tag from the web.xml cleared me this error,
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >

Categories

Resources