Skip to content

Commit 88447e5

Browse files
committed
Add first cut of SockJS server support
1 parent 30ab595 commit 88447e5

File tree

57 files changed

+3220
-50
lines changed

Some content is hidden

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

57 files changed

+3220
-50
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,9 @@ project("spring-websocket") {
526526

527527
optional("org.eclipse.jetty:jetty-websocket:8.1.10.v20130312")
528528
optional("org.glassfish.tyrus:tyrus-websocket-core:1.0-SNAPSHOT")
529+
530+
optional("com.fasterxml.jackson.core:jackson-databind:2.0.1")
531+
529532
}
530533

531534
repositories {

spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.io.InputStream;
2121

22+
import org.springframework.http.Cookies;
2223
import org.springframework.http.HttpHeaders;
2324
import org.springframework.http.HttpInputMessage;
2425
import org.springframework.util.Assert;
@@ -35,6 +36,8 @@ public class MockHttpInputMessage implements HttpInputMessage {
3536

3637
private final InputStream body;
3738

39+
private final Cookies cookies = new Cookies();
40+
3841

3942
public MockHttpInputMessage(byte[] contents) {
4043
this.body = (contents != null) ? new ByteArrayInputStream(contents) : null;
@@ -53,4 +56,8 @@ public InputStream getBody() throws IOException {
5356
return this.body;
5457
}
5558

59+
@Override
60+
public Cookies getCookies() {
61+
return this.cookies ;
62+
}
5663
}

spring-test/src/main/java/org/springframework/mock/http/MockHttpOutputMessage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.UnsupportedEncodingException;
2222
import java.nio.charset.Charset;
2323

24+
import org.springframework.http.Cookies;
2425
import org.springframework.http.HttpHeaders;
2526
import org.springframework.http.HttpOutputMessage;
2627

@@ -38,6 +39,7 @@ public class MockHttpOutputMessage implements HttpOutputMessage {
3839

3940
private final ByteArrayOutputStream body = new ByteArrayOutputStream();
4041

42+
private final Cookies cookies = new Cookies();
4143

4244
/**
4345
* Return the headers.
@@ -83,4 +85,9 @@ public String getBodyAsString(Charset charset) {
8385
}
8486
}
8587

88+
@Override
89+
public Cookies getCookies() {
90+
return this.cookies;
91+
}
92+
8693
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.http;
17+
18+
19+
public interface Cookie {
20+
21+
String getName();
22+
23+
String getValue();
24+
25+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.http;
17+
18+
import java.util.ArrayList;
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
23+
public class Cookies {
24+
25+
private final List<Cookie> cookies;
26+
27+
28+
public Cookies() {
29+
this.cookies = new ArrayList<Cookie>();
30+
}
31+
32+
private Cookies(Cookies cookies) {
33+
this.cookies = Collections.unmodifiableList(cookies.getCookies());
34+
}
35+
36+
public static Cookies readOnlyCookies(Cookies cookies) {
37+
return new Cookies(cookies);
38+
}
39+
40+
public List<Cookie> getCookies() {
41+
return this.cookies;
42+
}
43+
44+
public Cookie getCookie(String name) {
45+
for (Cookie c : this.cookies) {
46+
if (c.getName().equals(name)) {
47+
return c;
48+
}
49+
}
50+
return null;
51+
}
52+
53+
public Cookie addCookie(String name, String value) {
54+
DefaultCookie cookie = new DefaultCookie(name, value);
55+
this.cookies.add(cookie);
56+
return cookie;
57+
}
58+
59+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.http;
17+
18+
import org.springframework.util.Assert;
19+
20+
public class DefaultCookie implements Cookie {
21+
22+
private final String name;
23+
24+
private final String value;
25+
26+
DefaultCookie(String name, String value) {
27+
Assert.hasText(name, "cookie name must not be empty");
28+
this.name = name;
29+
this.value = value;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public String getValue() {
37+
return value;
38+
}
39+
40+
}

spring-web/src/main/java/org/springframework/http/HttpMessage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ public interface HttpMessage {
3131
*/
3232
HttpHeaders getHeaders();
3333

34+
/**
35+
* TODO ..
36+
*/
37+
Cookies getCookies();
38+
3439
}

spring-web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.io.OutputStream;
2121

22+
import org.springframework.http.Cookies;
2223
import org.springframework.http.HttpHeaders;
2324
import org.springframework.util.Assert;
2425

@@ -44,6 +45,11 @@ public final OutputStream getBody() throws IOException {
4445
return getBodyInternal(this.headers);
4546
}
4647

48+
public Cookies getCookies() {
49+
// TODO
50+
throw new UnsupportedOperationException();
51+
}
52+
4753
public final ClientHttpResponse execute() throws IOException {
4854
checkExecuted();
4955
ClientHttpResponse result = executeInternal(this.headers);

spring-web/src/main/java/org/springframework/http/client/AbstractClientHttpResponse.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020

21+
import org.springframework.http.Cookies;
2122
import org.springframework.http.HttpStatus;
2223

2324
/**
@@ -32,4 +33,9 @@ public HttpStatus getStatusCode() throws IOException {
3233
return HttpStatus.valueOf(getRawStatusCode());
3334
}
3435

36+
public Cookies getCookies() {
37+
// TODO
38+
throw new UnsupportedOperationException();
39+
}
40+
3541
}

spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
package org.springframework.http.client;
1818

1919
import java.io.IOException;
20-
import java.io.OutputStream;
2120
import java.net.URI;
2221

22+
import org.springframework.http.Cookies;
2323
import org.springframework.http.HttpHeaders;
2424
import org.springframework.http.HttpMethod;
2525
import org.springframework.util.Assert;
@@ -58,4 +58,9 @@ protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] buffere
5858
return new BufferingClientHttpResponseWrapper(response);
5959
}
6060

61+
@Override
62+
public Cookies getCookies() {
63+
return this.request.getCookies();
64+
}
65+
6166
}

0 commit comments

Comments
 (0)