Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:17:18+00:00 2026-05-22T22:17:18+00:00

I have a class that extends RemoteServiceServlet. This class has several methods, in one

  • 0

I have a class that extends RemoteServiceServlet. This class has several methods, in one method, I use getThreadLocalResponse() to get the HttpServletResponse for the current call, and then write a File in the response. Here is the code:

File aFile = new File("c://test.txt");
int iBufferSize = 1000;
int iLength = 0;

HttpServletResponse resp = getThreadLocalResponse();

ServletOutputStream op = resp.getOutputStream();
ServletContext context = getServletConfig().getServletContext();
String mimetype = context.getMimeType(aFile.getName());

resp.setContentType((mimetype != null) ? mimetype : "application/octet-stream");
resp.setContentLength((int) aFile.length());
resp.setHeader("Content-Disposition", "attachment; filename=\"" + aFile.getName() + "\"");

byte[] xbuf = new byte[iBufferSize];
DataInputStream in = new DataInputStream(new FileInputStream(aFile));

while ((in != null) && ((iLength = in.read(xbuf)) != -1))
{
  op.write(xbuf, 0, iLength);
}

in.close();
op.flush();
op.close();

However, an error always occurs. After debugging, I find out that an Exception is thrown when it writes the response.

I don’t override doGet and doPost, because there are some other methods, I don’t want every request to the class can invoke this piece of code.

But if I create a separate Servlet or override doGet or doPost in this class, it works fine.

Does anybody know why? Does GWT RemoteServiceServlet support writing a Stream in the response when we use getThreadLocalResponse() ?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:17:18+00:00Added an answer on May 22, 2026 at 10:17 pm

    Are you putting this code inside of a GWT-RPC method in your RemoteServiceServlet?

    If yes, then you are trying to mix GWT-RPC with some of your own content, which you are not allowed to do. You can’t just write arbitrary data to http response as this will clearly mess up the RPC protocol.

    OTOH, if your just putting some of your own methods side-by-side to GWT-RPC methods, then why not creating a new Servlet?

    AFAIK, GWT-RPC uses http POST, so overriding doGet() should work for your functionality and leave GWT-RPC working. But overriding doPost() will break GWT-RPC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that extends Thread. This thread when running spends most of
I have a class that extends View. I override the onDraw method and allow
I have a method that looks like this public static <T extends MyClass, X
I have class that extends 'IntentService' - this class occasionally receives data from a
i have class that extends thread and in one of its methodes i added
I have custom class that extends WebViewPage that I use as the base for
I have a class that extends Exception, and therefore has to be Serializable. The
If I have a base class such that public abstract class XMLSubscription <T extends
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
I have class method that returns a list of employees that I can iterate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.