Resizing undertow thread pool size dynamically
by Mohammed ElGhaouat
Hi,
I would like to know if there is a way to make undertow reducing the size
of the thread pool when the server is less loaded. Is there any
parameter(or other way) that make an idle thread die after some inactivity
time ?
Thanks.
Mohammed.
8 years, 11 months
Upgrade of undertow-pac4j
by Jérôme LELEU
Hi,
A few days ago, we released pac4j v1.8 which is now a full security engine
supporting authentication (for UI and web services), but also authorization
(see: https://github.com/pac4j/pac4j). It now provides guidelines on how to
create a full security library based on it.
There is currently a undertow-pac4j v1.0 which is based on pac4j v1.7 and
supports authentication (only for UI). I'd like to upgrade this library in
a new version 1.1 based on pac4j v1.8. It's mostly a smart copy/paste of
the j2e-pac4j implementation and the upgrade really worths it!
Although I could do this on my own, I'm looking for volunteers on this
upgrade to make things happen faster and get feedbacks.
Thanks.
Best regards,
Jérôme
9 years, 1 month
IllegalArgumentException - 'No servlet context to dispatch to' error in undertow for async servlet
by Dhamodharan Devarajan
Hello,
I am getting the below error when undertow tries to dispatch the
httpresponse.
java.lang.IllegalArgumentException: UT010046: No servlet context at
to dispatch to
at
io.undertow.servlet.spec.AsyncContextImpl.dispatch(AsyncContextImpl.java:173)
[undertow-servlet-1.1.0.Final.jar!/:1.1.0.Final]
at
org.eclipse.jetty.continuation.Servlet3Continuation.resume(Servlet3Continuation.java:152)
~[jetty-continuation.jar:8.1.3.v20120416]
at
com.xyz.xyzapp.apihandler.util.AsyncJobWaitingAPIHandler$MultiJobCompletionContext.onListenerCompletion(AsyncJobWaitingAPIHandler.java:460)
~[xyzapp-apihandler.jar:1.4.1-2015.10.dev]
at
com.xyz.xyzapp.apihandler.util.AsyncJobWaitingAPIHandler$MultiJobCompletionListener.onCompletion(AsyncJobWaitingAPIHandler.java:492)
~[xyzapp-apihandler.jar:1.4.1-2015.10.dev]
at com.xyz.xyzapp.job.JobEngine$4.onEvent(JobEngine.java:274)
~[xyzapp-job.jar:1.4.1-2015.10.dev]
at com.xyz.xyzapp.job.JobEngine$4.onEvent(JobEngine.java:269)
~[xyzapp-job.jar:1.4.1-2015.10.dev]
at
com.xyz.xyzapp.core.event.multicast.LocalMulticastEventManager$1.run(LocalMulticastEventManager.java:134)
~[xyzapp-core.jar:1.4.1-2015.10.dev]
at
org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
~[spring-context.jar:3.2.9.RELEASE]
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[na:1.8.0_51]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[na:1.8.0_51]
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
[na:1.8.0_51]
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
[na:1.8.0_51]
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[na:1.8.0_51]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[na:1.8.0_51]
I am using Jetty.Continuation (8.1.3) to suspend the HTTPrequest until it
has the response. I have spring (3.2.9) application that is deployed in
wildfly (8.2.0.Final). Spring servlet is configured via web-fragment.xml to
indicate that servlet is asynchronous
<servlet>
<servlet-name>apis</servlet-name>
<servlet-class>com.xyz.xyzapp.server.common.spring.ClassloaderOverridingDispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
When one of the job (job is internal framework) completes, it need to
respond back to clients (whoever is listening)
that job is completed. During this workflow, I am getting the above error.
I made sure the wildfly is up and running, clients are actually waiting for
response.
This was working with Jboss 6.1.0.Final/Tomcat.
What could be the problem? Any configuration I need to add in
standalone-full.xml for undertow? It appears that undertow closed the
HTTPrequest, not sure.
Regards,
Dhamodharan
9 years, 1 month
corrupted messages?
by Greg Shrack
I'm seeing an inconsistent problem where some messages are corrupted. We're
sending serialized objects over websockets, and are seeing some corrupted
messages with larger messages and sometimes when sending more quickly. We've
testing with a number of versions including undertow 1.1.8.Final, but was
seeing the same issue with newer versions as well. Wireshark appears to
show the corrupted data on the client side.
I've included sample code. The server creates a handler at localhost:6025
and then listens for messages. When a message is received it checks the
message against an expected pattern and prints out any bytes that don’t
match.
The client connects to the server and sends five 5000 byte messages one
second apart. On my machine at least one of the 5 messages would come
across with some corrupted data. I narrowed this down some - if the message
is 2930 bytes, it appears to get through. At 2931, I start seeing some
corruption. Using same test code with 1000 byte messages I was able to send
10000 messages with no sleep in between each send and all messages went
through fine.
Hopefully I'm missing something obvious. Thanks.
-----
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.websockets.WebSocketConnectionCallback;
import io.undertow.websockets.core.AbstractReceiveListener;
import io.undertow.websockets.core.BufferedBinaryMessage;
import io.undertow.websockets.core.WebSocketChannel;
import io.undertow.websockets.core.WebSockets;
import io.undertow.websockets.spi.WebSocketHttpExchange;
import org.xnio.Pooled;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
public class WebsocketTestServer
{
public WebsocketTestServer()
{
Undertow server = Undertow.builder()
.addHttpListener(6025, "localhost")
.setHandler(Handlers.pathTemplate().add("test",
Handlers.websocket(new TestHandler())))
.build();
server.start();
System.out.println("Server Started");
}
private class TestHandler extends AbstractReceiveListener implements
WebSocketConnectionCallback
{
@Override
public void onConnect(WebSocketHttpExchange webSocketHttpExchange,
WebSocketChannel webSocketChannel)
{
System.out.println("Client connected");
webSocketChannel.getReceiveSetter().set(this);
webSocketChannel.resumeReceives();
}
@Override
protected void onFullBinaryMessage(WebSocketChannel channel,
BufferedBinaryMessage message) throws IOException
{
try (Pooled<ByteBuffer[]> pooled = message.getData())
{
ByteBuffer[] buffers = pooled.getResource();
ByteBuffer bb = (buffers.length == 1) ? buffers[0] :
WebSockets.mergeBuffers(buffers);
if (bb.limit() > 0)
{
checkData(bb);
}
}
}
}
// Checks data against expected pattern
public static void checkData(ByteBuffer data)
{
long messageId = data.getLong(0);
for (int i = Long.BYTES; i < data.limit(); i++)
{
byte expected = (byte) (i%256);
byte actual = data.get(i);
if (actual != expected)
{
System.err.println("**** Corrupted data for message " + messageId +
" byte " + i + " expected " + expected + " but was " + actual);
}
}
}
public static void main(String[] args) throws InterruptedException
{
WebsocketTestServer server = new WebsocketTestServer();
while (true)
{
Thread.sleep(5000);
}
}
}
----------
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.net.URI;
import java.nio.ByteBuffer;
@ClientEndpoint
public class WebsocketTestClient
{
private Session session;
public WebsocketTestClient()
{
try
{
WebSocketContainer container =
ContainerProvider.getWebSocketContainer();
container.connectToServer(this,
URI.create("ws://localhost:6025/test"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
@OnOpen
public void onOpen(Session session)
{
System.out.println("Session opened");
this.session = session;
}
public void sendData(long index)
{
try
{
session.getBasicRemote().sendBinary(createTestData(index));
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static final ByteBuffer createTestData(long messageId)
{
ByteBuffer buffer = ByteBuffer.allocate(5000);
buffer.putLong(messageId);
for(int i=Long.BYTES; i< buffer.limit(); i++)
{
buffer.put((byte) (i%256));
}
buffer.flip();
return buffer;
}
public static void main(String[] args) throws InterruptedException
{
WebsocketTestClient client = new WebsocketTestClient();
Thread.sleep(1000);
for(int i=0; i<5; i++)
{
System.out.println("Sending " + i);
client.sendData(i);
Thread.sleep(1000);
}
System.out.println("Done");
}
}
9 years, 1 month
HttpServerExchange
by Greg Hellings
I'm trying to mock out the HttpServerExchange object in my tests, but
I apparently cannot do so because the class is declared final. Why is
it final? Does that give Undertow anything beneficial?
If there's good reason to not remove the final, I can just wrap the
object in a proxy class that's not final, but I'd rather not do that
just to get around limitations in mocking. Another alternative would
be for me to skip unit tests on the handler methods and leverage
integration tests.But there are sometimes bits of logic in the handler
that I want to Unit Test directly.
Any help would be appreciated.
--Greg
9 years, 1 month
webjars usage
by Bulut Aras
Hi,
I don't know if this is the right place but I have problems setting up
webjars in a maven project with undertow. I added dependencies to the
pom.xml. But can't figure out how to set up Resource/File handler.
Thanks in advance.
9 years, 1 month
Different Session Ids
by Dennis Gesker
Hello List:
I'm trying to use a websocket in Wildfly 10.0.0.CR2 from a Java SE client.
It's a pretty basic socket (a little more than just an echo). I'm sending a
string to the WS on the server. *However, the session id logged on WildFly
and the session id on my Java SE Client do not match*.
2015-10-06 12:31:28 INFO com.alamon.socket.GetCfgRoleWS - ServerSide
>>> Connected to ... *t9Y2a4kra35JpISc1s8F0qelNhoQ8mB7I_D3vTl4*
2015-10-06 12:31:28 INFO com.alamon.socket.GetCfgRoleWS - ServerSide
>>> *got: 6* : t9Y2a4kra35JpISc1s8F0qelNhoQ8mB7I_D3vTl4
2015-10-06 12:31:29 INFO stdout -
{"id":6,"name":"inspector","description":"inspector","enabled":true,"created":1444156117341,"modified":1444156117341}
2015-10-06 12:31:29 INFO com.alamon.socket.GetCfgRoleWS - ServerSide
>>> Session t9Y2a4kra35JpISc1s8F0qelNhoQ8mB7I_D3vTl4 closed because of
CloseReason[1000]
ClientSide >>> Session *6uT2VhsWOF8Kc5eMboHCybXQ02v1duV9MnhW8KMl* closed
because of CloseReason[1000]
The value I'm sending to the server (6 as a String) is showing up on the
server side but I'm not getting a response back. I'm guessing because the
session id's don't match. But, neither the Java SE client or the Wildfly
server are throwing any errors.
The client side seems pretty straight forward:
websocketServer = "http://localhost:8080/web/getCfgRoleWS";
websocketServerURI = new URI(websocketServer);
webSocketContainer = ContainerProvider.getWebSocketContainer();
webSocketSession = webSocketContainer.connectToServer(this.getClass(),
websocketServerURI);
// And after checking that the webSocketSession is not null or closed:
webSocketSession.getBasicRemote().sendText(id.toString());
Environment--
Client: JDK_1.8.0_60, Undertow 1.3.0.CR2
Server: JDK_1.8.0_60, Wildfly-10.0.0.CR2
I would welcome any hints or help that you can offer.
Cordially,
Dennis
9 years, 1 month