Shared bean between portlets in separate war files - java

I'm developing a 'user settings portlet' where users can effect the search behaviour of multiple other portlets. The way I'd like to do it is by a shared bean. All portlets are in different wars, and I'd rather avoid having all wars in a single ear and using a parent application context, so deployment of portlets can be made autonomously, but haven't had much luck in finding any information on how to do it.
I have followed this blog post to try to deploy an ear file with the wars in them, but after many hours of wrestling I've come no closer to solving my problem...
The directory structure looks like this:
portlets
|--- ear
| \--- src/main/application/META-INF/application.xml
|
|--- jar (contains UserSettings.java)
| \--- src/main/resources/beanRefContext.xml
| \--- src/main/resources/services-context.xml
| \--- src/main/java/com/foo/application/UserSettings.java
|
|--- messagehistory (war, portlet 1)
| \--- [...]
|
|--- settings (war, portlet 2)
| \--- [...]
|
\--- pom.xml
I've tried setting scope="session" like the following:
<bean id="userSettings" class="com.foo.application.UserSettings" scope="session">
<aop:scoped-proxy />
</bean>
But then when I deploy the ear I get java.lang.IllegalStateException: No Scope registered for scope 'session'.
This is the controller för the history portlet, where users can search for message history, with restrictions from the settings portlet. The controller for the settings portlet is identical.
package com.foo;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletSession;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import com.foo.application.UserSettings;
import javax.annotation.PostConstruct;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.ServletContextAware;
#Controller
#SessionAttributes({"searchQuery", "searchResults"})
#RequestMapping("VIEW")
public class ViewHistory extends ContextLoader implements ServletContextAware {
private UserSettings userSettings;
private ServletContext servletContext;
#Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
#PostConstruct
public void init() {
ApplicationContext ctx = loadParentContext(servletContext);
servletContext.setAttribute(LOCATOR_FACTORY_KEY_PARAM, "ear.context");
userSettings = (UserSettings) ctx.getBean("userSettings");
}
#ModelAttribute("userSettings")
public UserSettings createUserSettings(Model model) {
model.addAttribute(userSettings);
}
#RequestMapping
public String doSearch(Model model, PortletSession portletSession) {
return "view";
}
#ActionMapping(params = "action=search")
public void searchAction(
Model model,
ActionRequest request, ActionResponse response,
BindingResult bindingResult, SessionStatus status)
{
// do nothing
}
}
The web.xml file for both wars (they are identical) looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>parentContextKey</param-name>
<param-value>ear.context</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<filter>
<filter-name>springFilter</filter-name>
<filter-class>
org.springframework.web.filter.RequestContextFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>springFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Turns out it was really easy just using Spring's #EventMapping annotation for plain JSR 286 eventing. No ear required and no parent application context. I just have my UserSettings.java in a separate jar project and include it as a dependency to both wars.
The controller for the search portlet looks like this:
package com.foo;
import com.foo.event.UserSettings;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.EventRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import javax.portlet.Event;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.portlet.bind.annotation.EventMapping;
#Controller
#RequestMapping("VIEW")
public class ViewHistory {
private UserSettings userSettings = new UserSettings();
#ModelAttribute("userSettings")
public UserSettings createUserSettings(Model model) {
return userSettings;
}
#RequestMapping
public String doSearch(Model model) {
return "view";
}
#ActionMapping(params = "action=search")
public void searchAction(
Model model,
ActionRequest request, ActionResponse response,
#ModelAttribute("userSettings") UserSettings userSettings,
BindingResult bindingResult, SessionStatus status)
{
// do something
}
/**
* Spring calls this whenever an event is received.
* Can be limited to certain event.
*/
#EventMapping
public void handleEvent(EventRequest request) {
Event event = request.getEvent();
if (event.getName().equals("UserSettings")) {
userSettings = (UserSettings)event.getValue();
}
}
}
...and for the settings portlet:
package com.foo;
import com.foo.event.UserSettings;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import javax.xml.namespace.QName;
import org.springframework.web.bind.annotation.ModelAttribute;
#Controller
#RequestMapping("VIEW")
public class ViewSettings {
private QName qname = new QName("http:foo.com/usersettings", "UserSettings");
#ModelAttribute
public UserSettings createUserSettings(Model model) {
return new UserSettings();
}
#ActionMapping(params = "action=search")
public void searchAction(
Model model,
ActionRequest request, ActionResponse response,
#ModelAttribute("userSettings") UserSettings userSettings,
BindingResult bindingResult, SessionStatus status)
{
// as soon as an action is triggered (save button is pressed or
// whatever), send the modified UserSettings instance as an
// event to the search portlet (actually any portlet, but I
// only have one that will read events).
response.setEvent(qname, userSettings);
}
#RequestMapping
public String doView(Model model) {
return "view";
}
}

Related

Unable to test restful service

I am very new to Restful Services and I followed some guidelines given be the boss to make it. When I am using the URL to test it via browser, it shows not found. Console is not showing any error or exception (However, I removed almost 100 errors to reach this point), but still the result is same.
This is my directory structure
This is my RDRresource.java (Includes the service I want to test)
package org.uclab.IMP.rs.rdr;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.uclab.IMP.*;
import com.google.gson.Gson;
import org.uclab.IMP.datamodel.*;
import org.uclab.IMP.datamodel.RDR.*;
import org.uclab.IMP.datamodel.RDR.dataadapter.*;
/**
* Facade for the Restful Web service to handle the data curation functions
*/
#Path("rdr")
public class RDRresource {
#Context
private UriInfo context;
/**
* Creates a new instance of DataCurationResource
*/
public RDRresource() {
}
private static final Logger logger = LoggerFactory.getLogger(RDRresource.class);
/**
* This function is using to get user by ID
* #param UserID
* #return a list of object Users with "Error", "No Error" and new added ID
*/
#GET
#Produces("application/json")
#Consumes("application/json")
#Path("RetriveRules")
public List<Rules> RetriveRules() {
Rules objOuterRules = new Rules();
List<Rules> objListRules = new ArrayList<Rules>();
try
{
objOuterRules.setRuleID(Long.parseLong("RuleID"));
DataAccessInterface objDAInterface = new RuleDataAdapter();
AbstractDataBridge objADBridge = new DatabaseStorage(objDAInterface);
objListRules = objADBridge.RetriveRules();
logger.info("Get all rules successfully, rules Details="+objOuterRules);
}
catch(Exception ex)
{
logger.info("Error in getting user");
}
return objListRules;
}
This is my web.xml file
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.uclab.IMP.rs.rdr</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/webresources/*</url-pattern>
</servlet-mapping>
</web-app>
URL I am trying and result is here

There are no servelet mappings specified in web.xml for controller servelet

Hi I am trying to run my controller java but I am getting error of There are no servelet mappings specified in web.xml for controller servelet
I just wanted to ask how can to do servelet mapping I will really appreciate any advice thank you
here is my controller code
package com.kb.model;
import com.kb.model.tbl_batch;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.faces.bean.ManagedBean;
#ManagedBean
public class Controller extends HttpServlet {
static final long serialVersionUID = 1L;
#Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpSession httpSession = request.getSession();
tbl_dao dao = new tbl_dao();
ArrayList<tbl_batch> list = dao.getData();
httpSession.setAttribute("studentDetails", list);
RequestDispatcher dispatcher = request
.getRequestDispatcher("500kusers_hibernate.jsp");
dispatcher.forward(request, response);
}
}
this my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com
/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Pager Tag</display-name>
<welcome-file-list>
<welcome-file>500kusers_hibernate.jsp</welcome-file>
</welcome-file-list>
<servlet>
<display-name>Controller</display-name>
<servlet-name>Controller</servlet-name>
<servlet-class>
com.kb.model.Controller
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/Controller</url-pattern>
</servlet-mapping>

Cannot make Jersey 2.x hook the CORS filter

I need to enable the CORS headers on jersey server side because otherwise the Angualr frontend is getting:
XMLHttpRequest cannot load http://localhost:8080/api/products.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:9000' is therefore not allowed access.
As Jersey documentation explained I set up the filter and made it discoverable using web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 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">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>ny.devtest.endtoend.config.ApplicationConfig</param-value>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-name>ny.devtest.endtoend</param-name>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>
</web-app>
The filter interceptior implementation:
package ny.devtest.endtoend;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
#Provider
public class ResponseCorsFilter implements ContainerResponseFilter {
public ResponseCorsFilter() {
System.out.println("ServerResponseFilter initialization");
}
#Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
containerResponseContext.getHeaders().add("X-Powered-By", "Jersey :-)");
containerResponseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
containerResponseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
}
}
It is not working.
UPDATE:
package ny.devtest.endtoend.config;
import ny.devtest.endtoend.api.OrderResource;
import org.eclipse.persistence.jaxb.BeanValidationMode;
import org.eclipse.persistence.jaxb.MarshallerProperties;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.moxy.json.MoxyJsonConfig;
import org.glassfish.jersey.moxy.json.MoxyJsonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.server.validation.ValidationConfig;
import org.glassfish.jersey.server.validation.internal.InjectingConstraintValidatorFactory;
import javax.validation.ParameterNameProvider;
import javax.validation.Validation;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.ContextResolver;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
public class ApplicationConfig extends ResourceConfig {
private void ApplicationInit(){
// Resources.
packages(OrderResource.class.getPackage().getName());
// Validation.
property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true);
// Providers - JSON.
register(JacksonFeature.class);
register(MoxyJsonFeature.class);
register(new MoxyJsonConfig().setFormattedOutput(true)
.property(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE)
.resolver());
}
public ApplicationConfig() {
ApplicationInit();
// Bindings (#Inject)
register(new ApplicationBinder());
}
public ApplicationConfig(AbstractBinder customBinder) {
ApplicationInit();
register(customBinder);
}
#Override // << NOT WORKING
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
containerResponseContext.getHeaders().add("X-Powered-By", "Jersey :-)");
containerResponseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
containerResponseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
}
}
Let's try it:
package ny.devtest.endtoend.config;
import org.glassfish.jersey.server.ResourceConfig;
import ...
public class ApplicationConfig extends ResourceConfig {
private void ApplicationInit(){
// Resources.
packages(OrderResource.class.getPackage().getName());
// Register CORS filter.
register(ny.devtest.endtoend.ResponseCorsFilter.class);
// Register the rest you need
...
}
public ApplicationConfig() {
ApplicationInit();
// Bindings (#Inject)
register(new ApplicationBinder());
}
...
}
And configure in web.xml like that
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>ny.devtest.endtoend.config.ApplicationConfig</param-value>
</init-param>
<!-- Add parameter for CORS filter -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
ny.devtest.endtoend
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>
There are a few options to configure this
The way you are trying to do (in the web.xml). With this, you are 1) specifying the wrong init-param name. It should be jersey.config.server.provider.classnames and 2) You need to specify the (fully qualified) name of the filter class as the init-param value, not the package.
You have a java configuration class (ApplicationConfig), so you can just register the filter there
If you are using package (or classpath) scanning it should automatically pick up the filter and register it, because of the #Provider annotation.
For help with 2 or 3, please show your ApplicationConfig class. I'm not sure if you are directly subclassing Application or ResourceConfig. They are different in how they are configured.

Cannot Upload a file using Jax-RS

I want to use jersey framework. I´m running a web Service, using an ant app, on Java EE7. My application server is Glassfish
My method look like this:
package mypackage.service;
...
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
#POST
#Path("createSomething")
#Consumes(MULTIPART_FORM_DATA)
#Produces(APPLICATION_XML)
public Response createSomething(#FormDataParam("upload") InputStream is, #FormDataParam("upload") FormDataContentDisposition formData, #QueryParam("some") String some, #Context HttpServletRequest request) {
String fileLocation = "C:\\UploadFile\\" + formData.getFileName();
//more things, do not matter
try {
ctrl.saveFile(is, fileLocation);
String result = "Successfully File Uploaded on the path " + fileLocation;
return Response.status(Response.Status.OK).entity(result).build();
} catch (IOException e) {
e.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
I also have an application config:
package mypackage.service;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
#javax.ws.rs.ApplicationPath("")
public class ApplicationConfig extends Application {
#Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> resources = new HashSet<>();
addRestResourceClasses(resources);
resources.add(MultiPartFeature.class);
return resources;
}
/**
* Do not modify addRestResourceClasses() method. It is automatically
* populated with all resources defined in the project. If required, comment
* out calling this method in getClasses().
*/
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(mypackage.service.MYSERVICE.class);
}
}
On myweb.xml I have:
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>mypackage.service.ApplicationConfig</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>mypackage.service</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/createSomething/*</url-pattern>
</servlet-mapping>
I still get the same message:
Caused by: org.apache.catalina.LifecycleException: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response
What I´m doing wrong??
It works fine for me. Though I would completely get rid of the Application subclass. It is not needed, and may cause conflict/confusion. Your xml is sufficient configuration, just get rid of the javax.ws.rs.Application <init-param>. I would also look into making the multipart jars only compile-time jars (meaning not built into the war - they might conflict with Glassfish's version). I don't work much with Ant, so I'm not sure how you can do that, but I know it's possible.
Below code worked for me:
Class ->>> add it
Class Property --->> add it
Public Class userREST () {
#POST
#Path("upload")
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Produces(MediaType.APPLICATION_JSON)
public Response uploadImageFile(#FormDataParam("uploadFile") InputStream fileInputStream,
#FormDataParam("uploadFile") FormDataContentDisposition fileFormDataContentDisposition,
#FormDataParam("FIR_REG_NUM") String FIR_REG_NUM, #FormDataParam("LOGIN_ID") String LOGIN_ID) {
final_json_result = WriteFileInFolder.fileAnalysis(fileInputStream, fileFormDataContentDisposition, FIR_REG_NUM,
LOGIN_ID);
return Response.ok(final_json_result).build();
}// uploadImageFile
package ####.jaxrs.jwt;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import ####.helper.Common###;
import ####.jaxrs.jwt.filters.JWTRequestFilter;
import ####.jaxrs.jwt.filters.JWTResponseFilter;
import ####.service.FileServicesREST;
#ApplicationPath("fileservice")
public class FileJAXRSConfig extends Application {
#Override
public Set<Class<?>> getClasses() {
Common###.logging("#ApplicationPath#FileServicesREST...");
Set<Class<?>> clazzes = new HashSet<Class<?>>();
clazzes.add(JWTRequestFilter.class);
clazzes.add(FileServicesREST.class);
clazzes.add(JWTResponseFilter.class);
return clazzes;
}
#Override
public Map<String, Object> getProperties() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("jersey.config.server.provider.packages", "####.service");
properties.put("jersey.config.server.provider.classnames", "org.glassfish.jersey.media.multipart.MultiPartFeature");
return properties;
}
}
Don't need to add following in web.xml
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>mha.###.service</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>

gwt remote procedure call error

I am new to GWT and I have no result from my web application.
when I tried debugging, I got an error like "source not found"
and here is the code written in all the project
<---------------------------------------------------------------------------------------->
EntryPoint Class
package body.test.combo.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class Combo implements EntryPoint {
private final FileReaderServiceAsync serviceAsync = GWT
.create(FileReaderService.class);
String content;
/**
* This is the entry point method.
*/
public void onModuleLoad() {
VerticalPanel vPanel = new VerticalPanel();
serviceAsync.readMyFilePlease(new AsyncCallback<String>() {
#Override
public void onSuccess(String result) {
content = result;
}
#Override
public void onFailure(Throwable caught) {
System.out.println("Tezak");
}
});
Label lb = new Label(content);
vPanel.add(lb);
RootPanel.get().add(vPanel);
}
}
<---------------------------------------------------------------------------------------->
Service Interface
package body.test.combo.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
#RemoteServiceRelativePath("readmeplease")
public interface FileReaderService extends RemoteService {
String readMyFilePlease();
}
<---------------------------------------------------------------------------------------->
Service Async
package body.test.combo.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface FileReaderServiceAsync {
void readMyFilePlease(AsyncCallback<String> callbackVariable);
}
<---------------------------------------------------------------------------------------->
Server Implementation class
package body.test.combo.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import body.test.combo.client.FileReaderService;
public class FileReaderServiceImplementation extends RemoteServiceServlet implements FileReaderService {
#Override
public String readMyFilePlease() {
String allContent = "ezayak yad ya sayed";
return allContent;
}
}
<---------------------------------------------------------------------------------------->
Web.xml
<?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>readMyFilePlease</servlet-name>
<servlet-class>body.test.combo.server.FileReaderServiceImplementation</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>readMyFilePlease</servlet-name>
<url-pattern>/combo/readmeplease</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Combo.html</welcome-file>
</welcome-file-list>
</web-app>
Project name is 'combo'.
Does your project xml file (Combo.gwt.xml) contain the following:
<module rename-to='combo'>
You may also want to try some of the suggestions from this post.
it would be very useful for you to post that project xml file as well as the error itself.

Categories