Skip to content

Commit b8f6578

Browse files
committed
Enable execution mode for methods.
1 parent 0c4ce33 commit b8f6578

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main/java/org/tinystruct/handler/HttpRequestHandler.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.tinystruct.system.ApplicationManager;
2525
import org.tinystruct.system.Configuration;
2626
import org.tinystruct.system.Language;
27+
import org.tinystruct.system.annotation.Action;
28+
import org.tinystruct.system.annotation.Action.Mode;
2729
import org.tinystruct.system.util.StringUtilities;
2830

2931
import java.nio.charset.StandardCharsets;
@@ -76,8 +78,8 @@ private void service(final ChannelHandlerContext ctx, final Request<FullHttpRequ
7678
}
7779

7880
String[] parameterNames = request.parameterNames();
79-
for (String parameter: parameterNames) {
80-
if(parameter.startsWith("--")) {
81+
for (String parameter : parameterNames) {
82+
if (parameter.startsWith("--")) {
8183
context.setAttribute(parameter, request.getParameter(parameter));
8284
}
8385
}
@@ -127,8 +129,9 @@ private void service(final ChannelHandlerContext ctx, final Request<FullHttpRequ
127129

128130
String query = request.query();
129131
if (query != null && query.length() > 1) {
132+
Mode mode = Mode.fromName(request.method().name());
130133
query = StringUtilities.htmlSpecialChars(query);
131-
if (null == (message = ApplicationManager.call(query, context))) {
134+
if (null == (message = ApplicationManager.call(query, context, mode))) {
132135
message = "No response retrieved!";
133136
} else if (message instanceof Response) {
134137
// Write the response.
@@ -140,7 +143,7 @@ private void service(final ChannelHandlerContext ctx, final Request<FullHttpRequ
140143
return;
141144
}
142145
} else {
143-
message = ApplicationManager.call(this.configuration.getOrDefault("default.home.page", "say/Praise the Lord."), context);
146+
message = ApplicationManager.call(this.configuration.getOrDefault("default.home.page", "say/Praise the Lord."), context, Action.Mode.HTTP_GET);
144147
}
145148
} catch (ApplicationException e) {
146149
StackTraceElement[] trace = e.getStackTrace();
@@ -270,12 +273,11 @@ private void handleSSE(final ChannelHandlerContext ctx, final Request<FullHttpRe
270273
String sessionId = context.getId();
271274
SSEPushManager pushManager = getAppropriatePushManager(isMCP);
272275
pushManager.register(sessionId, response);
273-
if(call instanceof Builder) {
276+
if (call instanceof Builder) {
274277
pushManager.push(sessionId, (Builder) call);
275-
}
276-
else if(call instanceof String) {
278+
} else if (call instanceof String) {
277279
Builder builder = new Builder();
278-
builder.parse((String)call);
280+
builder.parse((String) call);
279281
pushManager.push(sessionId, builder);
280282
}
281283
}

0 commit comments

Comments
 (0)