Jump to content

Custom RepositoryService and URLStreamHandler in Jaspersoft Studio

Go to solution Solved by zharsing,

Recommended Posts

Hi everybody,

I am looking to add my custom RepositoryService to Jaspersoft Studio. I have implemented a custom protocol using a new URLStreamHandlerFactory. My code works just fine when use it in my application, although I would like to have the same functionality in the workbench at design time.


import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.net.URLConnection;import java.net.URLStreamHandler;import java.util.Arrays;import net.sf.jasperreports.engine.DefaultJasperReportsContext;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperReportsContext;import net.sf.jasperreports.engine.SimpleJasperReportsContext;import net.sf.jasperreports.repo.DefaultRepositoryService;import net.sf.jasperreports.repo.RepositoryService;public class CustomRepositoryService extends DefaultRepositoryService {    public CustomRepositoryService(JasperReportsContext parent) {        super(parent);        setURLStreamHandlerFactory(proto -> {            return "myproto".equals(proto) ? new URLStreamHandler() {                @Override                protected URLConnection openConnection(URL u) throws IOException {                    return new URLConnection(u) {                        @Override                        public void connect() throws IOException {                            // noop                        }                        @Override                        public InputStream getInputStream() throws IOException {                            // do custom stuff to retrieve the data stream                            return super.getInputStream();                        }                    };                }            } : null;        });    }}[/code]

Usage example snippet

        SimpleJasperReportsContext ctx = new SimpleJasperReportsContext();        CustomRepositoryService repositoryService = new CustomRepositoryService(DefaultJasperReportsContext.getInstance());        ctx.setExtensions(RepositoryService.class, Arrays.asList(repositoryService));        JasperFillManager fillManager = JasperFillManager.getInstance(ctx);        JasperPrint jasperPrint = fillManager.fill(jasperReport, parameters);[/code]

JRXML example snippet


Is it possible to attach this solution to the Jaspesoft Studio?
Is there a better way to achieve the same goal?

Any help would be much appreciated!

Best Regards,

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...