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.
Related
We have a Java Web application running in IBM Websphere Liberty profile server. We have recently developed a Java Servlet which is responsible to generate JFreeCharts using Java library.
Code in web.xml
<servlet>
<servlet-name>GraphicServlet</servlet-name>
<servlet-class>com.test.GraphicServlet</servlet-class>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>GraphicServlet</servlet-name>
<url-pattern>*.img</url-pattern>
</servlet-mapping>
Code in index.html file
<img src="summary/chart.img" height="100" width="100" />
Code in GraphicsServlet.java
This Servlet has doGet method implemented and the business logic in the method generates a chart image file(.png) using JFreeCharts and this image is returned as response in form of stream.
Application flow:
When application is accessed, index.html file is displayed by default and this page has a section where chart generated by JFreeChart needs to be displayed.
Scenario Description:
The Image file is not getting displayed when application is accessed. Using the browser's developer tools, I have found that 404 error is printed when a request is sent to *.img Url. Next, I tried to find out if that Servlet is really deployed on to the server or missed in the .war file by any chance, and I checked the deployment folder in websphere and found the Servlet deployed. Next, I tried to check if Servlet is up and running. From a new browser, I sent a test request like http://localhost:9080/myapp/summary/chart.img, it returned 404 error on to the screen.
I wanted to know why servlet is not getting up. So, I implemented the init() method of HttpServlet in my GraphicsServlet and written a print statement. I didnot get that print when the application finished loading. Finally, I tried with commenting out every line of doGet method, even then I received
404 Error on the screen.
Problem Description: I want to know why the GraphicsServlet is not getting up. Please let me know if there are any techniques to know the reason behind the failure of GraphicServlet.
Update 1:
I tried removing the configuration in web.xml and annotated the GraphicServlet with #WebServlet annotation. Now, I am able to see those print statements and it is now confirmed that GraphicServlet is up and running when annotation is used. So, I started looking at web.xml DOCTYPE tag. The version of Web app DTD was very old. It was 2.3 version, and the Java version we installed is 1.8. Can anyone here let me know whats the problem with WebApp-2.3 ?
Update 2:
I removed the #WebServlet annotation from GraphicServlet and again I tried with xml configuration and also changing the Web-app version from 2.3 to 3.1 (also 3.0) in web.xml file. The GraphicServlet is still not up and running.
Update 3:
I have noticed that javaee-7.0 feature is being used in the Websphere server.xml file.
Thanks for your patience.
Maybe you should change your servlet mapping in web.xml to be like this:
/summary/*.img
Problem 1: Angular 2 application deployed on JBOSS server but not able to load static content (js/css). The problem is the website is hosted under its own context (localhost:8080/sample/) and static resources is refered in index.html as (link href="css/index.css" rel="stylesheet") however it doesnt get loaded as network calls are made to localhost:8080/css/index.css.
I need it to point to localhost:8080/sample/css/index.css
Problem 2: Alternately we tried hosting angular application on tomcat but services need to be hosted on jboss, we tried implementing CROS filter (https://amodernstory.com/2014/12/27/using-cors-headers-with-java-example/) but the first request goes through but other request shows pending status in Chrome network's tab.
I'm having the same problem. To get it to load the static content, you need to set the base href inside index.html to "./". I have found that "." also works. The application should then load properly, BUT you will run into another problem: if you try to visit any of the application routes directly using the address bar, you will see "Not Found". This seems to be related to JBoss's ability to rewrite HTML5 URLs and redirect them to the index. I am trying to solve that problem using the information on this page: https://issues.jboss.org/browse/JDF-512. I will let you know if I succeed.
You can create an index.prod.html with the correct references to "/sample/css/index.css". Then add the following in the angular.json
"production": {
"fileReplacements": [
{
"replace": "src/index.html",
"with": "src/index.prod.html"
}
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.
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/*
I'm working on java project, which is using weblogic 10 as an application server. In this project there are around 11 servlets added in web.xml descriptor with url mapping. Whenever i'm adding new servlet, its not getting mapped to the url as wel as not getting invoked. What may be the problem. As, if I add the same logic in any of the existing servlet, its working fine.
Thanks in advance.
How is the question in the title of your post going to help you solve this problem?
Maybe you have another servlet that maps to the same URL pattern, or you have ambiguous URL patterns for your new servlet and already existing servlets (so that WebLogic doesn't know which one to call). Check the servlet mappings in your web.xml file.
Check the WebLogic management console to see if your servlet is deployed successfully, and check the logs of WebLogic for any deployment errors. Carefully read the error messages to find out what's wrong. If you don't understand them, add them to your post above, so that someone here can explain you what they mean.
If you go to an URL that's supposed to map to your servlet, then what do you get? An error message, or is it going to another servlet? If it's an error, then again, post the error message.