Correctly shutting down a websocket handler
by Robin Anil
When a client disconnects, I see that onClose is not being fired. The only
way this seems to be firing if client sents a close frame.
Is there any way to detect disconnection and immediately close all the
opened resources.
Robin
Robin Anil | Software Engineer
1 year, 2 months
Parts are not accessible after invoking getInputStream
by Juan Carlos Flores Beltran
I have implemented a servlet that has the following properties:
1) asyncSupported = true
2) @MultipartConfig
3) Uses a ReadListener to upload a file without blocking
The problem I have is that in the ReadListener the parts have disappeared. Obviously invoking request.getInputStream() in the Servlet causes request.getParts() in the ReadListener to return an empty list.
I found out that in the class io.undertow.servlet.spec.HttpServletRequestImpl the flag readStarted controls whether parts may be read or not. Obviously it is not possible to get the parts once you have called getInputStream(). I can't find the place in the spec where this is forbidden.
What I don't understand here is that this source code works using glassfish, but not using Wildfly 18 (with undertow). Can someone tell me why this is so? And maybe offer an alternative implementation.
This the Servlet:
@WebServlet(urlPatterns = { "/noblock" }, asyncSupported = true)
@MultipartConfig(maxFileSize = 1024 * 1024 * 10, maxRequestSize = 1024 * 1024 * 30)
public class AsyncServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private Logger log = Logger.getLogger(AsyncServlet.class.getName());
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.finest("doPost Start");
AsyncContext asyncContext = request.startAsync();
ServletInputStream input = request.getInputStream();
input.setReadListener(new ExampleReadListener(asyncContext));
PrintWriter writer = response.getWriter();
writer.println("Non blocking Servlet completed");
writer.flush();
log.finest("doPost End");
}
}
This ist the ReadListener:
public class ExampleReadListener implements ReadListener {
private Logger log = Logger.getLogger(ExampleReadListener.class.getName());
private AsyncContext asyncContext;
public ExampleReadListener(AsyncContext pAsyncContext) {
this.asyncContext = pAsyncContext;
}
@Override
public void onAllDataRead() throws IOException {
log.finest("onAllDataRead started");
try {
asyncContext.getResponse().getWriter().write("\n All data has been read!");
} catch (Exception e) {
e.printStackTrace();
}
asyncContext.complete();
log.finest("onAllDataRead ended");
}
@Override
public void onDataAvailable() throws IOException {
log.finest("onDataAvailable started");
HttpServletRequest request = (HttpServletRequest) asyncContext.getRequest();
ServletInputStream input = null;
Collection<Part> parts = null;
try {
asyncContext.getResponse().getWriter().write("Some data available!\n");
parts = request.getParts();
log.finest("Parts = " + parts);
input = request.getInputStream();
} catch (Exception e) {
e.printStackTrace();
}
int length = -1;
byte buffer[] = new byte[1024];
while (input.isReady() && (length = input.read(buffer)) != -1) {
String data = new String(buffer, 0, length);
asyncContext.getResponse().getWriter().write(data);
}
log.finest("onDataAvailable ended");
}
@Override
public void onError(Throwable arg0) {
log.finest("onError started");
asyncContext.complete();
log.finest("onError ended");
}
}
4 years, 11 months
HTTP PATCH support
by Chris Baumgartner
Hello,
My company is using Wildfly 10.0.0. Sorry, but I'm not sure what version of
undertow is in it.
I have a client application that is trying to perform an HTTP PATCH
request. The error that is being returned to the client is "Method PATCH is
not defined in RFC 2068 and is not supported by the Servlet API". This
isn't true, because it is in RFC 2068.
I can see that HTTP POST methods are reaching my servlet, but PATCH methods
are not.
If I run the servlet in another Web server (Jetty), it works just fine.
I've been searching through both Wildfly and Undertow code, and I can't
figure out where this error is coming from.
Does undertow support HTTP PATCH requests? I'm assuming it does, and there
is some configuration setting that I need, but I'm not sure which one.
Any help is greatly appreciated.
Thanks.
--
Chris Baumgartner
Java Software Developer
FUJIFILM Medical Systems U.S.A., Inc.
TeraMedica Division
10400 Innovation Drive, Suite 200
Milwaukee, WI 53226
Office: (414) 908-7724
www.teramedica.com
*Helping provide healthcare experiences that enhance the quality of life. *
--
NOTICE: This message, including any attachments, is only for the use of
the intended recipient(s) and may contain confidential, sensitive and/or
privileged information, or information otherwise prohibited from
dissemination or disclosure by law or regulation, including applicable
export regulations. If the reader of this message is not the intended
recipient, you are hereby notified that any use, disclosure, copying,
dissemination or distribution of this message or any of its attachments is
strictly prohibited. If you received this message in error, please contact
the sender immediately by reply email and destroy this message, including
all attachments, and any copies thereof.
4 years, 11 months