私はSpring XD用に作成するシンクの統合テストを作成しようとしています。ここに私のModuleConfiguration.javaSpring XD OAuthシンクユニットテスト「null」リソースの新しいアクセストークンを取得できません
@Configuration
@EnableIntegration
public class ModuleConfiguration {
private OAuth2AccessToken token;
@Bean
public MessageChannel input() {
return new DirectChannel();
}
@Bean
protected OAuth2ProtectedResourceDetails resource() {
BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
resource.setAccessTokenUri("https://xxxxxxxxxxx");
resource.setClientId("id");
resource.setClientSecret("secret");
resource.setGrantType("authorization_code");
return resource;
}
@Bean
public OAuth2RestTemplate oAuthTemplate() {
AccessTokenRequest atr = new DefaultAccessTokenRequest();
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource(), new DefaultOAuth2ClientContext(atr));
return restTemplate;
}
@Bean
public HeaderMapper<HttpHeaders> headerMapper() {
HeaderMapper<HttpHeaders> mapper = new DefaultHttpHeaderMapper();
HttpHeaders headers = new HttpHeaders();
token = oAuthTemplate().getAccessToken();
String authHeader = "Bearer " + token.getValue();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Authorization", authHeader);
mapper.toHeaders(headers);
return mapper;
}
@ServiceActivator(inputChannel="inputChannel")
@Bean
public MessageHandler httpout() {
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("https://yyyyyyyyy");
handler.setCharset("UTF-8");
handler.setHttpMethod(HttpMethod.POST);
handler.setHeaderMapper(headerMapper());
return handler;
}
}
私はプロセッサのためのテストが書かれているテストを同じように実装し、それはそれは期待するものだから、このモジュールは、プロセッサであるスプリングXDを伝えています。わかりませんが、問題はないと思いますが、例外はOAuthと関係があります。ここで私は私のModuleConfigurationのこの行に例外を取得SinkTest.java
public class SinkTest {
private static SingleNodeApplication application;
private static int RECEIVE_TIMEOUT = 5000;
private static String moduleName = "oauth-sink";
@BeforeClass
public static void setUp() {
application = new SingleNodeApplication().run();
SingleNodeIntegrationTestSupport singleNodeIntegrationTestSupport = new SingleNodeIntegrationTestSupport(
application);
singleNodeIntegrationTestSupport
.addModuleRegistry(new SingletonModuleRegistry(ModuleType.processor, moduleName));
}
@Test
public void test() {
String streamName = "sinkTest";
byte[] encoded = null;
String data = null;
try {
encoded = Files.readAllBytes(Paths.get("src/test/resources/dataunit.json"));
data = new String(encoded, "utf-8");
} catch (IOException e) {
e.printStackTrace();
fail("Exception thrown");
}
String processingChainUnderTest = moduleName;
SingleNodeProcessingChain chain = chain(application, streamName, processingChainUnderTest);
chain.sendPayload(data);
@SuppressWarnings("unchecked")
List<Map<String, Object>> result = (List<Map<String, Object>>) chain.receivePayload(RECEIVE_TIMEOUT);
// Unbind the source and sink channels from the message bus
chain.destroy();
// an exception is thrown by zookeeper when the spring xd container shuts down after the test passes
}
}
ある token = oAuthTemplate().getAccessToken();
Caused by: error="access_denied", error_description="Unable to obtain a new access token for resource 'null'. The provider manager is not configured to support it."
at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainNewAccessTokenInternal(AccessTokenProviderChain.java:146)
at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainAccessToken(AccessTokenProviderChain.java:118)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:221)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken(OAuth2RestTemplate.java:173)
私はこの
@Bean
protected OAuth2ProtectedResourceDetails resource() {
BaseOAuth2ProtectedResourceDetails resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri("https://xxxxxxx");
resource.setClientId("id");
resource.setClientSecret("secret");
resource.setGrantType("client_credentials");
return resource;
}
IのようModuleConfigurationにGrantTypeためclient_credentialsを使用している場合取得する
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:107)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
... 29 more
私はちょうどclientIdとシークレットを持っているときに使用する正しい助成金の種類は何ですか? ModuleConfigurationに何か不足していますか?
更新 は、私が正しい値に@ServiceActivator
でinputChannelを変更し、私は今BaseOAuth2ProtectedResourceDetails
と、以前と同じ例外を取得しています。これで、すべてのClientCredentialsResourceDetails
Caused by: java.lang.IllegalArgumentException: Map has no value for 'object-type'
at org.springframework.web.util.UriComponents$MapTemplateVariables.getValue(UriComponents.java:276)
at org.springframework.web.util.UriComponents.expandUriComponent(UriComponents.java:221)
at org.springframework.web.util.HierarchicalUriComponents$FullPathComponent.expand(HierarchicalUriComponents.java:650)
at org.springframework.web.util.HierarchicalUriComponents.expandInternal(HierarchicalUriComponents.java:319)
at org.springframework.web.util.HierarchicalUriComponents.expandInternal(HierarchicalUriComponents.java:46)
at org.springframework.web.util.UriComponents.expand(UriComponents.java:152)
at org.springframework.web.util.UriComponentsBuilder.buildAndExpand(UriComponentsBuilder.java:376)
at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:376)
... 35 more
ちょうど私のPCに到達したときにその補正 – gary69