Reputation: 508
I have some problems with my gwt project, i use eclipselink and hsqldb as database.
Here is my code: Project.java:
package com.example.client;
public class Project implements EntryPoint {
private final EmployeeServiceAsync eService = (EmployeeServiceAsync) GWT.create(EmployeeService.class);
[...] some GWT code
@Override
public void onModuleLoad() {
eService.createemployee(new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Fail!");
}
@Override
public void onSuccess(Void result) {
//nothing
}
});
but it fail every time with this warning:
WARNING: No file found for: /project/employeeService
So how i can call this method properly?
EmployeeService.java
package com.example.client.service;
@RemoteServiceRelativePath("employeeService")
public interface EmployeeService extends RemoteService{
public void createemployee();
}
EmployeeServiceAsync.java
package com.example.client.service;
public interface EmployeeServiceAsync {
void createemployee(AsyncCallback<Void> callback);
}
EmployeeServiceImpl
package com.example.server.ServiceImpl;
public class EmployeeServiceImpl extends RemoteServiceServlet implements EmployeeService {
private static final long serialVersionUID = 1L;
public void createemployee() {
javax.persistence.EntityManagerFactory emf = Persistence.createEntityManagerFactory("ronfPU");
javax.persistence.EntityManager em = emf.createEntityManager();
try {
// Create new Employee
em.getTransaction().begin();
Employee e1 = new Employee();
e1.setName("admin");
e1.setSurname("admin");
e1.setUsername("admin");
e1.setPassword("admin");
em.persist(a1);
em.getTransaction().commit();
} finally {
em.close();
}
}
}
Employee class is stored in com.example.shared.entity; I think that persistence.xml and project.gwt.xml are ok, but i'm not sure about web.xml code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>employeeServiceImpl</servlet-name>
<servlet-class>
com.example.server.ServiceImpl.EmployeeServiceImpl
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>employeeServiceImpl</servlet-name>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Project.html</welcome-file>
<url-pattern>/com.example.client.Project/employeeService</url-pattern>
</welcome-file-list>
</web-app>
First should be, if I understand correctly, derives from @RemoteServiceRelativePath("employeeService")
;
while <servlet-class>
derives from the class stored in the server-side wich extends RemoteServiceServlet; <servlet-mapping>
should be the same of <servlet-name>
, and here, in <url-pattern>
, i'm not sure about what i wrote.
How you suggest to run properly this code? Thank you in advance!
Upvotes: 0
Views: 523
Reputation: 64541
When generating the code for your client-side service-async stub, it takes the value of the @RemoteServiceRelativePath
annotation and prefixes it with the GWT.getModuleBaseURL()
(this is explained in the javadoc for RemoteServiceRelativePath
).
GWT.getModuleBaseURL()
is the "folder" where your nocache.js
file is located. In a standard setup, this depends directly on the name of your module (project.gwt.xml
and the package you put it in) or a rename-to
argument you have in it. According to the error message, it's http://…/project/
in your case (your nocache.js
is at project/project.nocache.js
).
You have to adjust the <url-pattern>
in your web.xml file to match that URL, so it should be /project/employeeService
in your case.
Put simply: with @RemoteServiceRelativePath
you configure which URL the client code will call, and with <url-pattern>
you configure at which URL your service "listens at"; and you have to make them match in order to make them talk to each other.
Upvotes: 1