@@ -325,21 +325,37 @@ public int getDepth() {
325325 @ SuppressWarnings ("unchecked" )
326326 @ Override
327327 public @ NotNull Response updateAdapter (final @ NotNull String adapterId , final @ NotNull Adapter adapter ) {
328- return systemInformation .isConfigWriteable () ?
329- configExtractor .getAdapterByAdapterId (adapterId ).map (oldInstance -> {
330- final ProtocolAdapterEntity newConfig = new ProtocolAdapterEntity (oldInstance .getAdapterId (),
331- oldInstance .getProtocolId (),
332- oldInstance .getConfigVersion (),
333- (Map <String , Object >) adapter .getConfig (),
334- oldInstance .getNorthboundMappings (),
335- oldInstance .getSouthboundMappings (),
336- oldInstance .getTags ());
337- if (!configExtractor .updateAdapter (newConfig )) {
338- return adapterCannotBeUpdatedError (adapterId );
339- }
340- return Response .ok ().build ();
341- }).orElseGet (adapterNotFoundError (adapterId )) :
342- errorResponse (new ConfigWritingDisabled ());
328+ if (!systemInformation .isConfigWriteable ()) {
329+ return errorResponse (new ConfigWritingDisabled ());
330+ }
331+
332+ // Validate adapter configuration before updating
333+ final ApiErrorMessages errorMessages = ApiErrorUtils .createErrorContainer ();
334+ validateAdapterSchema (errorMessages , adapter );
335+ if (hasRequestErrors (errorMessages )) {
336+ return errorResponse (new AdapterFailedSchemaValidationError (errorMessages .toErrorList ()));
337+ }
338+
339+ return configExtractor .getAdapterByAdapterId (adapterId ).map (oldInstance -> {
340+ try {
341+ final ProtocolAdapterEntity newConfig = new ProtocolAdapterEntity (oldInstance .getAdapterId (),
342+ oldInstance .getProtocolId (),
343+ oldInstance .getConfigVersion (),
344+ (Map <String , Object >) adapter .getConfig (),
345+ oldInstance .getNorthboundMappings (),
346+ oldInstance .getSouthboundMappings (),
347+ oldInstance .getTags ());
348+ if (!configExtractor .updateAdapter (newConfig )) {
349+ return adapterCannotBeUpdatedError (adapterId );
350+ }
351+ return Response .ok ().build ();
352+ } catch (final @ NotNull IllegalArgumentException e ) {
353+ if (e .getCause () instanceof final UnrecognizedPropertyException pe ) {
354+ addValidationError (errorMessages , pe .getPropertyName (), "Unknown field on adapter configuration" );
355+ }
356+ return errorResponse (new AdapterFailedSchemaValidationError (errorMessages .toErrorList ()));
357+ }
358+ }).orElseGet (adapterNotFoundError (adapterId ));
343359 }
344360
345361 @ Override
@@ -388,12 +404,12 @@ public int getDepth() {
388404 }
389405 });
390406 case RESTART -> protocolAdapterManager .stopAsync (adapterId )
391- .thenRun (() -> protocolAdapterManager .startAsync (adapterId ))
407+ .thenCompose ( ignored -> protocolAdapterManager .startAsync (adapterId ))
392408 .whenComplete ((result , throwable ) -> {
393409 if (throwable != null ) {
394410 log .error ("Failed to restart adapter '{}'." , adapterId , throwable );
395411 } else {
396- log .trace ("Adapter '{}' was restarted successfully." , adapterId );
412+ log .info ("Adapter '{}' was restarted successfully." , adapterId );
397413 }
398414 });
399415 }
@@ -894,17 +910,15 @@ private void validateAdapterSchema(
894910 }
895911
896912 private @ NotNull Adapter toAdapter (final @ NotNull ProtocolAdapterWrapper value ) {
897- final Thread currentThread = Thread .currentThread ();
898- final ClassLoader ctxClassLoader = currentThread .getContextClassLoader ();
899- final Map <String , Object > config ;
900- try {
901- currentThread .setContextClassLoader (value .getAdapterFactory ().getClass ().getClassLoader ());
902- config = value .getAdapterFactory ().unconvertConfigObject (objectMapper , value .getConfigObject ());
903- config .put ("id" , value .getId ());
904- } finally {
905- currentThread .setContextClassLoader (ctxClassLoader );
906- }
907913 final String adapterId = value .getId ();
914+ final Map <String , Object > config = runWithContextLoader (
915+ value .getAdapterFactory ().getClass ().getClassLoader (),
916+ () -> {
917+ final Map <String , Object > cfg = value .getAdapterFactory ()
918+ .unconvertConfigObject (objectMapper , value .getConfigObject ());
919+ cfg .put ("id" , value .getId ());
920+ return cfg ;
921+ });
908922 return new Adapter (adapterId ).type (value .getAdapterInformation ().getProtocolId ())
909923 .config (objectMapper .valueToTree (config ))
910924 .status (getAdapterStatusInternal (adapterId ));
0 commit comments