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

Commit 119438c

Browse files
committed
use websocket text/plain as default content-type fix jooby-project#504
1 parent 6b04308 commit 119438c

File tree

9 files changed

+70
-27
lines changed

9 files changed

+70
-27
lines changed

coverage-report/src/test/java/org/jooby/ws/OnByteArrayMessageFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.concurrent.CountDownLatch;
77
import java.util.concurrent.TimeUnit;
88

9+
import org.jooby.MediaType;
910
import org.jooby.test.ServerFeature;
1011
import org.junit.After;
1112
import org.junit.Before;
@@ -29,7 +30,7 @@ public class OnByteArrayMessageFeature extends ServerFeature {
2930
ws.close();
3031
});
3132
});
32-
});
33+
}).produces(MediaType.octetstream);
3334

3435
}
3536

coverage-report/src/test/java/org/jooby/ws/OnByteBufferMessageFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.concurrent.CountDownLatch;
88
import java.util.concurrent.TimeUnit;
99

10+
import org.jooby.MediaType;
1011
import org.jooby.test.ServerFeature;
1112
import org.junit.After;
1213
import org.junit.Before;
@@ -30,8 +31,7 @@ public class OnByteBufferMessageFeature extends ServerFeature {
3031
ws.close();
3132
});
3233
});
33-
34-
});
34+
}).produces(MediaType.octetstream);
3535

3636
}
3737

jooby-banner/src/test/java/org/jooby/banner/BannerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.jooby.banner;
22

33
import static org.easymock.EasyMock.expect;
4+
import static org.easymock.EasyMock.isA;
5+
6+
import javax.inject.Provider;
47

58
import org.jooby.Env;
69
import org.jooby.test.MockUnit;
@@ -14,6 +17,9 @@
1417

1518
import com.github.lalyos.jfiglet.FigletFont;
1619
import com.google.inject.Binder;
20+
import com.google.inject.Key;
21+
import com.google.inject.binder.LinkedBindingBuilder;
22+
import com.google.inject.name.Names;
1723
import com.typesafe.config.Config;
1824

1925
import javaslang.control.Try.CheckedRunnable;
@@ -34,6 +40,7 @@ public void configure() throws Exception {
3440
new MockUnit(Env.class, Config.class, Binder.class, Logger.class)
3541
.expect(conf("app", "1.0.0"))
3642
.expect(log("app"))
43+
.expect(banner())
3744
.expect(onStart)
3845
.run(unit -> {
3946
new Banner(banner)
@@ -50,6 +57,7 @@ public void print() throws Exception {
5057
.expect(onStart)
5158
.expect(convertOnLine(banner, "speed"))
5259
.expect(print(banner, "1.0.0"))
60+
.expect(banner())
5361
.run(unit -> {
5462
new Banner(banner)
5563
.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
@@ -67,6 +75,7 @@ public void font() throws Exception {
6775
.expect(onStart)
6876
.expect(convertOnLine(banner, "myfont"))
6977
.expect(print(banner, "1.0.0"))
78+
.expect(banner())
7079
.run(unit -> {
7180
new Banner(banner)
7281
.font("myfont")
@@ -85,6 +94,7 @@ public void defprint() throws Exception {
8594
.expect(onStart)
8695
.expect(convertOnLine(banner, "speed"))
8796
.expect(print(banner, "1.0.0"))
97+
.expect(banner())
8898
.run(unit -> {
8999
new Banner()
90100
.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
@@ -121,4 +131,16 @@ private Block conf(final String name, final String v) {
121131
expect(conf.getString("application.version")).andReturn(v);
122132
};
123133
}
134+
135+
@SuppressWarnings("unchecked")
136+
private Block banner() {
137+
return unit -> {
138+
139+
LinkedBindingBuilder<String> lbb = unit.mock(LinkedBindingBuilder.class);
140+
expect(lbb.toProvider(isA(Provider.class))).andReturn(lbb);
141+
142+
Binder binder = unit.get(Binder.class);
143+
expect(binder.bind(Key.get(String.class, Names.named("application.banner")))).andReturn(lbb);
144+
};
145+
}
124146
}

jooby/src/main/java/org/jooby/Route.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,8 @@ public Collection map(final Mapper<?> mapper) {
10081008
class Definition implements Props<Definition> {
10091009

10101010
private static final SourceProvider SRC = SourceProvider.DEFAULT_INSTANCE
1011-
.plusSkippedClasses(Definition.class, Jooby.class, Collection.class, Group.class);
1011+
.plusSkippedClasses(Definition.class, Jooby.class, Collection.class, Group.class,
1012+
javaslang.collection.List.class, Routes.class);
10121013

10131014
/**
10141015
* Route's name.
@@ -1173,6 +1174,15 @@ public boolean glob() {
11731174
return cpattern.glob();
11741175
}
11751176

1177+
/**
1178+
* Source information (where the route was defined).
1179+
*
1180+
* @return Source information (where the route was defined).
1181+
*/
1182+
public Route.Source source() {
1183+
return new RouteSourceImpl(declaringClass, line);
1184+
}
1185+
11761186
/**
11771187
* Recreate a route path and apply the given variables.
11781188
*
@@ -2229,7 +2239,9 @@ static String normalize(final String path) {
22292239
}
22302240

22312241
/**
2232-
* @return Source information.
2242+
* Source information (where the route was defined).
2243+
*
2244+
* @return Source information (where the route was defined).
22332245
*/
22342246
Route.Source source();
22352247

jooby/src/main/java/org/jooby/WebSocket.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,13 @@ class Definition {
279279
* Defines the media types that the methods of a resource class or can consumes. Default is:
280280
* {@literal *}/{@literal *}.
281281
*/
282-
private MediaType consumes = MediaType.all;
282+
private MediaType consumes = MediaType.plain;
283283

284284
/**
285285
* Defines the media types that the methods of a resource class or can produces. Default is:
286286
* {@literal *}/{@literal *}.
287287
*/
288-
private MediaType produces = MediaType.all;
288+
private MediaType produces = MediaType.plain;
289289

290290
/** A path pattern. */
291291
private String pattern;

jooby/src/main/java/org/jooby/internal/WebSocketImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void connect(final Injector injector, final Request req, final NativeWebS
151151

152152
ws.onTextMessage(message -> Try
153153
.run(() -> messageCallback.invoke(
154-
new MutantImpl(injector.getInstance(ParserExecutor.class),
154+
new MutantImpl(injector.getInstance(ParserExecutor.class), consumes,
155155
new StrParamReferenceImpl("body", "message", ImmutableList.of(message)))))
156156
.onFailure(this::handleErr));
157157

jooby/src/test/java/org/jooby/RouteDefinitionTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ public void attrs() throws Exception {
316316
assertEquals(Route.class, r.attr("type"));
317317
}
318318

319+
@Test
320+
public void src() throws Exception {
321+
Function<String, Route.Definition> route = path -> new Route.Definition("*", path, () -> null);
322+
Route.Definition r = route.apply("/");
323+
324+
assertEquals("org.jooby.RouteDefinitionTest:321", r.source().toString());
325+
}
326+
319327
@Test
320328
public void glob() throws Exception {
321329
Function<String, Route.Definition> route = path -> new Route.Definition("*", path, () -> null);

jooby/src/test/java/org/jooby/WebSocketDefinitionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public void toStr() {
1313
});
1414

1515
assertEquals("WS /pattern\n" +
16-
" consume: */*\n" +
17-
" produces: */*\n", def.toString());
16+
" consume: text/plain\n" +
17+
" produces: text/plain\n", def.toString());
1818
}
1919

2020
@Test

jooby/src/test/java/org/jooby/internal/AppPrinterTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void print() {
3232
" GET {complete}/ [*/*] [*/*] (/anonymous)\n" +
3333
" GET / [*/*] [*/*] (/anonymous)\n" +
3434
" GET /home [*/*] [*/*] (/anonymous)\n" +
35-
" WS /ws [*/*] [*/*]\n" +
35+
" WS /ws [text/plain] [text/plain]\n" +
3636
"\n" +
3737
"listening on:\n" +
3838
" http://localhost:8080/", setup);
@@ -58,11 +58,11 @@ public void printHttps() {
5858
.toString();
5959
assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" +
6060
" GET /home [*/*] [*/*] (/anonymous)\n" +
61-
" WS /ws [*/*] [*/*]\n" +
61+
" WS /ws [text/plain] [text/plain]\n" +
6262
"\n" +
63-
"listening on:" +
64-
"\n http://localhost:8080/" +
65-
"\n https://localhost:8443/", setup);
63+
"listening on:\n" +
64+
" http://localhost:8080/\n" +
65+
" https://localhost:8443/", setup);
6666
}
6767

6868
@Test
@@ -76,11 +76,11 @@ public void printHttp2() {
7676
.toString();
7777
assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" +
7878
" GET /home [*/*] [*/*] (/anonymous)\n" +
79-
" WS /ws [*/*] [*/*]\n" +
79+
" WS /ws [text/plain] [text/plain]\n" +
8080
"\n" +
81-
"listening on:" +
82-
"\n http://localhost:8080/ +h2" +
83-
"\n https://localhost:8443/ +h2", setup);
81+
"listening on:\n" +
82+
" http://localhost:8080/ +h2\n" +
83+
" https://localhost:8443/ +h2", setup);
8484
}
8585

8686
@Test
@@ -95,11 +95,11 @@ public void printHttp2Https() {
9595
.toString();
9696
assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" +
9797
" GET /home [*/*] [*/*] (/anonymous)\n" +
98-
" WS /ws [*/*] [*/*]\n" +
98+
" WS /ws [text/plain] [text/plain]\n" +
9999
"\n" +
100-
"listening on:" +
101-
"\n http://localhost:8080/" +
102-
"\n https://localhost:8443/ +h2", setup);
100+
"listening on:\n" +
101+
" http://localhost:8080/\n" +
102+
" https://localhost:8443/ +h2", setup);
103103
}
104104

105105
@Test
@@ -113,10 +113,10 @@ public void printHttp2ClearText() {
113113
.toString();
114114
assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" +
115115
" GET /home [*/*] [*/*] (/anonymous)\n" +
116-
" WS /ws [*/*] [*/*]\n" +
116+
" WS /ws [text/plain] [text/plain]\n" +
117117
"\n" +
118-
"listening on:" +
119-
"\n http://localhost:8080/ +h2", setup);
118+
"listening on:\n" +
119+
" http://localhost:8080/ +h2", setup);
120120
}
121121

122122
private Config config(final String path) {
@@ -136,7 +136,7 @@ public void printWithPath() {
136136
.toString();
137137
assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" +
138138
" GET /home [*/*] [*/*] (/anonymous)\n" +
139-
" WS /ws [*/*] [*/*]\n" +
139+
" WS /ws [text/plain] [text/plain]\n" +
140140
"\n" +
141141
"listening on:\n" +
142142
" http://localhost:8080/app", setup);

0 commit comments

Comments
 (0)