Here is example of usage Velocity templates for JIRA (or your own REST service).
Make ajax call from UI to REST service and you will get html content (or other data) that you needed. HtmlPresentationHelper class used as wrapper for html data.
You can use Jira integrated tool for debugging this (or yours) REST service: REST API Browser: https://developer.atlassian.com/display/DOCS/Using+the+REST+API+Browser/
And don't forget add your Velocity templates!
@Path("/")
public class CustomRestResource
{
private String pathToTemplate = "templates/reports/timesheet-report/";
private String templateFileName = "view.vm";
@GET
@Path("someMethod")
@AnonymousAllowed
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response anyName(@QueryParam("param") String param)
{
VelocityManager vm = ComponentAccessor.getVelocityManager();
try
{
return Response.ok(new HtmlPresentationHelper(
vm.getBody(pathToTemplate, templateFileName, prepareVelocityParams(param))
)).build();
}
catch (Exception ex)
{
ex.printStackTrace();
return Response.serverError().build();
}
}
Map<String, Object> prepareVelocityParams(String x)
{
Map<String, Object> velocityParams = new HashMap<String, Object>();
velocityParams.put("someParam", x);
velocityParams.put(...);
...
return velocityParams;
}
}
@XmlRootElement
public class HtmlPresentationHelper
{
@XmlElement
private String html;
private HtmlPresentationHelper()
{
// for JAXB
}
public HtmlPresentationHelper(String html)
{
this.html = html;
}
}