1

I have an API gateway using the declarative Http client and trying to pass the route parameter to the other microservice application as below

@Client(id="feteBirdProduct", path = "/sub-category")
public interface ISubCategoryClient extends ISubCategoryOperation{
}

The path on the @Client path = "/sub-category" is this correct for this URL http://localhost:8081/60236833af7a1d49478d2bef/sub-category

The Api Gateway controller

@Controller("/api/${api.version:v1}/{categoryId}/sub-category")
public class ApiGatewaySubCategoryController implements ISubCategoryOperation{
    private final ISubCategoryClient iSubCategoryClient;

    public ApiGatewaySubCategoryController(ISubCategoryClient iSubCategoryClient) {
        this.iSubCategoryClient = iSubCategoryClient;
    }

    @Override
    public Maybe<?> get(@ValidObjectId @NotBlank String categoryId) {
        return this.iSubCategoryClient.get(categoryId);
    }
}

ISubCategoryOperation

@Get
    @Secured(SecurityRule.IS_ANONYMOUS)
    Maybe<?> get(@Parameter(description="Category id") @ValidObjectId @NotNull String categoryId);

Implementation in the other microservice

@Controller("/{categoryId}/sub-category")
public class SubCategoryController implements ISubCategoryOperation {
    @Override
    public Maybe<?> get(String categoryId) {
        return iSubCategoryManager.find(categoryId);
    }
}

However, on the below CURL

curl -X GET "http://localhost:8080/api/v1/60236833af7a1d49478d2bef/sub-category" -H  "accept: application/json"

The end point is never hit, what I am missing ?

The HTTP client logs

DEBUG i.m.h.client.netty.DefaultHttpClient - Sending HTTP GET to http://localhost:8081/sub-category

The HTTP request should be http://localhost:8081/60236833af7a1d49478d2bef /sub-category

San Jaisy
  • 15,327
  • 34
  • 171
  • 290
  • What is HTTP response message? – Vazgen Torosyan Feb 11 '21 at 08:51
  • It goes to the fallback url however on the HTTP logs - Sending HTTP GET to http://localhost:8081 it should be Sending HTTP GET to http://localhost:8081/60236833af7a1d49478d2bef/sub-category – San Jaisy Feb 11 '21 at 10:04
  • I believe that you need to redifine the get in your ISubCategoryClient, I believe that currently the categoryId is being passed as parameter. Try to redefine the get on ISubCategoryClient to something like: @Get("/{categoryId}/sub-category") @Secured(SecurityRule.IS_ANONYMOUS) Maybe> get(String categoryId); And remove the path from the ISubCategoryClient @Controller annotation. I believe that should do it. – matutano Feb 11 '21 at 11:10
  • @matutano It's not only for the get method , I do have same thing for post, put and delete method. I don't want to redefined again all for all the methods. Is there a better way to do ? – San Jaisy Feb 11 '21 at 12:04
  • I am not sure, but you can try to add the annotation @PathVariable(name = "categoryId") in the categoryId in the ISubCategoryOperation and check if it does the trick. – matutano Feb 11 '21 at 12:22
  • @PathVariable(name = "categoryId") doesn't work – San Jaisy Feb 12 '21 at 02:14
  • I tried @Get("/{categoryId}/sub-category") @Secured(SecurityRule.IS_ANONYMOUS) Maybe> get(String categoryId). But the request is unAuthorized Received response 401 from http://localhost:8081/60236833af7a1d49478d2bef/sub-category. However, the method is denoted with @Secured(SecurityRule.IS_ANONYMOUS) – San Jaisy Feb 12 '21 at 02:39

0 Answers0