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

Commit 653f7df

Browse files
japodGerrit Code Review
authored andcommitted
Merge changes I6f82acbd,I7a6149c5
* changes: Added some delay to multipart tests to make sure temporary files are properly deleted. Fixed copyrights + few other minor improvements.
2 parents f157d1a + f37ae88 commit 653f7df

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

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

Lines changed: 29 additions & 32 deletions
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-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2015 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
@@ -68,29 +68,29 @@ public class LinkProvider implements HeaderDelegateProvider<Link> {
6868
private static final Logger LOGGER = Logger.getLogger(LinkProvider.class.getName());
6969

7070
@Override
71-
public boolean supports(Class<?> type) {
71+
public boolean supports(final Class<?> type) {
7272
return Link.class.isAssignableFrom(type);
7373
}
7474

7575
@Override
76-
public Link fromString(String value) throws IllegalArgumentException {
76+
public Link fromString(final String value) throws IllegalArgumentException {
7777
return initBuilder(new JerseyLink.Builder(), value).build();
7878
}
7979

8080
/**
8181
* Initialize an existing Jersey link builder with the link data provided in a form of a string.
8282
*
83-
* @param lb link builder to be initialized.
83+
* @param lb link builder to be initialized.
8484
* @param value link data as a string.
8585
* @return initialized link builder.
8686
*/
8787
static JerseyLink.Builder initBuilder(JerseyLink.Builder lb, String value) {
8888
throwIllegalArgumentExceptionIfNull(value, LocalizationMessages.LINK_IS_NULL());
8989
try {
9090
value = value.trim();
91-
String params;
91+
final String params;
9292
if (value.startsWith("<")) {
93-
int gtIndex = value.indexOf('>');
93+
final int gtIndex = value.indexOf('>');
9494
if (gtIndex != -1) {
9595
lb.uri(value.substring(1, gtIndex).trim());
9696
params = value.substring(gtIndex + 1).trim();
@@ -100,23 +100,22 @@ static JerseyLink.Builder initBuilder(JerseyLink.Builder lb, String value) {
100100
} else {
101101
throw new IllegalArgumentException("Missing starting token < in " + value);
102102
}
103-
if (params != null) {
104-
StringTokenizer st = new StringTokenizer(params, ";=\"", true);
105-
while (st.hasMoreTokens()) {
106-
checkToken(st, ";");
107-
String n = st.nextToken().trim();
108-
checkToken(st, "=");
109-
110-
String v = nextNonEmptyToken(st);
111-
if (v.equals("\"")) {
112-
v = st.nextToken();
113-
checkToken(st, "\"");
114-
}
115-
116-
lb.param(n, v);
103+
104+
final StringTokenizer st = new StringTokenizer(params, ";=\"", true);
105+
while (st.hasMoreTokens()) {
106+
checkToken(st, ";");
107+
final String n = st.nextToken().trim();
108+
checkToken(st, "=");
109+
110+
String v = nextNonEmptyToken(st);
111+
if (v.equals("\"")) {
112+
v = st.nextToken();
113+
checkToken(st, "\"");
117114
}
115+
116+
lb.param(n, v);
118117
}
119-
} catch (Throwable e) {
118+
} catch (final Throwable e) {
120119
if (LOGGER.isLoggable(Level.FINER)) {
121120
LOGGER.log(Level.FINER, "Error parsing link value '" + value + "'", e);
122121
}
@@ -128,18 +127,16 @@ static JerseyLink.Builder initBuilder(JerseyLink.Builder lb, String value) {
128127
return lb;
129128
}
130129

131-
private static String nextNonEmptyToken(StringTokenizer st) throws IllegalArgumentException {
132-
String token = null;
130+
private static String nextNonEmptyToken(final StringTokenizer st) throws IllegalArgumentException {
131+
String token;
133132
do {
134133
token = st.nextToken().trim();
135134
} while (token.length() == 0);
136-
if (token == null) {
137-
throw new IllegalArgumentException("Non-Empty token not found");
138-
}
135+
139136
return token;
140137
}
141138

142-
private static void checkToken(StringTokenizer st, String expected) throws IllegalArgumentException {
139+
private static void checkToken(final StringTokenizer st, final String expected) throws IllegalArgumentException {
143140
String token;
144141
do {
145142
token = st.nextToken().trim();
@@ -150,7 +147,7 @@ private static void checkToken(StringTokenizer st, String expected) throws Illeg
150147
}
151148

152149
@Override
153-
public String toString(Link value) {
150+
public String toString(final Link value) {
154151
return stringfy(value);
155152
}
156153

@@ -160,14 +157,14 @@ public String toString(Link value) {
160157
* @param value link instance to be stringified.
161158
* @return string version of a given link instance.
162159
*/
163-
static String stringfy(Link value) {
160+
static String stringfy(final Link value) {
164161
throwIllegalArgumentExceptionIfNull(value, LocalizationMessages.LINK_IS_NULL());
165162

166-
Map<String, String> map = value.getParams();
167-
StringBuilder sb = new StringBuilder();
163+
final Map<String, String> map = value.getParams();
164+
final StringBuilder sb = new StringBuilder();
168165
sb.append('<').append(value.getUri()).append('>');
169166

170-
for (Map.Entry<String, String> entry : map.entrySet()) {
167+
for (final Map.Entry<String, String> entry : map.entrySet()) {
171168
sb.append("; ").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
172169
}
173170
return sb.toString();

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

Lines changed: 10 additions & 10 deletions
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) 2011-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2011-2015 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
@@ -68,7 +68,7 @@ public void tearDown() throws Exception {
6868

6969
@Test
7070
public void testValueOf() {
71-
Link l1 = Link.fromUri("http://example.org/app/link1").build();
71+
final Link l1 = Link.fromUri("http://example.org/app/link1").build();
7272
Link l2 = Link.valueOf("<http://example.org/app/link1>");
7373
assertEquals(l1, l2);
7474
l2 = Link.valueOf(" <http://example.org/app/link1>");
@@ -82,25 +82,25 @@ public void testValueOfExceptions() {
8282
int nOfExceptions = 0;
8383
try {
8484
Link.valueOf("http://example.org/app/link1>");
85-
} catch (IllegalArgumentException e) {
85+
} catch (final IllegalArgumentException e) {
8686
nOfExceptions++;
8787
}
8888
try {
8989
Link.valueOf("<http://example.org/app/link1");
90-
} catch (IllegalArgumentException e) {
90+
} catch (final IllegalArgumentException e) {
9191
nOfExceptions++;
9292
}
9393
try {
9494
Link.valueOf("http://example.org/app/link1");
95-
} catch (IllegalArgumentException e) {
95+
} catch (final IllegalArgumentException e) {
9696
nOfExceptions++;
9797
}
9898
assertEquals(nOfExceptions, 3);
9999
}
100100

101101
@Test
102102
public void testValueOfParams() {
103-
Link l1 = Link.fromUri("http://example.org/app/link1").param("foo1", "bar1").param("foo2", "bar2").build();
103+
final Link l1 = Link.fromUri("http://example.org/app/link1").param("foo1", "bar1").param("foo2", "bar2").build();
104104
Link l2 = Link.valueOf("<http://example.org/app/link1>; foo1=\"bar1\"; foo2 = \"bar2\"");
105105
assertEquals(l1, l2);
106106
l2 = Link.valueOf("<http://example.org/app/link1>; foo2=\"bar2\"; foo1= \"bar1\"");
@@ -113,17 +113,17 @@ public void testValueOfParams() {
113113

114114
@Test
115115
public void testRoundTrip() {
116-
Link l1 = Link.fromUri("http://example.org/app/link1").param("foo1", "bar1").param("foo2", "bar2").build();
116+
final Link l1 = Link.fromUri("http://example.org/app/link1").param("foo1", "bar1").param("foo2", "bar2").build();
117117
assertEquals(l1, Link.valueOf(l1.toString()));
118-
Link l2 = Link.valueOf("<http://example.org/app/link1>; foo1=\"bar1\"; foo2 = \"bar2\"");
118+
final Link l2 = Link.valueOf("<http://example.org/app/link1>; foo1=\"bar1\"; foo2 = \"bar2\"");
119119
assertEquals(l1, l2);
120120
}
121121

122122
@Test
123123
public void testWithoutDoubleQuotes() {
124-
Link l1 = Link.fromUri("http://example.org/app/link1").param("foo1", "bar1").param("foo2", "bar2").build();
124+
final Link l1 = Link.fromUri("http://example.org/app/link1").param("foo1", "bar1").param("foo2", "bar2").build();
125125
assertEquals(l1, Link.valueOf(l1.toString()));
126-
Link l2 = Link.valueOf("<http://example.org/app/link1>; foo1=bar1; foo2 = bar2");
126+
final Link l2 = Link.valueOf("<http://example.org/app/link1>; foo1=bar1; foo2 = bar2");
127127
assertEquals(l1, l2);
128128
}
129129
}

media/multipart/src/test/java/org/glassfish/jersey/media/multipart/internal/FormDataMultiPartReaderWriterTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,9 @@ public void testInjectedFileNotCopied(@Mocked final BodyPartEntity entity) throw
706706

707707
// Make sure that the temp file has been removed.
708708
final String pathname = response.readEntity(String.class);
709+
// Wait a second to make sure the file doesn't exist.
710+
Thread.sleep(1000);
711+
709712
assertThat("Temporary file, " + pathname + ", on the server has not been removed",
710713
new File(pathname).exists(), is(false));
711714
}
@@ -726,6 +729,9 @@ public void tempFileDeletedAfterSuccessfulProcessing() throws Exception {
726729

727730
// Make sure that the temp file has been removed.
728731
final String pathname = response.readEntity(String.class);
732+
// Wait a second to make sure the file doesn't exist.
733+
Thread.sleep(1000);
734+
729735
assertThat("Temporary file, " + pathname + ", on the server has not been removed",
730736
new File(pathname).exists(), is(false));
731737
}
@@ -746,6 +752,9 @@ public void tempFileDeletedAfterExceptionInMethod() throws Exception {
746752

747753
// Make sure that the temp file has been removed.
748754
final String pathname = response.readEntity(String.class);
755+
// Wait a second to make sure the file doesn't exist.
756+
Thread.sleep(1000);
757+
749758
assertThat("Temporary file, " + pathname + ", on the server has not been removed",
750759
new File(pathname).exists(), is(false));
751760
}

tests/integration/jersey-2846/src/test/java/org/glassfish/jersey/tests/integration/jersey2846/Jersey2846ITCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public void _test(final String path, final int status, final Object entity) thro
138138

139139
// Get Response ...
140140
assertThat(response.getStatus(), is(status));
141+
// Wait a second to make sure the files don't exist.
142+
Thread.sleep(1000);
141143

142144
// Make sure that the message and it's parts have been closed and temporary files deleted.
143145
assertThat("Temporary files were not deleted", matchingTempFiles(tempDir), is(expectedTempFiles));

0 commit comments

Comments
 (0)