Building The Adapter
First run
If we run gradle build first, without any components implemented, we will get the following error:
$ ./gradlew build
> Task :test
ApplicationTest > contextLoads() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException at DefaultListableBeanFactory.java:1799
1 test completed, 1 failed
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///C:/Workspaces/services/leap-sdk-demo-adapter/build/reports/tests/test/index.html
...
BUILD FAILED in 31s
7 actionable tasks: 5 executed, 2 up-to-date
Test result:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authenticationController' defined in URL [jar:file:/C:/Users/miig/.m2/repository/com/stibo/leap/adapter-sdk/0.0.1-SNAPSHOT/adapter-sdk-0.0.1-SNAPSHOT-plain.jar!/com/stibo/leap/adapter/internal/api/authentication/controller/AuthenticationController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.stibo.leap.adapter.api.handler.auth.AuthenticationHandler' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at app//org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
at app//org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.stibo.leap.adapter.api.handler.auth.AuthenticationHandler' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1799)
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1355)
This indicates that bean implementing AuthenticationHandler
is required.
Simplest AuthenticationHandler implementation
Dummy implementation of AuthenticationHandler
can look like this:
package com.stibo.leap.sdkdemo.handlers;
import java.util.List;
import org.springframework.stereotype.Service;
import com.stibo.leap.adapter.api.handler.submit.RegularSubmitHandler;
import com.stibo.leap.adapter.api.handler.submit.model.Product;
import com.stibo.leap.adapter.api.service.status.model.ItemStatus;
import com.stibo.leap.adapter.api.service.status.model.SubmitStatus;
import com.stibo.leap.adapter.api.service.status.model.SubmitStatusBuilder;
@Service
public class DemoSubmissionHandler implements RegularSubmitHandler {
@Override
public SubmitStatus submitBatch(String clientId, String channelId, String submissionId, List<Product> allSummaryProducts) {
SubmitStatusBuilder status = SubmitStatus.success().withMessage("Test");
allSummaryProducts.forEach(sp -> status.withItem(ItemStatus.accepted(sp.getId(), "Good!").build()));
return status.build();
}
}
If we try to build again, we will see that additional beans are required.
$ ./gradlew build
> Task :test
ApplicationTest > contextLoads() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException at DefaultListableBeanFactory.java:1799
1 test completed, 1 failed
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///C:/Workspaces/services/leap-sdk-demo-adapter/build/reports/tests/test/index.html
...
* Get more help at https://help.gradle.org
BUILD FAILED in 33s
7 actionable tasks: 5 executed, 2 up-to-date
Test result:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'submitEventConsumer' defined in URL [jar:file:/C:/Users/miig/.m2/repository/com/stibo/leap/adapter-sdk/0.0.1-SNAPSHOT/adapter-sdk-0.0.1-SNAPSHOT-plain.jar!/com/stibo/leap/adapter/internal/api/submit/consumer/SubmitEventConsumer.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.stibo.leap.adapter.internal.api.submit.consumer.SubmissionDispatcher' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at app//org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
at app//org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.stibo.leap.adapter.internal.api.submit.consumer.SubmissionDispatcher' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1799)
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1355)
This indicates that bean implementing SubmissionDispatcher
is required. This interface is not public and is implemented by 3 dispatchers - RegularSubmitDispatcher, FamilyBasedSubmitDispatcher, PackagingBasedSubmitDispatcher - depending on submission mode used. Dispatchers are not public also - the way to customize them is to implement one of the SubmitHandler types: FamilyBasedSubmitHandler, RegularSubmitHandler, PackagingBasedSubmitHandler.
Simplest SubmitHandler implementation
Dummy implementation of RegularSubmitHandler
can look like this:
package com.stibo.leap.sdkdemo.handlers;
import java.util.List;
import org.springframework.stereotype.Service;
import com.stibo.leap.adapter.api.handler.submit.RegularSubmitHandler;
import com.stibo.leap.adapter.api.handler.submit.model.Product;
import com.stibo.leap.adapter.api.service.status.model.ItemStatus;
import com.stibo.leap.adapter.api.service.status.model.SubmitStatus;
import com.stibo.leap.adapter.api.service.status.model.SubmitStatusBuilder;
@Service
public class DemoSubmissionHandler implements RegularSubmitHandler {
@Override
public SubmitStatus submitBatch(String clientId, String channelId, String submissionId, List<Product> allSummaryProducts) {
SubmitStatusBuilder status = SubmitStatus.success().withMessage("Test");
allSummaryProducts.forEach(sp -> status.withItem(ItemStatus.accepted(sp.getId(), "Good!").build()));
return status.build();
}
}
Updated over 1 year ago