0

all I have a problem.

I wanna how to cross domain configuration in jetty. don't have web.xml file.

source here.

... ...

Server jetty = new Server();
    HandlerList hl = new HandlerList();
    hl.addHandler(sch);
    jetty.setHandler(hl);
    jetty.setThreadPool(new QueuedThreadPool(NumberUtils.toInt(config.getProperty("ambariplus.jetty.threadPoolSize"))));

    SelectChannelConnector conn = new SelectChannelConnector();
    conn.setMaxIdleTime(NumberUtils.toInt(config.getProperty("ambariplus.jetty.maxIdleTime")));
    conn.setPort(NumberUtils.toInt(config.getProperty("ambariplus.jetty.port")));

    MBeanContainer mbc = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    mbc.setDomain(config.getProperty("ambariplus.jmx.domain") + ".jetty");
    jetty.getContainer().addEventListener(mbc);
    jetty.addBean(mbc);

    jetty.addConnector(conn);
    jetty.setStopAtShutdown(true);

    try{
        jetty.start();
        logger.info("Jetty started at port {} on {}", conn.getPort(), "127.0.0.1");

        String s1 = StringUtils.substring(config.getProperty("ambariplus.jetty.rootServlet.contextPath"), 1);
        String s2 = StringUtils.substringBetween(
            config.getProperty("ambariplus.jetty.jerseyServlet.urlPattern"), "/", "/*");

...

1 Answers1

0

One standard technique is to implement a servlet filter. There are many such examples online, one is here. To do what you want you just need to set the CORS headers. The filter could be as simple as two lines to call chain.doFilter then set the Access-Control-Allow-Origin header on the filter's response. Since you don't have a web.xml there is a Jetty way to configure filters, you can find many examples online such as this SO post.

Community
  • 1
  • 1
Jason Winnebeck
  • 1,254
  • 1
  • 10
  • 15