简体   繁体   中英

How to Use Grizzly Embedded Server for Mule as Well as Jersey

I'm currently using JerseyTest w/ Grizzly embedded server to test some code. I do some very simple configuration to point it to the proper resources:

Map<String, String> initParams = new HashMap<String, String>();
initParams.put("com.sun.jersey.config.property.packages", "com.sample.service");
ApplicationDescriptor appDescriptor = new ApplicationDescriptor();
appDescriptor.setServletInitParams(initParams);
super.setupTestEnvironment(appDescriptor);

This works fine and the Jersey components are available and working as expected.

I'm now trying to add some Mule functionality to some of these Jersey calls, but Mule is not being properly initialized/configured by Grizzly. Has anyone gotten this kind of setup running? What additional configuration do I need to do with JerseyTest/GrizzlyWebServer to get it to initialize Mule properly?

While it is not ideal because the mule instance is not able to use Grizzly by default, I was able to get this working by staring up mule separately with:

    DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
    SpringXmlConfigurationBuilder configBuilder = new SpringXmlConfigurationBuilder("mule-config.xml");
    muleContext = muleContextFactory.createMuleContext(configBuilder);
    muleContext.start();

I'm not sure what you're trying to achieve but you can use the Mule Jersey connector. Mule will handle the HTTP requests (instead of Grizzly) and you'll keep the Jersey processing as is.

<service name="helloWorldResource">
         <inbound>
            <inbound-endpoint address="jersey:http://localhost:63081/" synchronous="true"/>
         </inbound>
<component class="org.mule.transport.jersey.HelloWorldResource"/>
</service>

http://www.mulesoft.org/display/JERSEY/User 's+Guide

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM