Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetworkingClient problem when handle response from CF security server #969

Closed
lavcraft opened this issue Jul 10, 2019 · 2 comments · Fixed by #990
Closed

NetworkingClient problem when handle response from CF security server #969

lavcraft opened this issue Jul 10, 2019 · 2 comments · Fixed by #990

Comments

@lavcraft
Copy link

Configure context with Network Client for cloudfoundry:

    @Bean
    DefaultConnectionContext connectionContext(CloudFoundryProperties cloudFoundryProperties) {
        return DefaultConnectionContext.builder()
                .apiHost(cloudFoundryProperties.getApiHost())
                .skipSslValidation(true)
                .cacheDuration(Duration.ofSeconds(cloudFoundryProperties.getClientCacheInSeconds()))
                .keepAlive(true)
                .build();
    }

    @Bean
    public ClientCredentialsGrantTokenProvider refreshTokenGrantTokenProvider(MetricsBrokerProperties metricsBrokerProperties) {
        return ClientCredentialsGrantTokenProvider.builder()
                .clientId(metricsBrokerProperties.getClientId())
                .clientSecret(metricsBrokerProperties.getClientSecret())
                .build();
    }

    @Bean
    public NetworkingClient networkingClient(ConnectionContext connectionContext,
                                             TokenProvider tokenProvider) {
        return ReactorNetworkingClient.builder()
                .connectionContext(connectionContext)
                .tokenProvider(tokenProvider)
                .build();
    }

And try it in next example:

@Service
@RequiredArgsConstructor
public class CFPolicyService implements PolicyService {
    private final NetworkingClient networkingClient;

    @Override
    public void allowConnection(String sourceId, String destId, List<Pair<String, Integer>> protocols) {
        networkingClient.policies()
                .create(CreatePoliciesRequest.builder()
                        .policies(createPolicies(sourceId, destId, protocols))
                        .build())
                .retry(3)
                .onErrorContinue((throwable, o) -> {
                    log.error("Sth went wrong with message: {}", throwable.getMessage());
                    if(o instanceof byte[]) {
                        byte[] byteData = (byte[]) o;
                        log.error("Data: {}", new String(byteData));
                    }
                })
                .block(Duration.ofSeconds(20));

        log.debug("Policy from {} to {} for protocols {} created", sourceId, destId, protocols);
    }
...

After run policies request I saw next error:

   2019-07-10T10:58:19.97+0300 [APP/PROC/WEB/0] OUT 2019-07-10 07:58:19.973 ERROR 9 --- [ry-client-nio-3] o.s.c.s.metrics.service.CFPolicyService  : Sth went wrong with message: The mapper returned a null value.
   2019-07-10T10:58:19.97+0300 [APP/PROC/WEB/0] OUT 2019-07-10 07:58:19.973 ERROR 9 --- [ry-client-nio-3] o.s.c.s.metrics.service.CFPolicyService  : Data: {}

2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR java.lang.NullPointerException: The mapper returned a null value.
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at java.util.Objects.requireNonNull(Objects.java:228)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:100)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:114)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:114)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.ipc.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:213)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.ipc.netty.channel.FluxReceive.onInboundNext(FluxReceive.java:329)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.ipc.netty.channel.ChannelOperations.onInboundNext(ChannelOperations.java:311)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.ipc.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:628)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.ipc.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:138)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.ipc.netty.http.HttpOperations.lambda$static$2(HttpOperations.java:280)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at reactor.ipc.netty.ReactorNetty$ExtractorHandler.channelRead(ReactorNetty.java:366)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1478)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1227)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1274)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:441)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1408)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:930)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:682)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:617)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:534)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
   2019-07-10T11:34:14.57+0300 [APP/PROC/WEB/0] ERR     at java.lang.Thread.run(Thread.java:748)

Mapper really returns null. I guess it is bug, because try to handle Mono, but api return empty json {}.

@GFriedrich
Copy link
Contributor

I ran into the same issue. Looks like that in contrast to the regular API, the networking API returns an empty JSON object (aka "{}") and HTTP code 200 (the Cloud Foundry API uses code 204 and therefore no response content at all).
This in turn results in the object mapper being called at


As the target type is set to "Void" it will always return "null" - which is the regular behaviour for Jackson's objectmapper class.

@twoseat Would you mind if I fix this issue in a PR?

@twoseat
Copy link
Contributor

twoseat commented Aug 15, 2019

@GFriedrich Please do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants