forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebSockets Next: error handlers part 1
- see quarkusio#39186
- Loading branch information
Showing
25 changed files
with
996 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...deployment/src/main/java/io/quarkus/websockets/next/deployment/ErrorCallbackArgument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.quarkus.websockets.next.deployment; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.IndexView; | ||
|
||
import io.quarkus.gizmo.ResultHandle; | ||
|
||
class ErrorCallbackArgument implements CallbackArgument { | ||
|
||
@Override | ||
public boolean matches(ParameterContext context) { | ||
return context.callbackAnnotation().name().equals(WebSocketDotNames.ON_ERROR) | ||
&& isThrowable(context.index(), context.parameter().type().name()); | ||
} | ||
|
||
@Override | ||
public ResultHandle get(InvocationBytecodeContext context) { | ||
return context.getPayload(); | ||
} | ||
|
||
boolean isThrowable(IndexView index, DotName clazzName) { | ||
if (clazzName.equals(WebSocketDotNames.THROWABLE)) { | ||
return true; | ||
} | ||
ClassInfo clazz = index.getClassByName(clazzName); | ||
if (clazz == null) { | ||
throw new IllegalArgumentException("The class " + clazzName + " not found in the index"); | ||
} | ||
if (clazz.superName().equals(DotName.OBJECT_NAME) | ||
|| clazz.superName().equals(DotName.RECORD_NAME) | ||
|| clazz.superName().equals(DotName.ENUM_NAME)) { | ||
return false; | ||
} | ||
if (clazz.superName().equals(WebSocketDotNames.THROWABLE)) { | ||
return true; | ||
} | ||
return isThrowable(index, clazz.superName()); | ||
} | ||
|
||
public static boolean isError(CallbackArgument callbackArgument) { | ||
return callbackArgument instanceof ErrorCallbackArgument; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.