0

I have a servlet class which has a method "process", over ridden from HttpServlet

@override
protected void process(HttpServletRequest request, HttpServletResponse response) {
    InputStream in = null;
    OutputStream out = null;
    String inXml = null;
    //some more code..
}

It is reading whatever is coming into the servlet.

How can I rewrite this as rest controller in spring??

1 Answer 1

1

Just code it as:

@RestController
public ReturnType process(HttpServletRequest request, HttpServletResponse response {
    //...
}

and check this part of the Spring MVC documentation as well:

@RequestMapping handler methods have a flexible signature and can choose from a range of supported controller method arguments and return values.

Note, that:

  • whatever you return from your Rest-Controller turns into HTTP Response Body;
  • you can define @RestController on the class level.
Sign up to request clarification or add additional context in comments.

7 Comments

currently my servlet is not returning anything, it is using outputsream only,
out = response.getOutputStream(); if (outXml == null) { outXml = (String) genericDTO.getObj(); } out.write(outXml.getBytes("UTF-8")); out.flush(); if (fwlogger.isDebugEnabled()) fwlogger.debug(requestId + " Response XML : " + outXml);
how can i make this outputstream into a returntype??
in rest concept, whatever i am returning shud come as a response right??
That is another question, which means that you're not focused on what you are asking. 1. why do you want to return OutputStream? what you're trying to achieve? Just return String or whatever type you wish.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.