Skip to content

Commit 88babe3

Browse files
committed
updates for actframework#205, actframework#206, actframework#207; websocket support wip
1 parent c416310 commit 88babe3

24 files changed

Lines changed: 660 additions & 30 deletions

src/main/java/act/Act.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ public static void start() throws Exception {
570570
RunApp.start(S.beforeLast(className, "."));
571571
}
572572

573+
public static Network network() {
574+
return network;
575+
}
576+
573577
private static boolean isItPackageName(String s) {
574578
if (s.length() < 4) {
575579
return false;

src/main/java/act/app/AppHolderBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* #L%
2121
*/
2222

23+
import act.Act;
2324
import act.Destroyable;
2425
import act.util.DestroyableBase;
2526
import org.osgl.$;
@@ -29,6 +30,7 @@ public abstract class AppHolderBase<T extends AppHolderBase> extends Destroyable
2930
private App app;
3031

3132
protected AppHolderBase() {
33+
app = Act.app();
3234
}
3335

3436
protected AppHolderBase(App app) {

src/main/java/act/app/util/EnvMatcher.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ enum Type {
5151
Profile() {
5252
@Override
5353
boolean matches(EnvAnnotationVisitor visitor) {
54-
return Env.profileMatches(visitor.value, visitor.unless);
54+
return Env.profileMatches(visitor.value, visitor.except);
5555
}
5656
}, Group() {
5757
@Override
5858
boolean matches(EnvAnnotationVisitor visitor) {
59-
return Env.groupMatches(visitor.value, visitor.unless);
59+
return Env.groupMatches(visitor.value, visitor.except);
6060
}
6161
}, Mode() {
6262
@Override
6363
boolean matches(EnvAnnotationVisitor visitor) {
64-
return Env.modeMatches(Act.Mode.valueOf(visitor.value), visitor.unless);
64+
return Env.modeMatches(Act.Mode.valueOf(visitor.value), visitor.except);
6565
}
6666
};
6767

@@ -70,7 +70,7 @@ boolean matches(EnvAnnotationVisitor visitor) {
7070

7171
private Type type;
7272
private String value;
73-
private boolean unless;
73+
private boolean except;
7474

7575
public EnvAnnotationVisitor(AnnotationVisitor av, String desc) {
7676
super(ASM5, av);
@@ -81,8 +81,8 @@ public EnvAnnotationVisitor(AnnotationVisitor av, String desc) {
8181
public void visit(String name, Object value) {
8282
if ("value".equals(name)) {
8383
this.value = value.toString();
84-
} else if ("unless".equals(name)) {
85-
this.unless = Boolean.parseBoolean(value.toString());
84+
} else if ("except".equals(name)) {
85+
this.except = Boolean.parseBoolean(value.toString());
8686
}
8787
super.visit(name, value);
8888
}

src/main/java/act/conf/AppConfig.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,29 @@ private void _mergeUploadFileDownload(AppConfig config) {
24422442
}
24432443
}
24442444

2445+
private String wsTicketKey;
2446+
2447+
protected T wsTicketeKey(String wsTicketKey) {
2448+
this.wsTicketKey = wsTicketKey;
2449+
return me();
2450+
}
2451+
2452+
public String wsTicketKey() {
2453+
if (null == wsTicketKey) {
2454+
wsTicketKey = get(WS_KEY_TICKET);
2455+
if (null == wsTicketKey) {
2456+
wsTicketKey = "ws_ticket";
2457+
}
2458+
}
2459+
return wsTicketKey;
2460+
}
2461+
2462+
private void _mergeWsTicketKey(AppConfig config) {
2463+
if (!hasConfiguration(WS_KEY_TICKET)) {
2464+
wsTicketKey = config.wsTicketKey;
2465+
}
2466+
}
2467+
24452468
private Set<AppConfigurator> mergeTracker = C.newSet();
24462469

24472470
public void loadJarProperties(Map<String, Properties> jarProperties) {
@@ -2471,6 +2494,7 @@ private void loadJarProperties(Properties p) {
24712494
}
24722495
}
24732496

2497+
24742498
/**
24752499
* Merge application configurator settings. Note application configurator
24762500
* settings has lower priority as it's hardcoded thus only when configuration file
@@ -2572,6 +2596,7 @@ public void _merge(AppConfigurator conf) {
25722596
_mergeCacheServiceProvider(conf);
25732597
_mergeUnknownHttpMethodHandler(conf);
25742598
_mergeUploadFileDownload(conf);
2599+
_mergeWsTicketKey(conf);
25752600

25762601
Set<String> keys = conf.propKeys();
25772602
if (!keys.isEmpty()) {

src/main/java/act/conf/AppConfigKey.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,15 @@ public <T> T val(Map<String, ?> configuration) {
834834
*/
835835
VIEW_DEFAULT("view.default"),
836836

837+
/**
838+
* `ws.key.ticket`
839+
*
840+
* Specifies the parameter variable name to get websocket ticket
841+
*
842+
* Default value: `ws_ticket`
843+
*/
844+
WS_KEY_TICKET("ws.key.ticket"),
845+
837846
X_FORWARD_PROTOCOL("x_forward_protocol"),
838847

839848
;

src/main/java/act/controller/meta/ControllerClassMetaInfo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import act.util.ClassInfoRepository;
3030
import act.util.ClassNode;
3131
import act.util.DestroyableBase;
32+
import act.ws.WsAction;
3233
import org.osgl.http.H;
3334
import org.osgl.mvc.annotation.*;
3435
import org.osgl.util.C;
@@ -454,7 +455,8 @@ private void buildHandlerLookup() {
454455
PostAction.class, H.Method.POST,
455456
PutAction.class, H.Method.PUT,
456457
DeleteAction.class, H.Method.DELETE,
457-
PatchAction.class, H.Method.PATCH
458+
PatchAction.class, H.Method.PATCH,
459+
WsAction.class, H.Method.GET
458460
);
459461

460462
public static boolean isActionAnnotation(Class<? extends Annotation> type) {

src/main/java/act/handler/builtin/controller/RequestHandlerProxy.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import act.util.MissingAuthenticationHandler;
3939
import act.view.ActErrorResult;
4040
import act.view.RenderAny;
41+
import act.xio.WebSocketConnectionHandler;
4142
import org.osgl.$;
4243
import org.osgl.cache.CacheService;
4344
import org.osgl.exception.UnexpectedException;
@@ -99,6 +100,8 @@ public final class RequestHandlerProxy extends RequestHandlerBase {
99100
private MissingAuthenticationHandler missingAuthenticationHandler;
100101
private MissingAuthenticationHandler csrfFailureHandler;
101102

103+
private WebSocketConnectionHandler webSocketConnectionHandler;
104+
102105
final GroupInterceptorWithResult BEFORE_INTERCEPTOR = new GroupInterceptorWithResult(beforeInterceptors);
103106
final GroupAfterInterceptor AFTER_INTERCEPTOR = new GroupAfterInterceptor(afterInterceptors);
104107
final GroupFinallyInterceptor FINALLY_INTERCEPTOR = new GroupFinallyInterceptor(finallyInterceptors);
@@ -343,12 +346,20 @@ private ActionMethodMetaInfo findActionInfoFromParent(ControllerClassMetaInfo ct
343346
return new ActionMethodMetaInfo($.notNull(actionInfo), ctrlInfo);
344347
}
345348

349+
private WebSocketConnectionHandler tryGenerateWebSocketConnectionHandler(ActionMethodMetaInfo methodInfo) {
350+
return Act.network().createWebSocketConnectionHandler(methodInfo);
351+
}
352+
346353
private void generateHandlers() {
347354
ControllerClassMetaInfo ctrlInfo = app.classLoader().controllerClassMetaInfo(controllerClassName);
348355
ActionMethodMetaInfo actionInfo = ctrlInfo.action(actionMethodName);
349356
if (null == actionInfo) {
350357
actionInfo = findActionInfoFromParent(ctrlInfo, actionMethodName);
351358
}
359+
webSocketConnectionHandler = tryGenerateWebSocketConnectionHandler(actionInfo);
360+
if (null != webSocketConnectionHandler) {
361+
return;
362+
}
352363
Act.Mode mode = Act.mode();
353364
actionHandler = mode.createRequestHandler(actionInfo, app);
354365
sessionFree = actionHandler.sessionFree();

src/main/java/act/inject/genie/GenieInjector.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,7 @@ public static void foundProviderBase(Class<? extends ActProvider> providerClass)
317317
}
318318

319319
private static boolean isModuleAllowed(Class<?> moduleClass) {
320-
Env.Profile profile = moduleClass.getAnnotation(Env.Profile.class);
321-
if (null != profile) {
322-
return Env.matches(profile);
323-
}
324-
Env.Mode mode = moduleClass.getAnnotation(Env.Mode.class);
325-
if (null != mode) {
326-
return Env.matches(mode);
327-
}
328-
Env.Group group = moduleClass.getAnnotation(Env.Group.class);
329-
if (null != group) {
330-
return Env.matches(group);
331-
}
332-
return true;
320+
return Env.matches(moduleClass);
333321
}
334322

335323
}

src/main/java/act/job/bytecode/ReflectedJobInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void init() {
6868
jobClass = $.classForName(classInfo.className(), cl);
6969
disabled = disabled || !Env.matches(jobClass);
7070
method = methodInfo.method();
71-
disabled = disabled || !Env.matches(jobClass);
71+
disabled = disabled || !Env.matches(method);
7272
providedParams = methodInfo.paramTypes();
7373
ParamValueLoaderManager paramValueLoaderManager = app.service(ParamValueLoaderManager.class);
7474
if (null != paramValueLoaderManager) {

0 commit comments

Comments
 (0)