Plugin that outputs XML file on the fly

I'm trying to build a plugin that outputs a stream of XML on the fly, per HTTP request. I'm new to the Java way of doing something like this. Is there a way to do this from within TeamCity without having to create a corresponding JSP file? Right now I'm inheriting from BaseController and using WebControllerManager to register that controller with TeamCity. All the documentation I look up seems to say that I need a corresponding JSP file for that controller. Is there a way to output a stream of XML to a browser/client without having a corresponding physical JSP file on disk? Thanks!

0
7 comments

You can obtain output stream from HttpServletResponse object (getOutputStream() method) and write your own data as you like. Do not forget to close stream after that.

0

That gets me closer to where I want to be


However, I'm still having trouble accessing my registered Controller via a URL. Tomcat keeps returning 404 errors no matter what format I try to put in. I have tried to access the Controller via http://<server_name>/Controller and http://<server_name>/Controller.html. Both of these URLs return a 404 error, but appending .html to the URL actually returns an error in the logs; the first URL does not. Is there something else I need to do to register the Controller properly besides making a call to  webControllerManager.registerController()?

0

Your controller should be accessible by the url which you are using when you register it in the web controller manager. The only restriction: url must end with .html. If you will attach here your code probably I will see where is the problem.

0

Here's how I am registering my controller inside my plugin's constructor:

webControllerManager.registerController("controller.html", new MyController(server));


Here is the controller class:

public class MyController extends BaseController {
    public MyController(SBuildServer server) {
        super(server);
        System.out.println("BigVisibleController intialized.");
    }
    protected ModelAndView doHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        System.out.println("processing request inside MyController.");
        httpServletResponse.getOutputStream().print("hello world");
        httpServletResponse.getOutputStream().close();
        return null;
    }
}


Accessing it via http://<servername>/controller or http://<servername>/controller.html does not work.

Does that help flesh out the problem?

0

Try to add leading / to the path: /controller.html

0

that did the trick. thanks!

0

Thank you for your feedback, javadoc fixed

0

Please sign in to leave a comment.