user11149927
user11149927

Reputation: 25

Alibaba Rsocket - MonoContextWrite cannot be cast to class java.lang.Integer

I used Alibaba Rsocket. I have broker service with code:

public interface ExampleService {
    Mono<String> getMessage();
}

and implementation:

@RSocketService(serviceInterface = ExampleService.class, encoding = "json")
@Service
@RequiredArgsConstructor
public class ExampleServiceImpl implements ExampleService {

    @Override
    public Mono<String> getMessage() {
        return Mono.just(response);
    }
}

and client service (other spring app):

public interface ExampleService {
        Mono<String> getMessage();
}

@Configuration
public class RSocketConfig {

    @Bean
    public ExampleService exampleService(@Autowired UpstreamManager upstreamManager) {
        return RSocketRemoteServiceBuilder
                .client(ExampleService.class)
                .service("com.example.rsocket.ExampleService")
                .upstreamManager(upstreamManager)
                .acceptEncodingType(RSocketMimeType.Json)
                .build();
    }
}

When I inject Bean of ExampleService in Controller and use getMessage() method I get the exception:

Caused by: java.lang.ClassCastException: class reactor.core.publisher.MonoContextWrite cannot be cast to class java.lang.Integer (reactor.core.publisher.MonoContextWrite is in unnamed module of loader 'app'; java.lang.Integer is in module java.base of loader 'bootstrap') 

What's the cause?

Upvotes: 0

Views: 290

Answers (1)

linux_china
linux_china

Reputation: 11

Yes, this is a bug caused by InvocationHandler that ignores hashCode, equals, toString methods.

An invocation of the hashCode, equals, or toString methods declared in java.lang.Object on a proxy instance will be encoded and dispatched to the invocation handler's invoke method in the same manner as interface method invocations are encoded and dispatched, as described above. The declaring class of the Method object passed to invoke will be java.lang.Object. Other public methods of a proxy instance inherited from java.lang.Object are not overridden by a proxy class, so invocations of those methods behave like they do for instances of java.lang.Object.

It's have been fixed with 1.1.2 version, please refer https://github.com/alibaba/alibaba-rsocket-broker/issues/174 for details.

Upvotes: 0

Related Questions