commit
						a72a88e4ef
					
				
					 2 changed files with 46 additions and 25 deletions
				
			
		|  | @ -648,27 +648,24 @@ public final class Utils { | ||||||
|             return StringUtils.EMPTY; |             return StringUtils.EMPTY; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return attributes |         return reduceFormUrlAttributes(attributes); | ||||||
|                 .entrySet() |  | ||||||
|                 .stream() |  | ||||||
|                 .reduce( |  | ||||||
|                         new StringBuilder(), |  | ||||||
|                         (sb, entry) -> { |  | ||||||
|                             final String name = entry.getKey(); |  | ||||||
|                             final List<String> values = entry.getValue(); |  | ||||||
|                             if (values == null) { |  | ||||||
|                                 return sb; |  | ||||||
|     } |     } | ||||||
|                             if (!sb.isEmpty()) { | 
 | ||||||
|                                 sb.append(Constants.AMPERSAND); |     public static String toAppFormUrlEncodedBodyForSPService(final MultiValueMap<String, String> attributes) { | ||||||
|  |         if (attributes == null) { | ||||||
|  |             return StringUtils.EMPTY; | ||||||
|         } |         } | ||||||
|                             if (values.size() == 1) { | 
 | ||||||
|                                 return sb.append(name).append(Constants.EQUALITY_SIGN).append(values.get(0)); |         for (String key : attributes.keySet()) { | ||||||
|  |             List<String> values = attributes.get(key); | ||||||
|  |             if (values != null) { | ||||||
|  |                 for (int i = 0; i < values.size(); i++) { | ||||||
|  |                     values.set(i, encodeFormURL_UTF_8(values.get(i))); | ||||||
|                 } |                 } | ||||||
|                             return sb.append(toAppFormUrlEncodedBody(name, values)); |             } | ||||||
|                         }, |         } | ||||||
|                         StringBuilder::append) | 
 | ||||||
|                 .toString(); |         return reduceFormUrlAttributes(attributes); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static String toAppFormUrlEncodedBody(@NotNull final String name, final Collection<String> array) { |     public static String toAppFormUrlEncodedBody(@NotNull final String name, final Collection<String> array) { | ||||||
|  | @ -925,4 +922,28 @@ public final class Utils { | ||||||
|                 .filter(Objects::nonNull) |                 .filter(Objects::nonNull) | ||||||
|                 .collect(Collectors.toSet()); |                 .collect(Collectors.toSet()); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     private static String reduceFormUrlAttributes(final MultiValueMap<String, String> attributes){ | ||||||
|  |         return attributes | ||||||
|  |                 .entrySet() | ||||||
|  |                 .stream() | ||||||
|  |                 .reduce( | ||||||
|  |                         new StringBuilder(), | ||||||
|  |                         (sb, entry) -> { | ||||||
|  |                             final String name = entry.getKey(); | ||||||
|  |                             final List<String> values = entry.getValue(); | ||||||
|  |                             if (values == null) { | ||||||
|  |                                 return sb; | ||||||
|  |                             } | ||||||
|  |                             if (!sb.isEmpty()) { | ||||||
|  |                                 sb.append(Constants.AMPERSAND); | ||||||
|  |                             } | ||||||
|  |                             if (values.size() == 1) { | ||||||
|  |                                 return sb.append(name).append(Constants.EQUALITY_SIGN).append(values.get(0)); | ||||||
|  |                             } | ||||||
|  |                             return sb.append(toAppFormUrlEncodedBody(name, values)); | ||||||
|  |                         }, | ||||||
|  |                         StringBuilder::append) | ||||||
|  |                 .toString(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -695,7 +695,7 @@ class ScreenProctoringAPIBinding { | ||||||
|         params.add(SPS_API.SESSION.ATTR_CLIENT_MACHINE_NAME, clientConnection.getClientMachineName()); |         params.add(SPS_API.SESSION.ATTR_CLIENT_MACHINE_NAME, clientConnection.getClientMachineName()); | ||||||
|         params.add(SPS_API.SESSION.ATTR_CLIENT_OS_NAME, clientConnection.getClientOsName()); |         params.add(SPS_API.SESSION.ATTR_CLIENT_OS_NAME, clientConnection.getClientOsName()); | ||||||
|         params.add(SPS_API.SESSION.ATTR_CLIENT_VERSION, clientConnection.getClientVersion()); |         params.add(SPS_API.SESSION.ATTR_CLIENT_VERSION, clientConnection.getClientVersion()); | ||||||
|         final String paramsFormEncoded = Utils.toAppFormUrlEncodedBody(params); |         final String paramsFormEncoded = Utils.toAppFormUrlEncodedBodyForSPService(params); | ||||||
| 
 | 
 | ||||||
|         final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded); |         final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded); | ||||||
|         if (exchange.getStatusCode() != HttpStatus.OK) { |         if (exchange.getStatusCode() != HttpStatus.OK) { | ||||||
|  | @ -910,7 +910,7 @@ class ScreenProctoringAPIBinding { | ||||||
|         params.add(SPS_API.GROUP.ATTR_NAME, name); |         params.add(SPS_API.GROUP.ATTR_NAME, name); | ||||||
|         params.add(SPS_API.GROUP.ATTR_DESCRIPTION, description); |         params.add(SPS_API.GROUP.ATTR_DESCRIPTION, description); | ||||||
|         params.add(SPS_API.GROUP.ATTR_EXAM_ID, spsExamUUID); |         params.add(SPS_API.GROUP.ATTR_EXAM_ID, spsExamUUID); | ||||||
|         final String paramsFormEncoded = Utils.toAppFormUrlEncodedBody(params); |         final String paramsFormEncoded = Utils.toAppFormUrlEncodedBodyForSPService(params); | ||||||
| 
 | 
 | ||||||
|         final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded); |         final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded); | ||||||
|         if (exchange.getStatusCode() != HttpStatus.OK) { |         if (exchange.getStatusCode() != HttpStatus.OK) { | ||||||
|  | @ -945,7 +945,7 @@ class ScreenProctoringAPIBinding { | ||||||
| 
 | 
 | ||||||
|             final String uuid = createExamUUID(exam); |             final String uuid = createExamUUID(exam); | ||||||
|             final MultiValueMap<String, String> params = createExamCreationParams(exam, uuid, userIds); |             final MultiValueMap<String, String> params = createExamCreationParams(exam, uuid, userIds); | ||||||
|             final String paramsFormEncoded = Utils.toAppFormUrlEncodedBody(params); |             final String paramsFormEncoded = Utils.toAppFormUrlEncodedBodyForSPService(params); | ||||||
| 
 | 
 | ||||||
|             final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded); |             final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded); | ||||||
|             if (exchange.getStatusCode() != HttpStatus.OK) { |             if (exchange.getStatusCode() != HttpStatus.OK) { | ||||||
|  | @ -1060,7 +1060,7 @@ class ScreenProctoringAPIBinding { | ||||||
|             final MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); |             final MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | ||||||
|             params.add(SPS_API.SEB_ACCESS.ATTR_NAME, name); |             params.add(SPS_API.SEB_ACCESS.ATTR_NAME, name); | ||||||
|             params.add(SPS_API.SEB_ACCESS.ATTR_DESCRIPTION, description); |             params.add(SPS_API.SEB_ACCESS.ATTR_DESCRIPTION, description); | ||||||
|             final String paramsFormEncoded = Utils.toAppFormUrlEncodedBody(params); |             final String paramsFormEncoded = Utils.toAppFormUrlEncodedBodyForSPService(params); | ||||||
| 
 | 
 | ||||||
|             final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded); |             final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded); | ||||||
|             if (exchange.getStatusCode() != HttpStatus.OK) { |             if (exchange.getStatusCode() != HttpStatus.OK) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 NadimETH
						NadimETH