Java Web App in Eclipse with Spring Framework not recognizing edits to controller - eclipse

I was given an existing dashboard at work and am new to the whole Java Servlets with Spring Framework deal.
So the pages that are there work, and the flow is that there is the #RequestMapping annotation for the method inside the controller. For Example
#RequestMapping("/index.do")
public ModelAndView index() throws Exception {
LoginDO oLoginDO = new LoginDO();
return new ModelAndView("index","oLoginDO",oLoginDO);
}
The servlet.xml file maps the views to jsp files, and it's all working.
But my issue is, when I edit the controller.java file and create another method returning a new view, which is for a new page to the webpage, the change isn't being recognized by the servlet. It says "No matching handler method found for servlet request."
Now here's the thing, I believe this is happening because somehow the Spring Framework isn't being "updated" (don't know if this is the right term) when the edits are made in controller.java. I deployed my source code from a WAR file in Eclipse, then run it on a Tomcat server. Here's the deal, my mentor's code is working fine along with the edits, but I believe that he created a Tomcat project, and the project directories are different, and the edits are updated onto the website immediately after a save.
Note that when I change the JSPs to the existing pages, the updates are recognized immediately, it's only when I create a new JSP and a new #RequestMapping annotation along with a new method, it's not working. I even tried print statements within the controller.java and nothings showing.
So I guess this is an Eclipse question and deployment question more than anything, but any help would be great! Not too sure what to do to fix this. I've even tried restarting the server, to no success though. Thanks!

New #RequestMapping methods require the context to be reloaded (updated) to make them be available. When STS (Eclipse) detects changes on a spring bean it reloads the context automatically. If you are having problems with this try redeploying the project or restarting Tomcat.
Also, I wonder if you are you putting that new #RequestMapping method in a new Controller or in an existing one. If it's a new controller, have you added that Controller to the Spring Web Context (e.g. #Controller + component-scan or just adding the bean to de config file).

Related

SmartGWT DataSource adding QueryString to REST call

So, I have a Spring-MVC RESTful backend, that is cross-domain enabled. It is unit-tested, I can call my web-services and get back the correct JSON.
I have a SmartGWT 5.1p and GWT 2.7.0 front-end application that works great in SuperDev mode or Classic Dev Mode, either works great. When I do this, I am using the old Firefox 24 browser with the GWT plugin, and I can see my app work just great. My datasources are tied to RESTful web-services, and I can create, retrieve, update, and delete records via my DataSources.
I can compile the whole app via Maven, and get a WAR created just fine. I tried moving this WAR over to a tomcat server, and it deploys correctly. I can see the app running in tomcat with no errors in the logs.
Then when I go to the first page, the app comes up s normal with no errors. The first thing I do is add a username and password into a form, and then it is supposed to call a LoginDataSource which is tied into a LoginCOntroller, or login web-service.
What I can see from firebug is that when I make my call, rather than just calling:
http://mydomain:8080/admin/login/user/myusername/pwd/mypassword
I get:
http://mydomain:8080/admin/login/user/myusername/pwd/mypassword?0{and a whole lotta stuff after this) ... the query string I presume.
When I hit the Submit button, I get a SERVER TRANSPORT error, and that's it, I don't get any more information that that. There is nothing else to report from firebug except that the OPTIONS and GET add a whole lot of query string nonsense after the password.
I can look in the tomcat logs, and I don't see any errors in there at all. I don't even see the URL call to the web-service.
Any help on this would be much appreciated. I've been dealing with SmartGWT for years, and switched to back-end development for a while, and not I am trying to make my SmartGWT front-end work as well. But, I am a little rusty as to what is happening now.
Thanks!
The problem is not the querystring, it's the old base url I have in the datasource. There is a method in each datasource called: getServiceRoot
In getServiceRoot, I was using a hardcoded "localhost:8080", which in client code that doesn't work. That means whoever is running the app in their browser, "localhost" means their machine. So, I had to change the getServiceRoot to do the following:
protected String getServiceRoot()
{
String baseUrl = "http://" + Window.Location.getHostName();
return baseUrl + UrlConstants.SOME_URL_REST_ENDPOINT;
}
Since I have two WAR's on the same machine;
one WAR is a Spring MVC back-end RESTful web-services
the other WAR is the front-end, SmartGWT client application
This is a problem I run into ... I think just because both are on the same machine, that to the front-end, just call the code on the localhost, because it is there. But to the browser, that could be any other machine.
I suppose I could have just hard-coded the public IP address of the machine running tomcat, and then the client-side SmartGWT would then certainly find the RESTful web-services. Or, I could have used a Spring Env Profile to make that happen as well. But the code change I made should work, provided both WARS are on the same machine.
I just got to remember that client-side code in a browser is relevant to the machine the browser is running on.
So, this is fixed. If anyone needs any clarification, please let me know.

JBoss Seam cannot create Java Persistence Entity Manager

I am at a complete loss with this one. I am scouring the Internet via Google to try and find a solution for this problem. I haven't used JBoss in a very long time, and we use Seam version 2 ... not sure what exact version. I've never used Seam before, so I don't know anything about this framework. My boss wrote most of this code, but he has moved beyond looking at this code, and has tasked me to fix this problem.
So, the problem is ... A user is logged into our Seam app, everything is fine, but when we try to load users from a CSV file, it's as if Seam forgets who we are, and then we get an error.
We have a UserIdentity class starts off like:
#Name("org.jboss.seam.security.identity")
#Scope(ScopeType.SESSION)
#Install(precedence = Install.APPLICATION)
#BypassInterceptors
#Startup
public class UserIdentity extends Identity {
In this class, we have one line of code:
EntityManager entityManager = (EntityManager)Component.getInstance("entityManager",true);
That is returning null, and hence we get an NullPointerException (NPE).
I presume that "Component.getInstance" fails, and it would be nice if we could refresh this and get it back again. It would be great if I could update to a newer seam jar and fix this.
I will continue to scour the Internet for a fix, but in the meantime, if someone has seen this issue, and knows how to fix it, that would be great.
Thanks!
When you use Component.getInstance method is used to get a reference to a Seam session bean component.
True end your context and creates again. As it is not finding that context It is returning null.
As the EntityManager is used in Session Scope, You don't have to Create it again.
Simple you can inject entity manager as,
EntityManager entityManager = (EntityManager)Component.getInstance("entityManager");
or
#In
EntityManager entityManager;

How can I access one Eclipse RAP entry point from another?

I have an Eclipse RAP 2.3 application with two entry points, say /first and /second.
In the GUI of the first entry point, there is a button with which I would like to open the second entry point in a new browser tab. The event handler of that button is currently
UrlLauncher launcher = RWT.getClient().getService( UrlLauncher.class );
launcher.openURL( "/second");
This already doesn't work when the application is deployed as myapp.war in a Tomcat web server (should then be /myapp/second).
My questions:
What's the best way to determine the URL to open within the event handler?
Do I have to fetch the HttpServletRequest, get the context path and so some string manipulation?
Is it actually safe to call RWT.getRequest() at this point?
Update
According to RĂ¼diger's comment I can acquire the context path in two different ways.
The first approach is
RWT.getRequest().getContextPath();
where RWT.getRequest() is documented with
This method is not recommended
Secondly, I could obtain it with
ApplicationContextImpl ac = (ApplicationContextImpl) RWT.getApplicationContext();
String contextPath = ac.getServletContext().getContextPath();
where the IDE displays the warning
Discouraged access: The type ApplicationContextImpl is not accessible due to restriction on required library ...\org.eclipse.rap.rwt_2.3.2.20150128-1013.jar
Despite the warning, it still works when deploying a WAR file with OSGi bundles to Tomcat.
So, in both cases there is some kind of warning, which makes the solutions look rather like workarounds.
Using RWT.getRequest() is not recommended because usually RWT would shield you from the lower-level servlet API and certain direct interactions with the request could even interfere with RWTs life cycle and yield funny responses.
While in your case it would be safe to access the ServletContext via RWT.getRequest(), I recommend to use
RWT.getUISession( display ).getHttpSession().getServletContext();
to access the servlet context.
The second approach accesses internal classes that aren't part of the public API and therefore shouldn't be use. The accessed classes may change or be (re)moved in the future without further notice and break your application.

Overriding liferay login jsp using a hook

I'm trying to override a JSP in Liferay 6.1, namely html/portlet/login/login.jsp.
I have
created a hook (using Eclipse)
added <custom-jsp-dir>/custom_jsps</custom-jsp-dir> to liferay-hook.xml
created the abovementioned directory structure
copied login.jsp there and modified it
deployed the hook
(restarted the server, you never know...)
But i am not able to see the modified login page.Where i am doing wrong.I am very new to this liferay.I am getting very much confuse with this.Can any one tell me where i am doing wrong.
Implementing Hooks in Liferay-portal-6.0.5
The above links targets on creation of a hook for custom login page. Hope this helps..!!!

Vaadin + Eclipse Visual Editor NOT reloading/updating Composite components

I created a Vaadin Project, then wanted to create a Custom composite and display that as my main window (so i could take advantage of the Visual UI editor). Working with Tomcat Apache Server and the Visual Editor has been a pain! Nothing updates even when i start, stop or restart the server. My mainWindow application will display some Vaadin components and not others. Here is an example i have of my main window code
import com.vaadin.Application;
import com.vaadin.ui.*;
public class DApplication extends Application {
#Override
public void init() {
Window mainWindow = new Window("DApplication");
//Header header = new Header();
//header.setSizeFull();
DHome dHome = new DHome(); // **HERE IS THE COMPOSITE INSTANCE I CREATED IN ECLIPSE**
dHome.setSizeFull();
mainWindow.getContent().setSizeFull();
mainWindow.addComponent(dHome);
setMainWindow(mainWindow);
}
}
Is this a bug or a problem with others using these same tool for making vaadin applications. My application even if i shut off my machine wont update with newly components added to the composite?
When you open the URL for the application, it creates a new user session. The session is preserved even if you reload the page. However, if you use Eclipse, it likes to do hot deployment to Tomcat and you may experience a problem that the application does not return to its initial state after you modify code. As Tomcat likes to persist sessions on server shutdown, the application state can remain even if you restart the server.
Adding the ?restartApplication parameter in the URL tells the Vaadin servlet to create a new Application instance on loading the page. If you also include a URI fragment, the parameter should be given before the fragment.