Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit d548655

Browse files
committed
Redo and simplify Request/Response model
1 parent c53e7f3 commit d548655

60 files changed

Lines changed: 3433 additions & 594 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
<version>${project.version}</version>
2323
</dependency>
2424

25-
<dependency>
26-
<groupId>com.github.jknack</groupId>
27-
<artifactId>jooby-hibernate</artifactId>
28-
<version>${project.version}</version>
29-
</dependency>
30-
3125
<dependency>
3226
<groupId>com.github.jknack</groupId>
3327
<artifactId>jooby-jackson</artifactId>

examples/src/main/java/jooby/Command.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/src/main/java/jooby/MyApp.java

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -203,79 +203,25 @@
203203
*/
204204
package jooby;
205205

206-
import java.util.Map;
207-
208-
import javax.persistence.EntityManager;
209-
import javax.persistence.EntityManagerFactory;
210-
211206
import com.google.common.collect.ImmutableMap;
212207

208+
213209
public class MyApp extends Jooby {
214210

215211
{
216212
{
217-
// require modules
218-
use(new Jetty()); // web server
219-
use(new HibernatePersistence(User.class));
220-
use(new Jackson()); // JSON read & write
221-
use(new Hbs()); // Handlebars
222-
223-
get("/", (req, response) -> {
224-
response.send("Root");
225-
});
226-
227-
get("/hello", (req, resp) -> {
228-
Map<String, Object> model = ImmutableMap.<String, Object> builder()
229-
.put("name", "Joobby")
230-
.build();
231-
213+
use(new Jetty());
214+
use(new Jackson());
215+
use(new Hbs());
216+
217+
get("/", (req, resp) -> {
218+
ImmutableMap<Object, Object> model = ImmutableMap.builder()
219+
.put("name", "K")
220+
.build();
232221
resp.send(model);
233222
});
234223

235-
get("/logica", Logica::login);
236-
237-
post("/hello", (req, resp) -> {
238-
resp.send("hello");
239-
});
240-
241-
post("/upload", (request, resp) -> {
242-
Upload files = request.file("name");
243-
resp.send(files);
244-
});
245-
246-
Route userRoute = (request, response) -> {
247-
String name = request.param("name", String.class).get();
248-
System.out.println(name);
249-
int age = request.param("age", Integer.class).get();
250-
System.out.println(age);
251-
long start = System.currentTimeMillis();
252-
User user = request.get(User.class);
253-
long end = System.currentTimeMillis();
254-
System.out.println(end - start);
255-
256-
response.render("user", user);
257-
};
258-
259-
get("/user/{id}", Command.class);
260-
// get("/user/{id}", (req, resp) -> {
261-
// String id = req.param("id", String.class).get();
262-
// EntityManager em = require(EntityManager.class);
263-
// User user = em.find(User.class, id);
264-
// resp.render("user", user);
265-
// });
266-
267-
post("/save-user/{id}", (req, resp) -> {
268-
String id = req.param("id", String.class).get();
269-
EntityManagerFactory emf = req.get(EntityManagerFactory.class);
270-
EntityManager em = emf.createEntityManager();
271-
User user = new User(id, "Edgar", 31, null);
272-
em.persist(user);
273-
resp.send(user);
274-
em.close();
275-
});
276-
277-
post("/user", userRoute);
278-
224+
route(Resource.class);
279225
}
280226
}
281227

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package jooby;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
5+
@Path("/resource")
6+
public class Resource {
7+
8+
@GET
9+
// @Produces({"text/html", "application/json"})
10+
@Produces({"application/json" })
11+
// @Produces({"*/*" })
12+
public Object index(final String name) {
13+
return ImmutableMap.builder()
14+
.put("name", name)
15+
.build();
16+
}
17+
}

examples/src/main/java/jooby/ZeroJoin.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,14 @@
203203
*/
204204
package jooby;
205205

206-
import java.util.List;
207-
208-
import com.google.common.base.Joiner;
209-
import com.google.common.base.Splitter;
210206

211207
public class ZeroJoin {
212208

213-
public static void main(final String[] args) {
214-
char ZERO = '\uFFFF';
215-
System.out.println((int) ZERO);
216-
String[] array = {"a" + ZERO, "b", "c" };
217-
String join = Joiner.on(ZERO).join(array);
218-
System.out.println(join);
219-
List<String> splitToList = Splitter.on(ZERO).omitEmptyStrings().splitToList(join);
220-
System.out.println(splitToList.size());
209+
public void m(final String m) {
210+
211+
}
212+
public static void main(final String[] args) throws NoSuchMethodException, SecurityException {
213+
System.out.println("text/*".chars().map(ch -> ch == '*' ? 0: 1).sum());
221214
}
222215

223216
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<title>Hola</title>
44
</head>
55
<body>
6-
{{this}}
6+
{{name}}
77
</body>
88
</html>

jooby-core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<artifactId>config</artifactId>
4545
</dependency>
4646

47+
<!-- ASM 5.0 -->
48+
<dependency>
49+
<groupId>org.ow2.asm</groupId>
50+
<artifactId>asm</artifactId>
51+
</dependency>
52+
4753
<!-- Guice -->
4854
<dependency>
4955
<groupId>com.google.inject.extensions</groupId>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package jooby;
2+
3+
import java.util.Optional;
4+
5+
public interface AfterRoute {
6+
7+
void handle(Request request, Response response, Optional<Exception> cause) throws Exception;
8+
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package jooby;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Inherited;
6+
import java.lang.annotation.Retention;
7+
import java.lang.annotation.RetentionPolicy;
8+
import java.lang.annotation.Target;
9+
10+
@Inherited
11+
@Target({ElementType.TYPE, ElementType.METHOD})
12+
@Retention(RetentionPolicy.RUNTIME)
13+
@Documented
14+
public @interface Consumes {
15+
String[] value();
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package jooby;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.METHOD)
10+
public @interface DELETE {
11+
12+
}

0 commit comments

Comments
 (0)