Tomcat - Click on Web Service gets "The requested resource is not available" - java

I am newbie for Java web services and tomcat.
I didn't find a specific answer, so I am trying...
I have built a war to deploy on a tomcat 8.0.28 server on windows (and later on Solaris)
On the "Tomcat Web Application Manager" I can see my webapp listed among the applications list and I see that it's "running" status is "true". (see image)
Doesn't it mean that the service is up and running?
I have two problems, which probably relate:
When I click on the application link on the Tomcat Web Application Manager, it gives me 404 error. Is it logical? Why is that?
On the WAR project I have a main method, in which I create a file. I can't find it, so I assume, it was never called. I guess it relates to the previous matter...
My suspicion is that I didn't configure the address well somewhere. I will try to pass here all the data that I think is relevant:
The application path, as it is shown in the "Tomcat Web Application Manager" is /CcgwServerWsCxf.
The display name as it is shown in the "Tomcat Web Application Manager" is CcgwCallbackWsServerWAR.
The servlet part in web.xml is as follows:
<servlet>
<servlet-name>CcgwCallbackServlet</servlet-name>
<servlet-class>com.mycomp.ta.load.CcgwCallbackServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CcgwCallbackServlet</servlet-name>
<url-pattern>/CCGWCallback/*</url-pattern>
</servlet-mapping>
This is my code in the port server class constructor:
System.out.println("Starting Server");
Object implementor = new CCGWCallbackPortTypeImpl();
String address = "http://192.168.5.106:1234/CCGWCallback/CallbackServer";
Endpoint.publish(address, implementor);
(1234 is my tomcat port)
The service address that I send to the client so it can send my notification messages back is:
http://192.168.5.106:1234/CCGWCallback/CallbackServer
The Serivce QName is
new QName("http://teleconference.mycompany.com/CCGW", "CCGWService");
I hope that I gave all the data.
Can you please help?
Thank you.

The context path of your application is /CcgwServerWsCxf and your servlet is mapped to /CCGWCallback/* (relative to the context path).
Any request with path below /CcgwServerWsCx is routed to your application.
But only requests with a path below /CcgwServerWsCx/CCGWCallback hit your servlet.
Therefore Tomcat responds with a 404 when you call /CcgwServerWsCxf (e.g. the hyperlink in the manager app).
You should call /CcgwServerWsCx/CCGWCallback and verify that your servlet is invoked.
Also you need to make sure that any client also uses the correct paths. For instance the URL http://192.168.5.106:1234/CCGWCallback/CallbackServer should probably be http://192.168.5.106:1234/CcgwServerWsCx/CCGWCallback/CallbackServer given your current Tomcat config.

Related

Issue with rest end point in Weblogic server

I have created rest api with following url-pattern in web.xml file.
/service/*
Its working fine in tomcat server with URL http://localhost:9080/context/service/test
however, in the WebLogic server, its getting failed with the above URL. But when I am using the following URL, It's working fine.
http://localhost:9080/context/resources/test
I am not sure why given first given URL not working with the web-logic server.
Please suggest.
Thanks in Advance
In web logic by default context name is given as resources( you can check in WADL file in web logic console resource folder), however you may further overwrite if required.

Servlet Working fine on local Server, but Unable to Invoke Same Servlet on Real cpanel Live Server

I am working with the Java Web Application Where user Should Invoke a servlet with the Url like
(This works fine when i run my project on my local server, Login is a Java Class extends HttpServlet).
But When i upload my project to Live Server through FileZilla FTP client
i am unable to invoke the Servlet with the Url like
www.mydomain.com/myproj/Login(Server returning Error 404)
Please see my Images and please kindly help me..
Thank you in advance..
Project Structure
web.xml for Live Server
I found the mistake..
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/servlet/Login</url-pattern>
</servlet-mapping>
if i map my servlet as above it is working.. but the another problem i am facing is, i am unable to invoke a servlet if i dont use "servlet" in my url mapping.. which obviously tells to the user what technology i am using.. how can i use my servlet without mentioning servlet in url pattern

403 Forbidden Error on Tomcat 7 When using POST or PUT

I have an AngularJS front end that receives data from a Java web service. Both of these live on a Tomcat 7 server. My application performs GET operations correctly. However, when I am trying to save a new object or update an object, my POST and PUT operations return a 403 Forbidden error.
From searching around, I found that Tomcat has PUT disabled and that it has to be turned on. So I modified the web.xml file in the conf folder in the Tomcat directory and added the following code under the DefaultServlet:
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>
After this, the server was restarted. But I am still receiving the 403 error.
Please let me know what other information I can include to help find what I am doing wrong.
The answer to my issue was discovered this morning. This was not a tomcat configuration error. Rather it was an authentication issue. We use openam to authenticate on the servers and the PUT and POST options were not marked. Once those were checked, my web services worked correctly.

Can a tomcat hosted servlet break out of it's base URL?

I've just started writing some java servlets and running them with Tomcat (v7). My understanding of how the directory structure works is that URLs are relative to the name of your application:
So if my app is MyWebApp then by visiting http://server/MyWebApp I'll see, for example, the "index.jsp" file I created in the root directory of my web app.
If said index.jsp has a form with POSTs to "submit" then the broswer will send to http://server/MyWebApp/submit
And in my web.xml file I can point a class which extends HttpServlet to handle this POST request. Something like:
<servlet>
<servlet-name>MyHandler</servlet-name>
<servlet-class>org.me.handler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyHandler</servlet-name>
<url-pattern>/submit</url-pattern>
</servlet-mapping>
However, suppose my form POSTs to "/submit". Then the browser sends the request to http://server/submit
I don't see any way to intercept this from my web app.
One approach is just to deploy my web app as the ROOT. Is there another approach?
Each web application in servlet container has a context path. It can only receive requests below the context path. For good reasons there is no way to "break out" of its context path (except if the servlet container has a bug).
A servlet mapping is always to be seen as relative to the context path.
You can deploy web applications as root, i.e. with context path "/". See here how to do this for Tomcat.
When your pages contain URLs to the server (href-, src-, action-attributes, etc.) you basically have two options:
Use a relative URL. E.g. the form in your example could simply have action="submit" which is turned into an absolute URL by the browser.
Use absolute URLs. Since (if) you don't want that your application is dependent on a fixed content path, you therefore should (need) to dynamically generate your pages and prefix those URLs with the actual context path.

404 with response.sendRedirect

I am using spring security login mechanism for my application and tested everything.Things were working fine.I have the following use case
If customer is not logged in , application will redirect customer to the login page.
On successful login, application will redirect customer back to same page from where they were redirected to the login page
this is the Java code used to redirect user to his original location
final SavedRequest savedRequest = this.requestCache.getRequest(request, response);
targetUrl = savedRequest.getRedirectUrl();
getRedirectStrategy().sendRedirect(request, response, targetUrl);
RedirectionStrategy being used here is DefaultRedirectStrategy, things were working fine. Application is now deployed on the Pre Production server and now this seems not working and I am getting 404 error.
When customer is being redirected to the home page,targetUrl is coming out as "/", I have a Spring controller named with this mapping
#RequestMapping("/")
public class HomePageController{ // home page code }
my application's current Pre-Prod urs is prepd-www.mysite.com so when sendredirect come in to action, webpage URL is getting changed to prepd-www.mysite.com/prepd-www.mysite.com
I am not sure what is causing this issue. is it because of the proxy server settings ?
Can any one suggest me about the possible root cause of this issue?
I have already tried it on all local machines and well on our QA but everything is working perfectly fine.
Current setup for the environment where this is happening is
We have 4 app server
We have one load balancer which is redirecting traffic to one of the app server.
Just a wild guess since you could not give the reverse proxy configuration, nor the exact URL used in pre prod and in developpement.
You say you are using DefaultRedirectStrategy from Spring security. This strategy has an option (contextRelative) that prepends the ServletContext path to the URL. If in your developpement system you were using the root context, that is if you were accessing home page at (for example) : http://localhost:8080/ the serlet context was empty.
But if now in preprod, the servlet context is no longer root but is say /myApp once translated by apache reverse proxy, when you redirect you get an URL of /myApp/myApp that could be translated back to what you gave.
You could try to control whether you have contextRelative as true in DefaultRedirectStrategy and if yes if you can set if to false and also control if you redirect to absolute or relative URLs.
If you are using apache in front check rewrite rule and redirect rules of apache config. Best way would be to ssh tunnel directly to application server(by skipping apache) and test. If it's working that means your application config is fine and it needs to be fixed in apache.
Are you using in preproduction tomcat or another application server?, normally if your war is calling foo and your commit to tomcat, the path for this war is
http://localhost:8080/foo/
So if you are using servlet you need specify in your web.xml that the main path is foo/*

Categories