Skip to content

Commit e10fa42

Browse files
committed
update to java-http 0.2.5; Fix issue: @with annotation does not working as expected
1 parent 943c18e commit e10fa42

16 files changed

Lines changed: 178 additions & 140 deletions

pom.xml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,37 +209,31 @@
209209
<dependency>
210210
<groupId>org.osgl</groupId>
211211
<artifactId>osgl-tool</artifactId>
212-
<version>0.7.0-SNAPSHOT</version>
212+
<version>0.7.1-SNAPSHOT</version>
213213
</dependency>
214214

215215
<dependency>
216216
<groupId>org.osgl</groupId>
217217
<artifactId>osgl-mvc</artifactId>
218-
<version>0.3.2-SNAPSHOT</version>
218+
<version>0.3.3-SNAPSHOT</version>
219219
</dependency>
220220

221221
<dependency>
222222
<groupId>org.osgl</groupId>
223223
<artifactId>osgl-logging</artifactId>
224-
<version>0.4-SNAPSHOT</version>
224+
<version>0.5-SNAPSHOT</version>
225225
</dependency>
226226

227227
<dependency>
228228
<groupId>org.osgl</groupId>
229229
<artifactId>osgl-storage</artifactId>
230-
<version>0.3-SNAPSHOT</version>
231-
<exclusions>
232-
<exclusion>
233-
<groupId>org.osgl</groupId>
234-
<artifactId>osgl-tool</artifactId>
235-
</exclusion>
236-
</exclusions>
230+
<version>0.5.3-SNAPSHOT</version>
237231
</dependency>
238232

239233
<dependency>
240234
<groupId>org.osgl</groupId>
241235
<artifactId>osgl-cache</artifactId>
242-
<version>0.3-SNAPSHOT</version>
236+
<version>0.3.2-SNAPSHOT</version>
243237
</dependency>
244238

245239
<dependency>

src/main/java/act/app/ActionContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public Locale locale() {
149149
}
150150

151151
public boolean isJSON() {
152-
return accept() == H.Format.json;
152+
return accept() == H.Format.JSON;
153153
}
154154

155155
public boolean isAjax() {

src/main/java/act/conf/ActConfigKey.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public enum ActConfigKey implements ConfigKey {
4343
* <ul>
4444
* <li>{@code dev} - run Act during development, loading and refreshing class
4545
* directly from srccode code enabled in this mode</li>
46-
* <li>{@code sit} - run Act during system test</li>
47-
* <li>{@code uat} - run Act during UAT test</li>
4846
* <li>{@code prod} - run Act when system is live</li>
4947
* </ul>
5048
* <p>You pass the mode to Act runtime during start up like:</p>

src/main/java/act/controller/Controller.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import java.lang.annotation.Target;
2222
import java.util.Map;
2323

24+
import static org.osgl.http.H.Format.CSV;
25+
import static org.osgl.http.H.Format.HTML;
26+
import static org.osgl.http.H.Format.TXT;
27+
2428
/**
2529
* Mark a class as Controller, which contains at least one of the following:
2630
* <ul>
@@ -333,7 +337,7 @@ public static Result renderTemplate(Object ... args) {
333337
}
334338

335339
private static void setDefaultContextType(H.Request req, H.Response resp) {
336-
resp.contentType(req.contentType().toContentType());
340+
resp.contentType(req.contentType().contentType());
337341
}
338342

339343
public static Result inferResult(Result r, ActionContext actionContext) {
@@ -350,23 +354,20 @@ public static Result inferResult(String s, ActionContext actionContext) {
350354
return new RenderJSON(s);
351355
}
352356
H.Format fmt = actionContext.accept();
353-
switch (fmt) {
354-
case txt:
355-
case csv:
356-
return new RenderText(fmt, s);
357-
case html:
358-
case unknown:
359-
return html(s);
360-
default:
361-
throw E.unexpected("Cannot apply text result to format: %s", fmt);
357+
if (HTML == fmt || H.Format.UNKNOWN == fmt) {
358+
return html(s);
359+
}
360+
if (TXT == fmt || CSV == fmt) {
361+
return new RenderText(fmt, s);
362362
}
363+
throw E.unexpected("Cannot apply text result to format: %s", fmt);
363364
}
364365

365-
public static Result inferResult(Map<String, ?> map, ActionContext actionContext) {
366+
public static Result inferResult(Map<String, Object> map, ActionContext actionContext) {
366367
if (actionContext.isJSON()) {
367368
return new RenderJSON(map);
368369
}
369-
throw E.tbd("render template with render args in map");
370+
return new RenderTemplate(map);
370371
}
371372

372373
/**

src/main/java/act/controller/bytecode/ControllerByteCodeScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void scanFinished(String className) {
6565

6666
@Override
6767
public void allScanFinished() {
68-
classInfoBase().mergeActionMetaInfo();
68+
classInfoBase().mergeActionMetaInfo(app());
6969
}
7070

7171
private ControllerClassMetaInfoManager classInfoBase() {

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

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package act.controller.meta;
22

3+
import act.app.App;
4+
import act.app.AppClassLoader;
35
import act.asm.Type;
46
import act.handler.builtin.controller.ControllerAction;
57
import act.handler.builtin.controller.Handler;
@@ -205,27 +207,63 @@ public HandlerMethodMetaInfo handler(String name) {
205207
return handlerLookup.get(className() + "." + name);
206208
}
207209

208-
public List<InterceptorMethodMetaInfo> beforeInterceptors() {
209-
return interceptors.beforeList();
210+
public List<InterceptorMethodMetaInfo> beforeInterceptors(App app) {
211+
C.List<InterceptorMethodMetaInfo> list = C.newList();
212+
AppClassLoader cl = app.classLoader();
213+
for (String with : withList) {
214+
ControllerClassMetaInfo withInfo = cl.controllerClassMetaInfo(with);
215+
if (null != withInfo) {
216+
list.addAll(withInfo.beforeInterceptors(app));
217+
}
218+
}
219+
list.addAll(interceptors.beforeList());
220+
return list;
210221
}
211222

212-
public List<InterceptorMethodMetaInfo> afterInterceptors() {
213-
return interceptors.afterList();
223+
public List<InterceptorMethodMetaInfo> afterInterceptors(App app) {
224+
C.List<InterceptorMethodMetaInfo> list = C.newList();
225+
AppClassLoader cl = app.classLoader();
226+
for (String with : withList) {
227+
ControllerClassMetaInfo withInfo = cl.controllerClassMetaInfo(with);
228+
if (null != withInfo) {
229+
list.addAll(withInfo.afterInterceptors(app));
230+
}
231+
}
232+
list.addAll(interceptors.afterList());
233+
return list;
214234
}
215235

216-
public List<CatchMethodMetaInfo> exceptionInterceptors() {
217-
return interceptors.catchList();
236+
public List<CatchMethodMetaInfo> exceptionInterceptors(App app) {
237+
C.List<CatchMethodMetaInfo> list = C.newList();
238+
AppClassLoader cl = app.classLoader();
239+
for (String with : withList) {
240+
ControllerClassMetaInfo withInfo = cl.controllerClassMetaInfo(with);
241+
if (null != withInfo) {
242+
list.addAll(withInfo.exceptionInterceptors(app));
243+
}
244+
}
245+
list.addAll(interceptors.catchList());
246+
return list;
218247
}
219248

220-
public List<InterceptorMethodMetaInfo> finallyInterceptors() {
221-
return interceptors.finallyList();
249+
public List<InterceptorMethodMetaInfo> finallyInterceptors(App app) {
250+
C.List<InterceptorMethodMetaInfo> list = C.newList();
251+
AppClassLoader cl = app.classLoader();
252+
for (String with : withList) {
253+
ControllerClassMetaInfo withInfo = cl.controllerClassMetaInfo(with);
254+
if (null != withInfo) {
255+
list.addAll(withInfo.finallyInterceptors(app));
256+
}
257+
}
258+
list.addAll(interceptors.finallyList());
259+
return list;
222260
}
223261

224-
public ControllerClassMetaInfo merge(ControllerClassMetaInfoManager infoBase) {
225-
mergeFromWithList(infoBase);
262+
public ControllerClassMetaInfo merge(ControllerClassMetaInfoManager infoBase, App app) {
263+
mergeFromWithList(infoBase, app);
226264
mergeIntoActionList();
227265
buildActionLookup();
228-
buildHandlerLookup();
266+
buildHandlerLookup(app);
229267
return this;
230268
}
231269

@@ -258,13 +296,13 @@ private void getAllWithList(Set<String> withList, ControllerClassMetaInfoManager
258296
}
259297
}
260298

261-
private void mergeFromWithList(ControllerClassMetaInfoManager infoBase) {
299+
private void mergeFromWithList(ControllerClassMetaInfoManager infoBase, App app) {
262300
C.Set<String> withClasses = C.newSet();
263301
getAllWithList(withClasses, infoBase);
264302
for (String withClass : withClasses) {
265303
ControllerClassMetaInfo withClassInfo = infoBase.controllerMetaInfo(withClass);
266304
if (null != withClassInfo) {
267-
withClassInfo.merge(infoBase);
305+
withClassInfo.merge(infoBase, app);
268306
interceptors.mergeFrom(withClassInfo.interceptors);
269307
} else {
270308
logger.warn("Cannot find class info for @With class: %s", withClass);
@@ -286,19 +324,19 @@ private void buildActionLookup() {
286324
actionLookup = lookup;
287325
}
288326

289-
private void buildHandlerLookup() {
327+
private void buildHandlerLookup(App app) {
290328
C.Map<String, HandlerMethodMetaInfo> lookup = C.newMap();
291329
lookup.putAll(actionLookup);
292-
for (InterceptorMethodMetaInfo info : beforeInterceptors()) {
330+
for (InterceptorMethodMetaInfo info : beforeInterceptors(app)) {
293331
lookup.put(info.fullName(), info);
294332
}
295-
for (InterceptorMethodMetaInfo info : afterInterceptors()) {
333+
for (InterceptorMethodMetaInfo info : afterInterceptors(app)) {
296334
lookup.put(info.fullName(), info);
297335
}
298-
for (InterceptorMethodMetaInfo info : exceptionInterceptors()) {
336+
for (InterceptorMethodMetaInfo info : exceptionInterceptors(app)) {
299337
lookup.put(info.fullName(), info);
300338
}
301-
for (InterceptorMethodMetaInfo info : finallyInterceptors()) {
339+
for (InterceptorMethodMetaInfo info : finallyInterceptors(app)) {
302340
lookup.put(info.fullName(), info);
303341
}
304342
handlerLookup = lookup;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package act.controller.meta;
22

3+
import act.app.App;
34
import act.asm.Type;
45
import act.util.AsmTypes;
56
import act.util.DestroyableBase;
@@ -61,9 +62,9 @@ public ControllerClassMetaInfo controllerMetaInfo(String className) {
6162
return controllers.get(className);
6263
}
6364

64-
public void mergeActionMetaInfo() {
65+
public void mergeActionMetaInfo(App app) {
6566
for (ControllerClassMetaInfo info : controllers.values()) {
66-
info.merge(this);
67+
info.merge(this, app);
6768
}
6869
}
6970

src/main/java/act/handler/builtin/StaticFileGetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public File base() {
7474

7575
private H.Format contentType(String path) {
7676
FastStr s = FastStr.unsafeOf(path).afterLast('.');
77-
return H.Format.valueOfIgnoreCase(s.toString());
77+
return H.Format.of(s.toString());
7878
}
7979

8080
protected InputStream inputStream(String path, ActionContext context) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,25 +249,25 @@ private void generateHandlers() {
249249
requireContextLocal = true;
250250
}
251251
App app = this.app;
252-
for (InterceptorMethodMetaInfo info : ctrlInfo.beforeInterceptors()) {
252+
for (InterceptorMethodMetaInfo info : ctrlInfo.beforeInterceptors(app)) {
253253
beforeInterceptors.add(mode.createBeforeInterceptor(info, app));
254254
if (info.appContextInjection().injectVia().isLocal()) {
255255
requireContextLocal = true;
256256
}
257257
}
258-
for (InterceptorMethodMetaInfo info : ctrlInfo.afterInterceptors()) {
258+
for (InterceptorMethodMetaInfo info : ctrlInfo.afterInterceptors(app)) {
259259
afterInterceptors.add(mode.createAfterInterceptor(info, app));
260260
if (info.appContextInjection().injectVia().isLocal()) {
261261
requireContextLocal = true;
262262
}
263263
}
264-
for (CatchMethodMetaInfo info : ctrlInfo.exceptionInterceptors()) {
264+
for (CatchMethodMetaInfo info : ctrlInfo.exceptionInterceptors(app)) {
265265
exceptionInterceptors.add(mode.createExceptionInterceptor(info, app));
266266
if (info.appContextInjection().injectVia().isLocal()) {
267267
requireContextLocal = true;
268268
}
269269
}
270-
for (InterceptorMethodMetaInfo info : ctrlInfo.finallyInterceptors()) {
270+
for (InterceptorMethodMetaInfo info : ctrlInfo.finallyInterceptors(app)) {
271271
finallyInterceptors.add(mode.createFinallyInterceptor(info, app));
272272
if (info.appContextInjection().injectVia().isLocal()) {
273273
requireContextLocal = true;

src/main/java/act/mail/MailerConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import act.ActComponent;
44
import act.app.App;
55
import act.app.AppHolderBase;
6+
import org.osgl.exception.ConfigurationException;
67
import org.osgl.http.H;
78
import org.osgl.util.C;
89
import org.osgl.util.E;
@@ -187,13 +188,12 @@ private H.Format getContentTypeConfig(Map<String, String> properties) {
187188
}
188189
try {
189190
H.Format fmt = H.Format.valueOf(s);
190-
switch (fmt) {
191-
case html:
192-
case txt:
193-
return fmt;
194-
default:
195-
throw E.invalidConfiguration("Content type not supported by mailer: %s", fmt);
191+
if (H.Format.HTML == fmt || H.Format.TXT == fmt) {
192+
return fmt;
196193
}
194+
throw E.invalidConfiguration("Content type not supported by mailer: %s", fmt);
195+
} catch (ConfigurationException e) {
196+
throw e;
197197
} catch (Exception e) {
198198
throw E.invalidConfiguration("Invalid mailer config content type: %s", s);
199199
}

0 commit comments

Comments
 (0)