Skip to content

Commit ab20c6d

Browse files
committed
fix: update encoding header handling in DsnGet and add corresponding test
Signed-off-by: Kasper Helsted <helsted@vopu.dk>
1 parent 5b26c38 commit ab20c6d

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/main/java/zowe/client/sdk/zosfiles/dsn/methods/DsnGet.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ public InputStream get(final String targetName, final DsnDownloadInputData downl
139139
value = ZosmfHeaders.HEADERS.get("X_IBM_BINARY").get(1);
140140
headers.put(key, value);
141141
} else if (downloadInputData.getEncoding().isPresent()) {
142-
key = ZosmfHeaders.X_IBM_TEXT;
143-
value = ZosmfHeaders.X_IBM_TEXT + ZosmfHeaders.X_IBM_TEXT_ENCODING + downloadInputData.getEncoding();
142+
key = ZosmfHeaders.HEADERS.get("X_IBM_TEXT").get(0);
143+
value = String.format("%s%sIBM-%s",
144+
ZosmfHeaders.HEADERS.get("X_IBM_TEXT").get(1),
145+
ZosmfHeaders.HEADERS.get("X_IBM_TEXT_ENCODING").get(0),
146+
downloadInputData.getEncoding().getAsLong()
147+
);
144148
headers.put(key, value);
145149
}
146150

src/test/java/zowe/client/sdk/zosfiles/dsn/methods/DsnGetTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ public void tstDsnGetTokenWithMultipleParamsSuccess() throws ZosmfRequestExcepti
106106
assertEquals("https://1:443/zosmf/restfiles/ds/TEST.DATASET", mockGetRequestToken.getUrl());
107107
}
108108

109+
@Test
110+
public void tstDsnGetTokenWithOnlyEncodingParamsSuccess() throws ZosmfRequestException, IOException {
111+
final DsnGet dsnGet = new DsnGet(connection, mockGetRequestToken);
112+
final DsnDownloadInputData downloadInputData = new DsnDownloadInputData.Builder()
113+
.encoding(1047L)
114+
.build();
115+
final InputStream inputStream = dsnGet.get("TEST.DATASET", downloadInputData);
116+
assertEquals("{X-IBM-Data-Type=text;fileEncoding=IBM-1047, " +
117+
"Accept-Encoding=1047, X-CSRF-ZOSMF-HEADER=true, " +
118+
"Content-Type=application/json}",
119+
mockGetRequestToken.getHeaders().toString());
120+
assertEquals("test data", new String(inputStream.readAllBytes()));
121+
assertEquals("https://1:443/zosmf/restfiles/ds/TEST.DATASET", mockGetRequestToken.getUrl());
122+
}
123+
109124
@Test
110125
public void tstDsnGetTokenWithMultipleParamsWithoutEncodingSuccess() throws ZosmfRequestException, IOException {
111126
final DsnGet dsnGet = new DsnGet(connection, mockGetRequestToken);

0 commit comments

Comments
 (0)