View http request when using mvn jetty:run [duplicate] - java

This question already has answers here:
Enable debug logging in maven jetty 7 plugin
(5 answers)
Closed 7 years ago.
Now, I run the simple example of Motown (Link Single application setup)
First, I check out code and install jar. After that, I run "mvn jetty:run". The application starts OK.
I want to review http request sending from browser into application but the console does not have this information. How can I view the http request?
Thanks

One option is to use tcpmon - it is very simple tool, you just change port in the browser sending requests to tcpmon and tcpmon will send the requests to your application but also will print it. The same with responses. (https://code.google.com/p/tcpmon/)

Related

Java Spring MVC WebSocket application works on local application server only but not on openshift host

I tried to make a simple websocket chat, also using Spring MVC.
Source code is available in my repository here on GitHub
It consists of following parts:
Welcome view page index.jsp contains form for user's nickname and password entering and binding it to new User instance.
User instance is passed to the Spring MVC controller MainController.java. Controller creates new ModelAndView linked to the chat.jsp and passes the User instance to it for user's nickname displaying in the header and in the chat window. chat.jsp contains js code providing connection to websocket endpoint in Chat.java. And it also passes user's nikname to the endpoint to store it in its String field.
When I try it on my local Tomcat 8 everything works fine, just as expected.
This is request and response of websocket endpoint connection.
But when I try it on OpenShift's Tomcat 7 remote host it doesn't work.
Here are the screenshots:
As you can see user's nickname was not displayed in header and was not passed to the endpoint with request URL.
It seems that even the User instance has not been passed from the Spring MVC controller to the chat.jsp view page.
Can somebody please explain me what I'm doing wrong?
I see two problems there:
Ws and wss ports - use ports 8000 or 8443 for web socket connection on OpenShift. I recommend amending your chat.jsp:
Chat.initialize = function () {
if (window.location.protocol == 'http:') {
Chat.connect('ws://' + window.location.host + ':8000/websocket/chat/${user.nickname}');
} else {
Chat.connect('wss://' + window.location.host + ':8443/websocket/chat/${user.nickname}');
}
};
The Tomcat server version. You can use this quick-start to run Tomcat 8 on OpenShift Online. However, when I tried using the quick-start, I faced some trouble so I changed a few things and created a PR; before it's merged you can take a version that worked for me from here. In order to deploy Tomcat 8 on a small DIY gear, you can use this command: rhc app create tomcat8 diy --from-code https://github.com/jiri-fiala/openshift-tomcat8-quickstart. Replace tomcat8 with the name you want for your app. Note that it will take a few minutes to download and compile Tomcat 8.
With the Tomcat 8 running on OpenShift, I deployed your code as ROOT.war (I've created a package locally using mvn package), using Tomcat's web interface. The testing chat app seems to be just fine.
Of course, this is not quite an ideal deployment; the web app is deployed to the data directory this way. OpenShift Online presently does not offer a Tomcat 8 cartridge where you could push your code into the repo and have your web app built and deployed automatically.
One problem has been solved. Now user nickname is displayed in the view header and it is also passed to websocket endpoint with connection request.
I just added one line <%# page isELIgnored="false" %> to chat.jsp to make Expression Language work. For some reason it is necessary if you use Tomacat 7.
So now after adding the port numbers to websocket endpoint connection request I have got this:
But the chat still doesn't work properly, as connection has been closed right after its establishment.

Tomcat 5.5: The requested resource is not available [duplicate]

This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 6 years ago.
I'm having some trouble getting my web app to launch on my server. The URL is:
http://www.apollowebworks.com/kmsales/ItemSearch.do
It used to work fine, and still runs on my local build using Eclipse. I noticed it wasn't working anymore sometime after my hosting provider informed me that they were migrating to a new server.
This is the error I'm getting:
HTTP Status 404 - /kmsales/ItemSearch.do
type Status report
message /kmsales/ItemSearch.do
description The requested resource is not available.
Apache Tomcat/7.0.42
I find it suspicious that it's posting "Apache Tomcat/7.0.42". My host has Tomcat 5.5. I am running it on a 5.5 build locally. I was initially running it on a higher build, and I'm thinking maybe some of my xml files or jars might still reference the wrong Tomcat somehow. I can't find that anywhere though. Any idea where else to look?
The libraries I'm using are:
javacsv.jar
jstl.jar
mysql-connector-java-5.1.15-bin.jar
standard.jar
You said "migrating to a new server". This is most likely why you see there Tomcat 7. I think you need to check with your provider to see what exactly they migrated. Maybe your app wasn't copied to the new Tomcat. In any case you really need to see if your app is there where it should be and, if it is, check the log files.

how to detect whether request is coming from browser or smartphone? [duplicate]

This question already has answers here:
Detecting Device Type in a web application
(8 answers)
Closed 9 years ago.
I am having a web application , which works fine .
now there is a particular page which gets bulky when i access the application from smartphone browser , so I wanted a situation like
if(request comes from computer browser client )
forward to bulky page in web application
else
if (request comes from smartphone )
forward to some other light page .
please put your suggestion how can i achieve this
Use the user-agent. Every connection to your server carries this header, by convenience and convention. There is no guarantee that a browser will be truthful(such as a spambot reporting itself as Chrome). You can get the user-agent as follows:
request.getHeader("User-Agent");
and then check again known user-agent strings and templates.
It's generally done by checking "User-Agent" header of Request

how to send HTTP request to a servlet [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to send HTTP request in java?
I only have one servlet running on the Tomcat server side. Now I want to send a HTTP request to this servlet from a Swing application, and it's not an APPLET application (because I see some examples sending request from applet). How can I do this?
While you can open a direct socket connection and send the raw HTTP headers & content and receive a response back, I would urge you to take a look at HttpRequestBase.

how to solve error http status 404 in servlet jsp [duplicate]

This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 6 years ago.
I am trying to run some basic servlet and jsp program with Tomcat. but it gives some error.
I am using Tomcat 6.0.29 and jdk 1.6.0_21.
When i click on WebAppl link in Tomcat then it gives below error
HTTP Status 404 - /WebAppl/
type Status report
message /WebAppl/
description The requested resource (/WebAppl/) is not available.
I tried another code which was running properly on Tomcat 5.5.9. But still gives same error here.
HTTP Status 404 - /SampleAppl/
type Status report
message /SampleAppl/
description The requested resource (/SampleAppl/) is not available.
What should I do to solve this error?
Is it because of new version of Tomcat? Can anyone guide me.
Either you are not using the right URL to access the web application, or you had an error when deploying. Have a look at the Tomcat server logs to see if there is anything in there.
Also the management console might help you getting the URL right.
It looks like your web applications are not deployed. Check carefully the log files of the booting of your tomcat. It will indicate when it starts deploying your webapps and why they failed.
The stacktraces stick out like a sore thumb and following the Up, or looking in down for 'Caused By' lines usually gives a reason why they do not deploy.
If you are stumped you may want to post some parts to this site to ask for guidance.
Your project hierarchy is the one that needs to be checked
project-
src-
servlet
webcontent-
web-inf-
web.xml
index.jsp
Your url will be http://localhost:8080/project
You say you are using tomcat. In that case check the $tomcat/webapps directory. There should be a WebAppl and a SampleAppl directory (and/or war) in there.
Als check the $tomcat/logs directory and read catalina.out (the logfile). Check for Exceptions and the text deployed. You would expect that it says that application WebAppl is deployed.
Of course,you do have to connect to your tomcat. Tomcat is usually listening in port 8080 (check $tomcat/conf/servlet.xml). It could be that you are connecting to another application at port 80 (the http default, usually Apache or IIS).
If it is in port 8080, your URL should look like: http://localhost:8080/WebAppl
Might be
1)Don't violate folder creation structure hierarchy and place corresponding files
2)web applications are not deployed
3)right URL to access the web application
4)Container not yet started(because check out the port numbers that may clash with earlier configured setups )
It could be due to missing tld files in WEB-INF directory which are being used, inside JSP, example JSTL Core.
<c:out value="${salary}"/>

Categories