0

I have the following Spring Boot Controller:

import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.att.aft.dme2.internal.javaxwsrs.PUT;
import com.att.bttw.model.HelloWorld;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Api
@Path("/service")
@Produces({ MediaType.APPLICATION_JSON })
public interface RestService {


    @PUT
    @Path("/datarouter/{filename}")
    @Consumes("application/gzip")
    @Produces(MediaType.APPLICATION_JSON)
    Response testEndpoint(@Context HttpServletRequest request, @PathParam("filename") String filename, InputStream inputStream);

}

The implementation of this method is simply:

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import org.springframework.stereotype.Component;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.RestTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;

import com.att.bttw.model.ApplicationResults;
import com.att.bttw.model.CountsDataModel;
import com.att.bttw.model.CountsDataResults;
import com.att.bttw.model.DisplayFieldRecord;
import com.att.bttw.model.DisplayRecord;
import com.att.bttw.model.WatermarkEventObject;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Override
    public Response testEndpoint(HttpServletRequest request, String filename, InputStream inputStream) {
        System.out.println("File name consumed: " + filename);
        return null;
    }

When I try to hit this endpoint, I get the following error:

"Following issues have been detected: Response testEndpoint(javax.servlet.http.HttpServletRequest, java.lang.String, java.io.InputStream), can not have an entity parameter. Try to move the parameter to the corresponding resource method".

When I remove the InputStream and HttpServletRequest parameters, the endpoint works just fine, I'm just not understanding the error message I'm getting.

kramsiv1234
  • 113
  • 1
  • 2
  • 9
  • Can you post your imports (specifically the whole package for PathParam) – Not a JD Mar 28 '19 at 20:32
  • Yes --updated accordingly – kramsiv1234 Mar 28 '19 at 20:42
  • 1
    can you try adding the @javax.ws.rs.core.Context annotation to the request argument in your implementation? – Not a JD Mar 28 '19 at 20:43
  • Is there a particular reason that you're using a PUT rather than a POST and a multi-part request? Ala: https://stackoverflow.com/questions/16958448/what-is-http-multipart-request https://www.mkyong.com/spring-boot/spring-boot-file-upload-example/ https://www.baeldung.com/spring-file-upload – MarkOfHall Mar 28 '19 at 20:46
  • Changing the method to: ``` @PUT @Path("/datarouter/{filename}") @Consumes("application/gzip") @Produces(MediaType.APPLICATION_JSON) Response testEndpoint(@Context HttpServletRequest request, @PathParam("filename") String filename, InputStream inputStream); ``` Resolved it -- thanks! – kramsiv1234 Mar 28 '19 at 20:49
  • @MarkOfHall Poor architectural decisions on behalf of the developers of an internal tool we're using to receive messages from :) – kramsiv1234 Mar 28 '19 at 20:52

0 Answers0