Coder Social home page Coder Social logo

Spring Cloud Gateway Server MVC rateLimit filter(Bucket4jFilter) will got UnsupportedOperationException when response headers is ReadOnlyHttpHeaders about spring-cloud-gateway HOT 2 OPEN

zzphyh avatar zzphyh commented on May 26, 2024
Spring Cloud Gateway Server MVC rateLimit filter(Bucket4jFilter) will got UnsupportedOperationException when response headers is ReadOnlyHttpHeaders

from spring-cloud-gateway.

Comments (2)

spencergibb avatar spencergibb commented on May 26, 2024

I don't understand your full configuration. Can you provide it. Where does return ServerResponse.ok().body(result); live?

from spring-cloud-gateway.

zzphyh avatar zzphyh commented on May 26, 2024

I don't understand your full configuration. Can you provide it. Where does return ServerResponse.ok().body(result); live?

I have added a custom handler, the code in spring.factories is:

org.springframework.cloud.gateway.server.mvc.handler.HandlerSupplier=\
test.HandlerFunctions.MyHandlerSupplier

Custom handler code:

public abstract class HandlerFunctions {

    public static HandlerFunction<ServerResponse> dubbo() {
        return new DubboHandler();
    }

    public static class MyHandlerSupplier implements HandlerSupplier {

        @Override
        public Collection<Method> get() {
            return Arrays.asList(HandlerFunctions.class.getMethods());
        }
    }
}
public class DubboHandler implements HandlerFunction<ServerResponse> {
    @Override
    public ServerResponse handle(@Nonnull ServerRequest request) {
        try {
            final JSONObject result = callDubboRPC(request);
            return ServerResponse.ok().body(result);
        } catch (Exception e) {
            log.error("forward to rpc failed.", e);
            return ServerResponse.status(BAD_GATEWAY).body(new Result<>(HTTP_FORWARD_DUBBO_ERROR));
        }
    }
}

The routing configuration is similar to the following (excluding the rate-limiting part):

spring:
  cloud:
    gateway:
      mvc:
        routes:
          - id: im_route1
            uri: dubbo://dubboserviceaddress
            predicates:
              - Path=/calltodubbo
              - Method=POST

from spring-cloud-gateway.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.