Skip to content

Commit fac2a3c

Browse files
committed
Refactor character encoding method usage
This commit simplifies the usage of character encoding methods. StandardCharsets.UTF_8.name() was replaced by StandardCharsets.UTF_8 in several places. This was done to improve code readability since StandardCharsets.UTF_8.name() and StandardCharsets.UTF_8 essentially do the same thing. Additionally, try-catch block related to encoding in RequestReceiver class has been removed since the encoding method used will not throw an exception, therefore the block was redundant.
1 parent 8d27337 commit fac2a3c

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

eidas-middleware/src/main/java/de/governikus/eumw/eidasmiddleware/controller/RequestReceiver.java

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,33 +176,26 @@ private ModelAndView showErrorPage(String errorMessage)
176176
*/
177177
private ModelAndView showMiddlewarePage(String sessionId, String userAgent)
178178
{
179-
try
179+
String ausweisappLink;
180+
if (isMobileDevice(userAgent))
180181
{
181-
String ausweisappLink;
182-
if (isMobileDevice(userAgent))
183-
{
184-
ausweisappLink = "eid://127.0.0.1:24727/eID-Client?tcTokenURL=";
185-
}
186-
else
187-
{
188-
ausweisappLink = "http://127.0.0.1:24727/eID-Client?tcTokenURL=";
189-
}
190-
ModelAndView modelAndView = new ModelAndView("middleware");
191-
192-
String tcTokenURL = requestHandler.getTcTokenURL(sessionId);
193-
modelAndView.addObject("tcTokenURL", tcTokenURL);
194-
195-
ausweisappLink = ausweisappLink.concat(URLEncoder.encode(tcTokenURL, StandardCharsets.UTF_8.name()));
196-
modelAndView.addObject("ausweisapp", ausweisappLink);
197-
198-
String linkToSelf = ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId=" + sessionId;
199-
modelAndView.addObject("linkToSelf", linkToSelf);
200-
return modelAndView;
182+
ausweisappLink = "eid://127.0.0.1:24727/eID-Client?tcTokenURL=";
201183
}
202-
catch (UnsupportedEncodingException e)
184+
else
203185
{
204-
return showErrorPage(e.getMessage());
186+
ausweisappLink = "http://127.0.0.1:24727/eID-Client?tcTokenURL=";
205187
}
188+
ModelAndView modelAndView = new ModelAndView("middleware");
189+
190+
String tcTokenURL = requestHandler.getTcTokenURL(sessionId);
191+
modelAndView.addObject("tcTokenURL", tcTokenURL);
192+
193+
ausweisappLink = ausweisappLink.concat(URLEncoder.encode(tcTokenURL, StandardCharsets.UTF_8));
194+
modelAndView.addObject("ausweisapp", ausweisappLink);
195+
196+
String linkToSelf = ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId=" + sessionId;
197+
modelAndView.addObject("linkToSelf", linkToSelf);
198+
return modelAndView;
206199
}
207200

208201
private ModelAndView showSamlErrorPage(ErrorCodeWithResponseException e, String relayState)

eidas-middleware/src/test/java/de/governikus/eumw/eidasmiddleware/controller/RequestReceiverTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void testDoGetShouldReturnLandingPage() throws Exception
6969
ModelMap modelMap = landingPage.getModelMap();
7070
Assertions.assertEquals(3, modelMap.size());
7171
Assertions.assertEquals(EID_CLIENT_URL
72-
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8.name()),
72+
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8),
7373
modelMap.getAttribute("ausweisapp"));
7474
Assertions.assertEquals(ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId="
7575
+ REQUEST_ID,
@@ -88,7 +88,7 @@ void testDoGetWithSessionIdShouldReturnLandingPage() throws Exception
8888
ModelMap modelMap = landingPage.getModelMap();
8989
Assertions.assertEquals(3, modelMap.size());
9090
Assertions.assertEquals(EID_CLIENT_URL
91-
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8.name()),
91+
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8),
9292
modelMap.getAttribute("ausweisapp"));
9393
Assertions.assertEquals(ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId="
9494
+ REQUEST_ID,
@@ -197,7 +197,7 @@ void testDoPostShouldReturnLandingPage() throws Exception
197197
ModelMap modelMap = landingPage.getModelMap();
198198
Assertions.assertEquals(3, modelMap.size());
199199
Assertions.assertEquals(EID_CLIENT_MOBIL_URL
200-
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8.name()),
200+
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8),
201201
modelMap.getAttribute("ausweisapp"));
202202
Assertions.assertEquals(ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId="
203203
+ REQUEST_ID,

eidas-starterkit/src/test/java/de/governikus/eumw/eidasstarterkit/person_attributes/natural_persons_attribute/DateOfBirthAttributeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void testDateOfBirthAttributeString(String testDate) throws Exception
5353
ByteArrayOutputStream bout = new ByteArrayOutputStream();
5454
trans.transform(new DOMSource(all), new StreamResult(bout));
5555

56-
String attrString = new String(bout.toByteArray(), StandardCharsets.UTF_8.name());
56+
String attrString = bout.toString(StandardCharsets.UTF_8);
5757
assertTrue(attrString.contains(testDate));
5858
}
5959
}

0 commit comments

Comments
 (0)