Skip to content

Commit b10cec0

Browse files
direct dependencies update
1 parent a73f135 commit b10cec0

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@
120120
<!-- <version>4.5.13</version>-->
121121
<!-- <scope>compile</scope>-->
122122
<!-- </dependency>-->
123+
124+
<dependency>
125+
<groupId>org.springframework</groupId>
126+
<artifactId>spring-web</artifactId>
127+
<version>5.3.20</version>
128+
</dependency>
123129
</dependencies>
124130

125131
<build>

src/main/java/com/contentstack/utils/presets/Preset.java

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.contentstack.utils.presets;
22

3-
import org.apache.http.client.utils.URIBuilder;
43
import org.jetbrains.annotations.NotNull;
54
import org.json.simple.JSONArray;
65
import org.json.simple.JSONObject;
6+
import org.springframework.web.util.UriComponentsBuilder;
77

8-
import java.net.MalformedURLException;
9-
import java.net.URISyntaxException;
108
import java.util.List;
119
import java.util.concurrent.atomic.AtomicReference;
1210

@@ -26,17 +24,12 @@ public String resolvePresetByPresetName(
2624
}
2725
List<JSONObject> presetOptionKEYS = extractMetadata(localExtensionUid, presetName, "name");
2826
String assetUrl = (String) asset.get(URL);
29-
try {
30-
assetUrl = findPresetOptions(presetOptionKEYS, assetUrl);
31-
} catch (MalformedURLException | URISyntaxException e) {
32-
throw new InvalidUrlException(e.getLocalizedMessage());
33-
}
27+
assetUrl = findPresetOptions(presetOptionKEYS, assetUrl);
3428

3529
return assetUrl;
3630
}
3731

38-
String findPresetOptions(List<JSONObject> presetOptionKEYS, String assetUrl)
39-
throws MalformedURLException, URISyntaxException {
32+
String findPresetOptions(List<JSONObject> presetOptionKEYS, String assetUrl) {
4033
AtomicReference<JSONObject> optionsJson = new AtomicReference<>();
4134
if (!presetOptionKEYS.isEmpty()) {
4235
presetOptionKEYS.forEach(options -> {
@@ -64,63 +57,63 @@ public String resolvePresetByPresetUID(
6457
return assetUrl;
6558
}
6659

67-
private String getImageURL(String assetUrl, JSONObject optionKEYS)
68-
throws URISyntaxException, MalformedURLException {
69-
URIBuilder uriBuilder = new URIBuilder(assetUrl);
60+
private String getImageURL(String assetUrl, @NotNull JSONObject optionKEYS) {
61+
UriComponentsBuilder urlBuilder = UriComponentsBuilder
62+
.fromUriString(assetUrl);
7063
if (optionKEYS.containsKey(TRANSFORM)) {
7164
JSONObject transform = (JSONObject) optionKEYS.get(Constant.TRANSFORM);
72-
getTransformParam(uriBuilder, transform);
65+
getTransformParam(urlBuilder, transform);
7366
}
7467
if (optionKEYS.containsKey(IMAGE_TYPE)) {
7568
String imageType = (String) optionKEYS.get(Constant.IMAGE_TYPE);
76-
uriBuilder.addParameter("format", imageType);
69+
urlBuilder.queryParam("format", imageType);
7770
}
7871
if (optionKEYS.containsKey(QUALITY)) {
7972
String quality = (String) optionKEYS.get(Constant.QUALITY);
80-
uriBuilder.addParameter(Constant.QUALITY, quality);
73+
urlBuilder.queryParam(Constant.QUALITY, quality);
8174
}
8275
if (optionKEYS.containsKey(EFFECTS)) {
8376
JSONObject effects = (JSONObject) optionKEYS.get(Constant.EFFECTS);
84-
getEffectsParams(uriBuilder, effects);
77+
getEffectsParams(urlBuilder, effects);
8578
}
86-
return uriBuilder.build().toURL().toString();
79+
return urlBuilder.build().encode().toUriString();
8780
}
8881

89-
private void getTransformParam(URIBuilder uriBuilder, JSONObject transform) {
82+
private void getTransformParam(UriComponentsBuilder uriBuilder, JSONObject transform) {
9083
if (transform.containsKey(HEIGHT)) {
9184
Object height = transform.get(Constant.HEIGHT);
92-
uriBuilder.addParameter(Constant.HEIGHT, height.toString());
85+
uriBuilder.queryParam(Constant.HEIGHT, height.toString());
9386
}
9487
if (transform.containsKey(WIDTH)) {
9588
Object width = transform.get(Constant.WIDTH);
96-
uriBuilder.addParameter(Constant.WIDTH, width.toString());
89+
uriBuilder.queryParam(Constant.WIDTH, width.toString());
9790
}
9891
if (transform.containsKey(FLIP_MODE)) {
9992
String flipMode = (String) transform.get(Constant.FLIP_MODE);
10093
if (flipMode.equalsIgnoreCase("both")) {
101-
uriBuilder.addParameter(ORIENT, "3");
94+
uriBuilder.queryParam(ORIENT, "3");
10295
}
10396
if (flipMode.equalsIgnoreCase("horiz")) {
104-
uriBuilder.addParameter(ORIENT, "2");
97+
uriBuilder.queryParam(ORIENT, "2");
10598
}
10699
if (flipMode.equalsIgnoreCase("verti")) {
107-
uriBuilder.addParameter(ORIENT, "4");
100+
uriBuilder.queryParam(ORIENT, "4");
108101
}
109102
}
110103
}
111104

112-
private void getEffectsParams(URIBuilder uriBuilder, JSONObject effects) {
105+
private void getEffectsParams(UriComponentsBuilder uriBuilder, JSONObject effects) {
113106
if (effects.containsKey(BRIGHTNESS)) {
114-
uriBuilder.addParameter(BRIGHTNESS, effects.get(Constant.BRIGHTNESS).toString());
107+
uriBuilder.queryParam(BRIGHTNESS, effects.get(Constant.BRIGHTNESS).toString());
115108
}
116109
if (effects.containsKey(CONTRAST)) {
117-
uriBuilder.addParameter(CONTRAST, effects.get(Constant.CONTRAST).toString());
110+
uriBuilder.queryParam(CONTRAST, effects.get(Constant.CONTRAST).toString());
118111
}
119112
if (effects.containsKey(SHARPEN)) {
120-
uriBuilder.addParameter("saturation", effects.get("saturation").toString());
113+
uriBuilder.queryParam("saturation", effects.get("saturation").toString());
121114
}
122115
if (effects.containsKey(BLUR)) {
123-
uriBuilder.addParameter(BLUR, effects.get(Constant.BLUR).toString());
116+
uriBuilder.queryParam(BLUR, effects.get(Constant.BLUR).toString());
124117
}
125118
}
126119

src/test/java/com/contentstack/utils/preset/PresetTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void testResolvePresetByPresetName() throws Exception {
9191
}
9292

9393
@Test
94-
public void testResolvePresetByPresetNameWithUrlQuestionMark() throws Exception {
94+
public void testResolvePresetByPresetNameWithUrlQuestionMark() {
9595
JSONObject assetWithQuestionMarkJson = readJson("management/asset_with_question_mark.json");
9696
String url = preset.resolvePresetByPresetName(assetWithQuestionMarkJson, "theExtensionUid", "Local Preset");
9797
Assert.assertEquals(
@@ -123,7 +123,7 @@ public void testResolvePresetBy() {
123123
String url = preset.resolvePresetByPresetUID(assetWithQuestionMarkJson, "theExtensionUid",
124124
"the_fake_preset_uid");
125125
Assert.assertEquals(
126-
"http://localhost:8000/v3/assets/crop_area.jpeg?format=jpeg&quality=100&height=412&width=500&format=jpeg&quality=10",
126+
"http://localhost:8000/v3/assets/crop_area.jpeg?format=jpeg&quality=100",
127127
url);
128128
}
129129

0 commit comments

Comments
 (0)