Skip to content

Commit 9092e37

Browse files
committed
better error messages when mvc arg provision fails + mvc doc
1 parent 625d5f8 commit 9092e37

File tree

12 files changed

+386
-213
lines changed

12 files changed

+386
-213
lines changed

docs/mvc-api.adoc

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,140 @@ class MyController {
206206
}
207207
}
208208
----
209+
210+
[id=mvc-body]
211+
==== Body
212+
213+
Body parameter doesn't require an annotation:
214+
215+
.HTTP Body
216+
[source, java, role = "primary"]
217+
----
218+
public class MyController {
219+
220+
@Path("/")
221+
@POST
222+
public Object provisioning(MyObject body) {
223+
...
224+
}
225+
}
226+
----
227+
228+
.Kotlin
229+
[source, kotlin, role = "secondary"]
230+
----
231+
class MyController {
232+
233+
@Path("/")
234+
@POST
235+
fun provisioning(body: MyObject) : Any {
236+
...
237+
}
238+
}
239+
----
240+
241+
=== Registration
242+
243+
Mvc routes need to be registered (no classpath scanning). Registration is done from your application
244+
class:
245+
246+
.Simple MVC route registration
247+
[source, java, role = "primary"]
248+
----
249+
public class App extends Jooby {
250+
{
251+
mvc(new MyController());
252+
}
253+
254+
public static void main(String[] args) {
255+
run(App::new, args);
256+
}
257+
}
258+
----
259+
260+
.Kotlin
261+
[source, kotlin, role = "secondary"]
262+
----
263+
264+
import io.jooby.*
265+
266+
fun main(args: Array<String>) {
267+
run(args) {
268+
mvc(MyController())
269+
}
270+
}
271+
----
272+
273+
The javadoc:Jooby[mvc, java.lang.Object] install the mvc route. As showed in the example there is
274+
no dependency injection involved, you just instantiate a MVC route and register.
275+
276+
.Class MVC route registration
277+
[source, java, role = "primary"]
278+
----
279+
public class App extends Jooby {
280+
{
281+
mvc(MyController.class);
282+
}
283+
284+
public static void main(String[] args) {
285+
run(App::new, args);
286+
}
287+
}
288+
----
289+
290+
.Kotlin
291+
[source, kotlin, role = "secondary"]
292+
----
293+
294+
import io.jooby.*
295+
296+
fun main(args: Array<String>) {
297+
run(args) {
298+
mvc(MyController::class)
299+
}
300+
}
301+
----
302+
303+
The javadoc:Jooby[mvc, java.lang.Class] does the same job, but delegates route instantiation to a
304+
dependency injection framework of your choice.
305+
306+
NOTE: Jooby 1.x was built around Guice, this is not the case for 2.x. The entire project was built
307+
without dependency injection. This make DI optional and at same time give you freedom to choose the
308+
one you like most.
309+
310+
.Provider MVC route registration
311+
[source, java, role = "primary"]
312+
----
313+
314+
import javax.inject.Provider;
315+
316+
public class App extends Jooby {
317+
{
318+
Provider<MyController> provider = ...;
319+
320+
mvc(MyController.class, provider);
321+
}
322+
323+
public static void main(String[] args) {
324+
run(App::new, args);
325+
}
326+
}
327+
----
328+
329+
.Kotlin
330+
[source, kotlin, role = "secondary"]
331+
----
332+
import javax.inject.Provider
333+
import io.jooby.*
334+
335+
fun main(args: Array<String>) {
336+
run(args) {
337+
val provider = ...
338+
mvc(MyController::class, provider)
339+
}
340+
}
341+
----
342+
343+
The javadoc:Jooby[mvc, javax.inject.Provider] does the same job, might or might not delegate
344+
instantiation to a dependency injection framework but most important let you control lifecycle of
345+
MVC routes (Singleton vs Non-Singleton routes).

docs/src/main/java/io/jooby/adoc/DocServer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ public static void main(String[] args) throws Exception {
1515

1616
DocGenerator.generate(basedir, false);
1717

18+
Process process = new ProcessBuilder("open", basedir.resolve("out").resolve("index.html").toUri().toString())
19+
.start();
20+
process.waitFor();
21+
process.destroy();
22+
1823
System.out.println("listening for changes on: " + basedir);
19-
System.out.println("ready");
2024

2125
ExecutorService executor = Executors.newSingleThreadExecutor();
2226
DirectoryWatcher watcher = DirectoryWatcher.builder()

examples/src/main/java/examples/MvcApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class MvcApp extends Jooby {
77

88
{
9-
use(new PlainText());
9+
mvc(new PlainText());
1010
}
1111

1212
public static void main(String[] args) {

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package io.jooby;
1717

1818
import io.jooby.internal.RegistryImpl;
19-
import io.jooby.internal.RouteAnalyzer;
2019
import io.jooby.internal.RouterImpl;
2120
import org.slf4j.Logger;
2221
import org.slf4j.LoggerFactory;
@@ -140,19 +139,19 @@ public Jooby use(@Nonnull Predicate<Context> predicate, @Nonnull Router router)
140139
return this;
141140
}
142141

143-
@Nonnull @Override public Jooby use(@Nonnull Object router) {
144-
this.router.use(router);
142+
@Nonnull @Override public Jooby mvc(@Nonnull Object router) {
143+
this.router.mvc(router);
145144
return this;
146145
}
147146

148-
@Nonnull @Override public Jooby use(@Nonnull Class router) {
149-
this.router.use(router, () -> require(router));
147+
@Nonnull @Override public Jooby mvc(@Nonnull Class router) {
148+
this.router.mvc(router, () -> require(router));
150149
return this;
151150
}
152151

153152
@Nonnull @Override
154-
public <T> Jooby use(@Nonnull Class<T> router, @Nonnull Provider<T> provider) {
155-
this.router.use(router, provider);
153+
public <T> Jooby mvc(@Nonnull Class<T> router, @Nonnull Provider<T> provider) {
154+
this.router.mvc(router, provider);
156155
return this;
157156
}
158157

jooby/src/main/java/io/jooby/Router.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ interface Match {
8080
@Nonnull Router use(@Nonnull Router router);
8181

8282
/* ***********************************************************************************************
83-
* use(Mvc)
83+
* Mvc
8484
* ***********************************************************************************************
8585
*/
86-
@Nonnull Router use(@Nonnull Class router);
86+
@Nonnull Router mvc(@Nonnull Class router);
8787

88-
@Nonnull <T> Router use(@Nonnull Class<T> router, @Nonnull Provider<T> provider);
88+
@Nonnull <T> Router mvc(@Nonnull Class<T> router, @Nonnull Provider<T> provider);
8989

90-
@Nonnull Router use(@Nonnull Object router);
90+
@Nonnull Router mvc(@Nonnull Object router);
9191

9292

9393
@Nonnull List<Route> routes();

jooby/src/main/java/io/jooby/internal/RouterImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,17 @@ public Router use(@Nonnull Router router) {
231231
return use("", router);
232232
}
233233

234-
@Nonnull @Override public Router use(@Nonnull Object router) {
234+
@Nonnull @Override public Router mvc(@Nonnull Object router) {
235235
mvc(null, router.getClass(), () -> router);
236236
return this;
237237
}
238238

239-
@Nonnull @Override public Router use(@Nonnull Class router) {
239+
@Nonnull @Override public Router mvc(@Nonnull Class router) {
240240
throw new UnsupportedOperationException();
241241
}
242242

243243
@Nonnull @Override
244-
public <T> Router use(@Nonnull Class<T> router, @Nonnull Provider<T> provider) {
244+
public <T> Router mvc(@Nonnull Class<T> router, @Nonnull Provider<T> provider) {
245245
mvc(null, router, provider);
246246
return this;
247247
}

0 commit comments

Comments
 (0)