Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6036941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:59:57+00:00 2026-05-23T05:59:57+00:00

I want to generate raw xml from a REST service using Spring. Something is

  • 0

I want to generate raw xml from a REST service using Spring. Something is getting lost in resolving the views. I am getting the following:

javax.servlet.ServletException: Circular view path [RemedyXml]: would dispatch back to the current handler URL [/audiClave/REST/remedies/RemedyXml] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

Here is the web.xml (abbreviated):

<servlet>
    <servlet-name>rest</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/restServlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>rest</servlet-name>
    <url-pattern>/REST/</url-pattern>
</servlet-mapping>

restServlet-context.xml is as follows (abbreviated):

<context:component-scan base-package="com.audiClave.controllers" />
<bean id="beanNameResolver" 
    class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean id = "RemedyXml" class = "com.audiClave.views.RemedyXmlView"/>

Now for the controller:

@Controller
public class RestController{
private static final String REMEDIES = "remedies";

    @RequestMapping(value = "/REST/remedies/{language}", method = RequestMethod.GET)
    protected ModelAndView getAllRemedies(HttpServletResponse response,
        @PathVariable("language") String language) throws IOException {
        Map<String, List<Remedy>> myModel = new HashMap<String, List<Remedy>>();
        RemediesBean remediesBean = Factory.getRemediesBean();
        myModel.put("remedies", remediesBean.loadRemedies(language));
        return new ModelAndView("RemedyXml","model", myModel);

And finally the view:

public class RemedyXmlView implements View
{

  /** XML document */
  private Document doc = null;

  public RemedyXmlView()
  {
  }

  public String getContentType()
  {
    return "text/xml";
  }

@Override
  public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) 
    throws Exception {

    /** Generate the XML */
    // Start document with "root" tag
    this.doc = new Document(new Element("model"));
    // Get the root tag
    Element rootEl = this.doc.getRootElement();

    // Add other tags
    Map<String,List<Remedy>> myModel = (Map<String,List<Remedy>>)model.get("model");
    List<Remedy> messages = (List<Remedy>)myModel.get("remedies");
    Iterator<Remedy> iter = messages.iterator();
    while(iter.hasNext()){
      Remedy remedy = iter.next();

      // Add new xml element
      Element messageEl = new Element("remedy");
      messageEl.setText(remedy.getName());
      rootEl.addContent(messageEl);
    }

    // printXMLDocument(this.doc);

    /** Set response type and write XML */
    XMLOutputter outp = new XMLOutputter();
    outp.setFormat(Format.getPrettyFormat());
    String xmlAsString = outp.outputString(doc);

    response.setContentType("text/xml");
    response.setContentLength(xmlAsString.length());

    PrintWriter out = new PrintWriter(response.getOutputStream());
    out.print(xmlAsString);
    out.flush();
    out.close();    
  }

}

Any input would be appreciated, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:59:58+00:00Added an answer on May 23, 2026 at 5:59 am

    I moved the view to a .JSP implementation and the problem was resolved with a lot less code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate some XML in a stored procedure based on data in
I want to generate some formatted output of data retrieved from an MS-Access database
I want to generate PDF from a html doc in a rails app. So
I have developed a jQuery API browser from the raw XML available from http://api.jquery.com/api/
I want to read from the text file which is placed in res/raw/text i
Let's say I have a class of 30 students and want generate every possible
I want to generate a thumbnail preview of videos in Java. I'm mostly JMF
I want to generate a list in C#. I am missing python's list comprehensions.
I want to generate a dict with the letters of the alphabet as the
I want to generate random numbers manually. I know that every language have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.