-
使用环境: springcloud gateway 转发 websocket 报错
-
报错内容:
15:30:38.092 [http-nio-9999-exec-1] ERROR c.m.g.e.GlobalErrorWebExceptionHandler - [handle,38] - org.apache.catalina.connector.ResponseFacade cannot be cast to reactor.netty.http.server.HttpServerResponse
java.lang.ClassCastException: org.apache.catalina.connector.ResponseFacade cannot be cast to reactor.netty.http.server.HttpServerResponse
at org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy.getNativeResponse(ReactorNettyRequestUpgradeStrategy.java:182)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP GET "/sys/websocket/1" [ExceptionHandlingWebHandler]
Stack trace:
at org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy.getNativeResponse(ReactorNettyRequestUpgradeStrategy.java:182)
at org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy.upgrade(ReactorNettyRequestUpgradeStrategy.java:162)
at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.lambda$handleRequest$1(HandshakeWebSocketService.java:235)
at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:151)
at reactor.core.publisher.MonoFlatMap.subscribeOrReturn(MonoFlatMap.java:53)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.Mono.subscribe(Mono.java:4252)
at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172)
at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at com.alibaba.csp.sentinel.adapter.reactor.MonoSentinelOperator.subscribe(MonoSentinelOperator.java:40)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
- 报错原因: 依赖冲突
请求时使用的是springBoot的tomcat servlet,而响应的时候使用的是gateway Netty的tomcat,所以导致类型转换异常 - 解决办法 gateway pom文件修改:
删除以下 或 排除以下 依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
使用环境: springcloud gateway 转发 websocket 报错报错内容:15:30:38.092 [http-nio-9999-exec-1] ERROR c.m.g.e.GlobalErrorWebExceptionHandler - [handle,38] - org.apache.catalina.connector.ResponseFacade cannot be cast to reactor.netty.http.server.HttpServerResponsej.
问题描述:websocket 请求通过网关时报错,
2022-02-25 14:41:28,117 [boundedElastic-2] o.s.c.l.CompositeLog ERROR [262f41de-1] 500 Server Error for HTTP GET “/stt/streaming”
java.lang.ClassCastException: class io.undertow.server.HttpServerExchange
搭建了一个父子分布式项目
但是配置gateway的时候, 由于各种依赖冲突导致gateway的路由无法生效
后来发现是因为父项目pom文件中引入的部分依赖和gateway依赖有冲突
下面这些依赖和springcloud gateway相冲突造成以下冲突
java.lang.ClassCastException: org.springframework.core.io.buffer.DefaultDataBufferFactory cannot be cast to org.springframewo
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartRequest
com.wa.editor.xheditor.controller.UploadController.uploa
使用spring-boot-starter-websocket搭建了websocket服务,直接用服务的IP加端口访问是正常的,换成网关的访问地址就报错。
查看日志,
2020-12-17 18:26:43,675 ERROR AbstractErrorWebExceptionHandler:117 -[d5c6b807] 500 Server Error for HTTP GET "/websocket/pk/ssss/1"
java.lang.ClassCastException: com.spinni
java.lang.ClassCastException
当Eclipse报java.lang.ClassCastException时是向下类型转换发生错误
父类转换为子类时 存在风险(类似于低精度和高精度之间的转关系)
举例子说明
可以再类型转换前加上 instanceof进行判断
instanceof是Java 的一个二元操作符,它的作用是测试它左边的对象是否是它右边的类的实例,返回 boolean 的数据类型,
本人初学webservice,平台用spring+cxf+ibatis,在调用接口中含返回自定义对象的方法时,就会报ClassCastException,即方法:
public List<User> getUserList()
调用返回值为基本类型的方法,则没问题,如:
public Integer getUserCount();
困扰很久,包括调用含自定义类型的方法,也会报...
spring mvc 上传时
org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
添加配置:
<bean id="multipartResolver"...
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
写错成了:
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpS..
IDEA--Maven项目中Spring与MyBatis整合中的报错问题org.apache.ibatis.builder.BuilderException: Error parsing Mapper
冷冷的菜哥:
gateway 转发weboskct 报错 ClassCastException
kk~~:
gateway 转发weboskct 报错 ClassCastException
qq_55539171:
gateway 转发weboskct 报错 ClassCastException
izaogao:
gateway 转发weboskct 报错 ClassCastException
ma_508346117: