Skip to content

Commit cd8e46e

Browse files
authored
Merge pull request #107 from wujinhu/json-lib
change test json lib
2 parents 80f53f7 + 0b4071b commit cd8e46e

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The recommended way to use the Aliyun OSS SDK for Java in your project is to con
2424
<dependency>
2525
<groupId>com.aliyun.oss</groupId>
2626
<artifactId>aliyun-sdk-oss</artifactId>
27-
<version>2.8.2</version>
27+
<version>2.8.3</version>
2828
</dependency>
2929
```
3030

pom.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.aliyun.oss</groupId>
1313
<artifactId>aliyun-sdk-oss</artifactId>
14-
<version>2.8.2</version>
14+
<version>2.8.3</version>
1515
<packaging>jar</packaging>
1616
<name>Aliyun OSS SDK for Java</name>
1717
<description>The Aliyun OSS SDK for Java used for accessing Aliyun Object Storage Service</description>
@@ -30,10 +30,16 @@
3030
<version>1.1</version>
3131
</dependency>
3232
<dependency>
33-
<groupId>net.sf.json-lib</groupId>
34-
<artifactId>json-lib</artifactId>
35-
<version>2.4</version>
36-
<classifier>jdk15</classifier>
33+
<groupId>com.sun.jersey</groupId>
34+
<artifactId>jersey-json</artifactId>
35+
<version>1.9</version>
36+
<scope>test</scope>
37+
<exclusions>
38+
<exclusion>
39+
<groupId>stax</groupId>
40+
<artifactId>stax-api</artifactId>
41+
</exclusion>
42+
</exclusions>
3743
</dependency>
3844
<dependency>
3945
<groupId>junit</groupId>

src/test/java/com/aliyun/oss/integrationtests/ImageProcessTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import java.util.Date;
2727

2828
import junit.framework.Assert;
29-
import net.sf.json.JSONObject;
3029

31-
import org.apache.commons.beanutils.PropertyUtils;
30+
import org.codehaus.jettison.json.JSONException;
31+
import org.codehaus.jettison.json.JSONObject;
3232
import org.junit.Test;
3333

3434
import com.aliyun.oss.HttpMethod;
@@ -264,22 +264,20 @@ public void testGeneratePresignedUrlWithProcess() {
264264
}
265265
}
266266

267-
private static ImageInfo getImageInfo(final String bucket, final String image) throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
267+
private static ImageInfo getImageInfo(final String bucket, final String image) throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, JSONException {
268268
GetObjectRequest request = new GetObjectRequest(bucketName, image);
269269
request.setProcess("image/info");
270270
OSSObject ossObject = ossClient.getObject(request);
271271

272272
String jsonStr = IOUtils.readStreamAsString(ossObject.getObjectContent(), "UTF-8");
273273
ossObject.getObjectContent().close();
274274

275-
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
276-
Object bean = JSONObject.toBean(jsonObject);
277-
278-
long height = Long.parseLong((String) PropertyUtils.getProperty(PropertyUtils.getProperty(bean, "ImageHeight"), "value"));
279-
long width = Long.parseLong((String) PropertyUtils.getProperty(PropertyUtils.getProperty(bean, "ImageWidth"), "value"));
280-
long size = Long.parseLong((String) PropertyUtils.getProperty(PropertyUtils.getProperty(bean, "FileSize"), "value"));
281-
String format = (String) PropertyUtils.getProperty(PropertyUtils.getProperty(bean, "Format"), "value");
282-
275+
JSONObject jsonObject = new JSONObject(jsonStr);
276+
277+
long height = jsonObject.getJSONObject("ImageHeight").getLong("value");
278+
long width = jsonObject.getJSONObject("ImageWidth").getLong("value");
279+
long size = jsonObject.getJSONObject("FileSize").getLong("value");
280+
String format = jsonObject.getJSONObject("Format").getString("value");
283281
return new ImageInfo(height, width, size, format);
284282
}
285283

src/test/java/com/aliyun/oss/integrationtests/SecurityTokenTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import junit.framework.Assert;
3434

35+
import org.codehaus.jettison.json.JSONException;
3536
import org.junit.Ignore;
3637
import org.junit.Test;
3738

@@ -72,7 +73,7 @@ public class SecurityTokenTest {
7273

7374
@SuppressWarnings("deprecation")
7475
@Test
75-
public void testBucketOperationsWithToken() {
76+
public void testBucketOperationsWithToken() throws JSONException {
7677
List<String> actions = new ArrayList<String>();
7778
actions.add("oss:ListBuckets");
7879
List<String> resources = new ArrayList<String>();
@@ -417,7 +418,7 @@ public void testBucketOperationsWithToken() {
417418
}
418419

419420
@Test
420-
public void testObjectOperationsWithToken() {
421+
public void testObjectOperationsWithToken() throws JSONException {
421422
List<String> actions = new ArrayList<String>();
422423
List<String> resources = new ArrayList<String>();
423424

src/test/java/com/aliyun/oss/integrationtests/TestUtils.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import javax.net.ssl.X509TrustManager;
4444

4545
import junit.framework.Assert;
46-
import net.sf.json.JSONArray;
47-
import net.sf.json.JSONObject;
4846

4947
import org.apache.http.HttpResponse;
5048
import org.apache.http.NameValuePair;
@@ -65,6 +63,9 @@
6563
import com.aliyun.oss.model.InitiateMultipartUploadRequest;
6664
import com.aliyun.oss.model.InitiateMultipartUploadResult;
6765
import com.aliyun.oss.model.PartETag;
66+
import org.codehaus.jettison.json.JSONArray;
67+
import org.codehaus.jettison.json.JSONException;
68+
import org.codehaus.jettison.json.JSONObject;
6869

6970
@SuppressWarnings("deprecation")
7071
public class TestUtils {
@@ -342,21 +343,21 @@ public void setSecurityToken(String securityToken) {
342343
}
343344
}
344345

345-
public static OSSClient createSessionClient(List<String> actions, List<String> resources) {
346+
public static OSSClient createSessionClient(List<String> actions, List<String> resources) throws JSONException {
346347
String tokenPolicy = jsonizeTokenPolicy(actions, resources, true);
347348
StsToken token = getStsToken("", "", 3600, tokenPolicy);
348349
return new OSSClient(OSS_TEST_ENDPOINT, token.accessKeyId, token.secretAccessKey, token.securityToken,
349350
new ClientConfiguration().setSupportCname(false));
350351
}
351352

352-
public static String jsonizeTokenPolicy(List<String> actions, List<String> resources, boolean allow) {
353+
public static String jsonizeTokenPolicy(List<String> actions, List<String> resources, boolean allow) throws JSONException {
353354
JSONObject stmtJsonObject = new JSONObject();
354355
stmtJsonObject.put("Action", actions);
355356
stmtJsonObject.put("Resource", resources);
356357
stmtJsonObject.put("Effect", allow ? "Allow" : "Deny");
357358

358359
JSONArray stmtJsonArray = new JSONArray();
359-
stmtJsonArray.add(0, stmtJsonObject);
360+
stmtJsonArray.put(0, stmtJsonObject);
360361

361362
JSONObject policyJsonObject = new JSONObject();
362363
policyJsonObject.put("Version", "1");
@@ -401,7 +402,7 @@ public static StsToken getStsToken(String grantor, String grantee,
401402
System.out.println(line);
402403
}
403404

404-
JSONObject tokenJsonObject = JSONObject.fromObject(tokenString.toString());
405+
JSONObject tokenJsonObject = new JSONObject(tokenString.toString());
405406
JSONObject credsJsonObjson = tokenJsonObject.getJSONObject("Credentials");
406407
String accessKeyId = credsJsonObjson.getString("AccessKeyId");
407408
String secretAccessKey = credsJsonObjson.getString("AccessKeySecret");

0 commit comments

Comments
 (0)