Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 397573f

Browse files
committed
JAX-RS 2.1-m08
Change-Id: Id90b6049b1296cd4b4bfdd01cc882f9897121785
1 parent 67d5865 commit 397573f

File tree

10 files changed

+214
-64
lines changed

10 files changed

+214
-64
lines changed

connectors/jetty-connector/src/test/java/org/glassfish/jersey/jetty/connector/MethodTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void testDeleteAsync() throws ExecutionException, InterruptedException {
164164

165165
@Test
166166
public void testPatch() {
167-
Response response = target(PATH).request().patch(Entity.entity("PATCH", MediaType.TEXT_PLAIN));
167+
Response response = target(PATH).request().method("PATCH", Entity.entity("PATCH", MediaType.TEXT_PLAIN));
168168
assertEquals("PATCH", response.readEntity(String.class));
169169
}
170170
}

core-client/src/main/java/org/glassfish/jersey/client/AbstractRxInvoker.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,6 @@ public <R> T trace(final GenericType<R> responseType) {
186186
return method("TRACE", responseType);
187187
}
188188

189-
@Override
190-
public T patch(final Entity<?> entity) {
191-
return method("PATCH", entity);
192-
}
193-
194-
@Override
195-
public <R> T patch(final Entity<?> entity, Class<R> responseType) {
196-
return method("PATCH", entity, responseType);
197-
}
198-
199-
@Override
200-
public <R> T patch(final Entity<?> entity, GenericType<R> responseType) {
201-
return method("PATCH", entity, responseType);
202-
}
203-
204189
@Override
205190
public T method(final String name) {
206191
return method(name, Response.class);

core-client/src/main/java/org/glassfish/jersey/client/JerseyClientBuilder.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Map;
4444
import java.util.concurrent.ExecutorService;
4545
import java.util.concurrent.ScheduledExecutorService;
46+
import java.util.concurrent.TimeUnit;
4647

4748
import javax.ws.rs.client.ClientBuilder;
4849
import javax.ws.rs.core.Configuration;
@@ -156,6 +157,26 @@ public ClientBuilder scheduledExecutorService(ScheduledExecutorService scheduled
156157
return this;
157158
}
158159

160+
@Override
161+
public ClientBuilder connectTimeout(long timeout, TimeUnit unit) {
162+
if (timeout < 0) {
163+
throw new IllegalArgumentException("Negative timeout.");
164+
}
165+
166+
this.property(ClientProperties.CONNECT_TIMEOUT, Math.toIntExact(unit.toMillis(timeout)));
167+
return this;
168+
}
169+
170+
@Override
171+
public ClientBuilder readTimeout(long timeout, TimeUnit unit) {
172+
if (timeout < 0) {
173+
throw new IllegalArgumentException("Negative timeout.");
174+
}
175+
176+
this.property(ClientProperties.READ_TIMEOUT, Math.toIntExact(unit.toMillis(timeout)));
177+
return this;
178+
}
179+
159180
@Override
160181
public JerseyClient build() {
161182
if (sslContext != null) {

core-client/src/main/java/org/glassfish/jersey/client/JerseyInvocation.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -412,21 +412,6 @@ public <T> T trace(final GenericType<T> responseType) throws ProcessingException
412412
return method("TRACE", responseType);
413413
}
414414

415-
@Override
416-
public Response patch(final Entity<?> entity) {
417-
return method("PATCH", entity);
418-
}
419-
420-
@Override
421-
public <T> T patch(final Entity<?> entity, Class<T> responseType) {
422-
return method("PATCH", entity, responseType);
423-
}
424-
425-
@Override
426-
public <T> T patch(final Entity<?> entity, GenericType<T> responseType) {
427-
return method("PATCH", entity, responseType);
428-
}
429-
430415
@Override
431416
public Response method(final String name) throws ProcessingException {
432417
requestContext.setMethod(name);
@@ -690,27 +675,6 @@ public <T> Future<T> trace(final InvocationCallback<T> callback) {
690675
return method("TRACE", callback);
691676
}
692677

693-
@Override
694-
public Future<Response> patch(final Entity<?> entity) {
695-
return method("PATCH", entity);
696-
}
697-
698-
@Override
699-
public <T> Future<T> patch(final Entity<?> entity, Class<T> responseType) {
700-
return method("PATCH", entity, responseType);
701-
702-
}
703-
704-
@Override
705-
public <T> Future<T> patch(final Entity<?> entity, GenericType<T> responseType) {
706-
return method("PATCH", entity, responseType);
707-
}
708-
709-
@Override
710-
public <T> Future<T> patch(final Entity<?> entity, InvocationCallback<T> callback) {
711-
return method("PATCH", entity, callback);
712-
}
713-
714678
@Override
715679
public Future<Response> method(final String name) {
716680
builder.requestContext.setMethod(name);

core-client/src/test/java/org/glassfish/jersey/client/JerseyClientBuilderTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -43,6 +43,7 @@
4343
import java.security.KeyStore;
4444
import java.security.KeyStoreException;
4545
import java.security.NoSuchAlgorithmException;
46+
import java.util.concurrent.TimeUnit;
4647

4748
import javax.ws.rs.client.Client;
4849
import javax.ws.rs.client.ClientBuilder;
@@ -56,7 +57,9 @@
5657
import javax.net.ssl.SSLContext;
5758

5859
import org.junit.Before;
60+
import org.junit.Rule;
5961
import org.junit.Test;
62+
import org.junit.rules.ExpectedException;
6063
import static org.hamcrest.CoreMatchers.equalTo;
6164
import static org.junit.Assert.assertNotSame;
6265
import static org.junit.Assert.assertSame;
@@ -71,6 +74,9 @@
7174
*/
7275
public class JerseyClientBuilderTest {
7376

77+
@Rule
78+
public final ExpectedException exception = ExpectedException.none();
79+
7480
private JerseyClientBuilder builder;
7581

7682
@Before
@@ -224,4 +230,20 @@ public void _testCreateClientWithAnotherConfig(final boolean clientInFilter) thr
224230
assertThat(response.getStatus(), equalTo(200));
225231
assertThat(response.readEntity(String.class), equalTo("ok"));
226232
}
233+
234+
@Test
235+
public void testNegativeConnectTimeout() {
236+
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
237+
238+
exception.expect(IllegalArgumentException.class);
239+
clientBuilder.connectTimeout(-1, TimeUnit.SECONDS);
240+
}
241+
242+
@Test
243+
public void testNegativeReadTimeout() {
244+
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
245+
246+
exception.expect(IllegalArgumentException.class);
247+
clientBuilder.readTimeout(-1, TimeUnit.SECONDS);
248+
}
227249
}

core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundJaxrsResponse.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,34 @@ public javax.ws.rs.core.Response.ResponseBuilder status(StatusType status) {
406406
return this;
407407
}
408408

409+
@Override
410+
public ResponseBuilder status(int status, final String reasonPhrase) {
411+
if (status < 100 || status > 599) {
412+
throw new IllegalArgumentException("Response status must not be less than '100' or greater than '599'");
413+
}
414+
415+
final Status.Family family = Status.Family.familyOf(status);
416+
417+
this.status = new StatusType() {
418+
@Override
419+
public int getStatusCode() {
420+
return status;
421+
}
422+
423+
@Override
424+
public Status.Family getFamily() {
425+
return family;
426+
}
427+
428+
@Override
429+
public String getReasonPhrase() {
430+
return reasonPhrase;
431+
}
432+
};
433+
434+
return this;
435+
}
436+
409437
@Override
410438
public javax.ws.rs.core.Response.ResponseBuilder status(int code) {
411439
this.status = Statuses.from(code);

core-common/src/test/java/org/glassfish/jersey/message/internal/ResponseTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -45,6 +45,7 @@
4545
import javax.ws.rs.core.Response.Status.Family;
4646
import javax.ws.rs.core.Response.StatusType;
4747

48+
import org.junit.Test;
4849
import static org.junit.Assert.assertEquals;
4950
import static org.junit.Assert.assertNotNull;
5051
import static org.junit.Assert.assertSame;
@@ -55,13 +56,15 @@
5556
*/
5657
public class ResponseTest {
5758

59+
@Test
5860
public void testDeclaredStatusCodes() {
5961
for (Status s : Status.values()) {
6062
StatusType _s = Response.status(s.getStatusCode()).build().getStatusInfo();
6163
assertSame(s, _s);
6264
}
6365
}
6466

67+
@Test
6568
public void testUndeclaredStatusCodes() {
6669
StatusType st = Response.status(199).build().getStatusInfo();
6770
assertNotNull(st);
@@ -93,4 +96,13 @@ public void testUndeclaredStatusCodes() {
9396
assertEquals("", st.getReasonPhrase());
9497
assertEquals(Family.SERVER_ERROR, st.getFamily());
9598
}
99+
100+
@Test
101+
public void reasonPhraseTest() {
102+
Response response = Response.status(123, "test").build();
103+
104+
assertNotNull(response);
105+
assertEquals(123, response.getStatus());
106+
assertEquals("test", response.getStatusInfo().getReasonPhrase());
107+
}
96108
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@
18721872
<jsonb.api.version>1.0.0-M2</jsonb.api.version>
18731873
<jsonb.ri.version>1.0.0-M2</jsonb.ri.version>
18741874
<jaxrs.api.spec.version>2.1</jaxrs.api.spec.version>
1875-
<jaxrs.api.impl.version>2.1-m07</jaxrs.api.impl.version>
1875+
<jaxrs.api.impl.version>2.1-m08</jaxrs.api.impl.version>
18761876
<jboss.logging.version>3.3.0.Final</jboss.logging.version>
18771877
<jersey1.version>1.19.3</jersey1.version>
18781878
<jersey1.last.final.version>${jersey1.version}</jersey1.last.final.version>
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.tests.e2e.client;
42+
43+
import java.net.SocketTimeoutException;
44+
import java.util.concurrent.TimeUnit;
45+
46+
import javax.ws.rs.GET;
47+
import javax.ws.rs.Path;
48+
import javax.ws.rs.ProcessingException;
49+
import javax.ws.rs.client.Client;
50+
import javax.ws.rs.client.ClientBuilder;
51+
import javax.ws.rs.core.Application;
52+
import javax.ws.rs.core.Response;
53+
54+
import org.glassfish.jersey.client.JerseyWebTarget;
55+
import org.glassfish.jersey.server.ResourceConfig;
56+
import org.glassfish.jersey.test.JerseyTest;
57+
58+
import org.junit.Test;
59+
import static org.junit.Assert.assertEquals;
60+
import static org.junit.Assert.fail;
61+
62+
/**
63+
* @author Pavel Bucek (pavel.bucek at oracle.com)
64+
*/
65+
public class JaxRsTimeoutTest extends JerseyTest {
66+
67+
private final Client client =
68+
ClientBuilder.newBuilder().readTimeout(2000, TimeUnit.MILLISECONDS).build();
69+
70+
@Path("/test")
71+
public static class TimeoutResource {
72+
@GET
73+
public String get() {
74+
return "GET";
75+
}
76+
77+
@GET
78+
@Path("timeout")
79+
public String getTimeout() {
80+
try {
81+
Thread.sleep(5000);
82+
} catch (InterruptedException e) {
83+
e.printStackTrace();
84+
}
85+
return "GET";
86+
}
87+
}
88+
89+
@Override
90+
protected Application configure() {
91+
return new ResourceConfig(TimeoutTest.TimeoutResource.class);
92+
}
93+
94+
@Override
95+
protected Client getClient() {
96+
return client;
97+
}
98+
99+
@Test
100+
public void testFast() {
101+
Response r = target("test").request().get();
102+
assertEquals(200, r.getStatus());
103+
assertEquals("GET", r.readEntity(String.class));
104+
}
105+
106+
@Test
107+
public void testSlow() {
108+
try {
109+
target("test/timeout").request().get();
110+
fail("Timeout expected.");
111+
} catch (ProcessingException e) {
112+
if (!(e.getCause() instanceof SocketTimeoutException)) {
113+
e.printStackTrace();
114+
fail();
115+
}
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)