Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » download service servlet error on Tomcat 8
download service servlet error on Tomcat 8 [message #1803482] Fri, 01 March 2019 13:03 Go to next message
Hsuan-Ming Chen is currently offline Hsuan-Ming ChenFriend
Messages: 2
Registered: February 2019
Junior Member
Recently, I have made an Eclipse RAP program using javax servlet package to create a File Download service. It works pretty well when using the built-in server inside the Eclipse IDE. However, after deploying the program on the Tomcat server, while opening the download link, the error message shows HTTP 500 error as following:

Type: Exception Report

Message: Servlet execution threw an exception Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception: javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Root Cause: java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "javax/servlet/http/HttpServletResponse" testproject.DownloadServiceHandler.service(DownloadServiceHandler.java:59) org.eclipse.rap.rwt.engine.RWTServlet.handleValidRequest(RWTServlet.java:135) org.eclipse.rap.rwt.engine.RWTServlet.handleRequest(RWTServlet.java:117) org.eclipse.rap.rwt.engine.RWTServlet.doGet(RWTServlet.java:100) javax.servlet.http.HttpServlet.service(HttpServlet.java:635) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.eclipse.rap.rwt.osgi.internal.CutOffContextPathWrapper.service(CutOffContextPathWrapper.java:106) org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl$LegacyServlet.service(HttpServiceRuntimeImpl.java:1240) org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:151) org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:65) org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:134) org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet.service(ProxyServlet.java:103) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.eclipse.equinox.servletbridge.BridgeServlet.service(BridgeServlet.java:158) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


Following is my code and related file:

BasicApplication.java
package testproject;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.rap.rwt.application.Application;
import org.eclipse.rap.rwt.application.ApplicationConfiguration;
import org.eclipse.rap.rwt.client.WebClient;

public class BasicApplication implements ApplicationConfiguration {

    public void configure(Application application) {
        Map<String, String> properties = new HashMap<String, String>();
        properties.put(WebClient.PAGE_TITLE, "Test Project");
        application.addEntryPoint("/", BasicEntryPoint.class, properties);
    }

}


BasicEntryPoint.java
public class BasicEntryPoint extends AbstractEntryPoint {

    @Override
    protected void createContents(Composite parent) {
        parent.setLayout(new GridLayout(2, false));

        Button downloadButton = new Button(parent, SWT.PUSH);
        downloadButton.setText("Download");
        downloadButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              try {
                    File testfile = new File("/home/user/Desktop/test.file");
                    byte[] fileContent = Files.readAllBytes(testfile.toPath());
                    sendDownload(fileContent, testfile.getName());
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
              }
            });
      }

    public boolean sendDownload(byte[] data, String filename) {
        DownloadServiceHandler service = new DownloadServiceHandler(data, filename);
        service.register();
        UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
        launcher.openURL(service.getURL());
        return true;
    }

}


DownloadServiceHandler.java
public class DownloadServiceHandler implements ServiceHandler {

    private final byte[] data;
    private final String filename;
    private String id;

    public DownloadServiceHandler(byte[] data, String filename) {
        this.data = data;
        this.filename = filename;
        this.id = calculateId();
    }

    public String getURL() {
        return RWT.getServiceManager().getServiceHandlerUrl(getId());
    }

    private String getId() {
        return id;
    }

    private String calculateId() {
        return String.valueOf(System.currentTimeMillis()) + data.length;
    }

    public boolean register() {
        try {
            RWT.getServiceManager().registerServiceHandler(getId(), this);
            return true;
        } catch (Exception e) {
            System.out.println("failed to register download service handler");
            return false;
        }
    }

    private boolean unregister() {
        try {
            RWT.getServiceManager().unregisterServiceHandler(getId());
            return true;
        } catch (Exception e) {
            System.out.println("failed to unregister download service handler");
            return false;
        }
    }

    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        try {
            response.setContentType("application/octet-stream"); // this is the error line "DownloadServiceHandler.java:59"
            response.setContentLength(data.length);
            response.setHeader("Content-Disposition", "attachment; filename=\"" + filename
                    + "\"");
            response.getOutputStream().write(data);
        } catch (Exception e) {
            System.out.println("failed to dispatch download");
        } finally {
            unregister();
        }
    }

}


META-INF/MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Testproject
Bundle-SymbolicName: testproject
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: testproject
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.rap.rwt;bundle-version="[3.0.0,4.0.0)"
Service-Component: OSGI-INF/contribution.xml
Import-Package: javax.servlet;version="3.1.0",
 javax.servlet.http;version="3.1.0"
Bundle-ClassPath: .


OSGI-INF/contribution.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www osgi org/xmlns/scr/v1.1.0" name="BasicApplication">
   <implementation class="testproject.BasicApplication"/>
   <service>
      <provide interface="org.eclipse.rap.rwt.application.ApplicationConfiguration"/>
   </service>
</scr:component>


How am I suppose to fix this bug? I do not know how come it works in Eclipse IDE but not working after deploying it on the Tomcat server. Thanks in advance.
Re: download service servlet error on Tomcat 8 [message #1803582 is a reply to message #1803482] Mon, 04 March 2019 23:55 Go to previous message
Chris Fairhall is currently offline Chris FairhallFriend
Messages: 221
Registered: February 2011
Senior Member
Are you packaging javax.servlet in your WAR file? you may have multiple copies of the servlet classes.
Previous Topic:check size and format before FileUpload
Next Topic:Show Image from Server on Browsers Canvas
Goto Forum:
  


Current Time: Fri Jan 17 01:33:38 GMT 2025

Powered by FUDForum. Page generated in 0.03532 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top