2023-01-25

How to create object of a response service class in spring framework

How to use this method in another class? I have to make its object as I have to use this API while creating otherAPI so how can I create its object and use this in another class in same project.


    @POST
    @Path(PathConstants.UPDATE_EPM_DETAILS)
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response updateEpmDetails(InputStream incomingData, @Context HttpHeaders headers) {
        logger.info();
        mapper = getObjectMapper();
        epmHelper = getEpmHelper();
        ElementUpdateEpmRequest[] updateEpmRequestArray = null;
        String jsonInString = "{}";
        UpdateEpmDetailsResponse updateEpmDetailsResponse = new UpdateEpmDetailsResponse();
        int responseStatus = Response.Status.OK.getStatusCode();
        try {
            updateEpmRequestArray = mapper.readValue(incomingData, ElementUpdateEpmRequest[].class);
            List<ElementUpdateEpmRequest> updateEpmRequestList = new ArrayList<>(Arrays.asList(updateEpmRequestArray));
            updateEpmDetailsResponse = epmHelper.updateEpmDetails(updateEpmRequestList);
            jsonInString = mapper.writeValueAsString(updateEpmDetailsResponse);
            logger.infoEndOfMethod();
            return Response.status(responseStatus).entity(jsonInString).build();
        } catch (Exception e) {
            return DataUtils.prepareServerErrorWithMessage(e, e.getMessage());
        }
    }



No comments:

Post a Comment