It worked, thanks!

And for those out there wanting to have JUnit tests that involve HTTP
service with Restlet 2.3.x JEE edition, here's a handy trick:

Stick the following code in your test classes, either in each concrete
class or in a common abstract base:

    @BeforeClass
    public static void ensureHttpServer() {
        org.restlet.engine.Engine.getInstance().getRegisteredServers().add(
            new org.restlet.engine.connector.HttpServerHelper(null));
    }

The key is that you only want to do this once, which is why it's annotated
@BeforeClass rather than just @Before. Then you can create and start your
Restlet Component and Application(s) with @Before and stop them and tear
them down in @After. I like to make the test class extend Application, but
there are a number of other patterns that work here.

Of course you could just run your tests with the JSE edition, but I'm
happier running my tests against the same exact jars that I deploy with.

--tim

On Fri, Dec 19, 2014 at 3:23 PM, Thierry Boileau <tboil...@restlet.com>
wrote:
>
> Hi Tim,
>
> I think it is not called early enough. It should be done before the
> Component.getServers() method is called.
>
> --
> Thierry Boileau
>
> 2014-12-19 21:10 GMT+01:00 Tim Peierls <t...@peierls.net>:
>
>> I tried adding this line:
>>
>> Engine.getInstance().getRegisteredServers().add(
>>                 new org.restlet.engine.connector.HttpServerHelper(null));
>>
>> but it didn't seem to work -- maybe I didn't call it early enough. As far
>> as you know, though, that's all I should have to do?
>>
>> On Fri, Dec 19, 2014 at 3:08 PM, Thierry Boileau <tboil...@restlet.com>
>> wrote:
>>>
>>> wow, I need vacations!
>>> The fix is exactly: register these default connectors.
>>>
>>> Best regards,
>>> Thierry Boileau
>>>
>>>
>>> 2014-12-19 21:02 GMT+01:00 Thierry Boileau <tboil...@restlet.com>:
>>>
>>>> Hi Tim,
>>>>
>>>> I'm afraid I've taken all alone the decision to remove these files as
>>>> they appeared useless to me. I feel really sorry about that.
>>>> I revert back these changes on the 2.3 and master branches: that is to
>>>> say the JEE edition provides these connectors. However, I wonder if we have
>>>> to register these connectors by default, what is your thinking about that?
>>>>
>>>> And unfortunately, I won't be able to package a 2.3.1 release soon, I
>>>> can achieve this on the 29th of December.
>>>>
>>>>
>>>> Best regards,
>>>> Thierry Boileau
>>>>
>>>>
>>>>
>>>> 2014-12-19 20:34 GMT+01:00 Tim Peierls <t...@peierls.net>:
>>>>
>>>>> The default connectors for various editions have changed between 2.2
>>>>> and 2.3 (actually between 2.3-RC1 and 2.3.0). JEE edition no longer
>>>>> registers HTTP or HTTPS server helpers; JSE still does.
>>>>>
>>>>> Assuming this was intentional and not an oversight, the change causes
>>>>> problems for me. For several versions now I've been able to maintain one
>>>>> build that works both as a standalone deployment and when embedded in a 
>>>>> WAR
>>>>> for deployment in a production server running Tomcat. I've used the JEE
>>>>> edition because of the dependency on 
>>>>> org.restlet.ext.servlet.ServerServlet.
>>>>>
>>>>> (Why use Tomcat at all? There are better connectors for production
>>>>> purposes. Short answer is that it plays well with AWS Elastic Beanstalk.)
>>>>>
>>>>> With this latest change, however, the standalone deployment no longer
>>>>> works. I get message: No available server connector supports the
>>>>> required protocols: 'HTTP' Please add the jar of a matching connector to
>>>>> your classpath.
>>>>> <https://github.com/restlet/restlet-framework-java/blob/09c78b4737c1eda45a276dc284d4ffee61f8efca/modules/org.restlet/src/org/restlet/engine/Engine.java#L650-L663>
>>>>>
>>>>> It's because no HttpServerHelper has been registered in these lines
>>>>> <https://github.com/restlet/restlet-framework-java/blob/09c78b4737c1eda45a276dc284d4ffee61f8efca/modules/org.restlet/src/org/restlet/engine/Engine.java#L896-L901>
>>>>> for JEE (the "jee" token was added to the #ifndef list only a few days
>>>>> ago). I'd be happy to add the jar of a matching connector if there was one
>>>>> that the JEE edition supported, but the obvious candidates, Jetty and
>>>>> Simple, don't seem to be available for that edition.
>>>>>
>>>>> I'd be happy to switch to the JSE edition, but then I wouldn't be able
>>>>> to compile against org.restlet.ext.servlet.
>>>>>
>>>>> There's an existing issue which is vaguely related:
>>>>>
>>>>> https://github.com/restlet/restlet-framework-java/issues/876
>>>>>
>>>>> I'm not filing my own issue yet, because I don't see it as a bug, but
>>>>> I'd like advice on what to do here. I'd prefer not to have to make 
>>>>> separate
>>>>> builds -- it was a really nice property that I could run the same code and
>>>>> libraries either standalone or deployed as a WAR.
>>>>>
>>>>> --tim
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> *Thierry Boileau, Mr B*
>>>> +1 (408) 387-3184 • tboil...@restlet.com
>>>>
>>>> <http://restlet.com/>
>>>> 6 Rue Rose Dieng-Kuntz • Nantes, 44300 • France
>>>>
>>>
>>>
>>>
>>> --
>>> *Thierry Boileau, Mr B*
>>> +1 (408) 387-3184 • tboil...@restlet.com
>>>
>>> <http://restlet.com/>
>>> 6 Rue Rose Dieng-Kuntz • Nantes, 44300 • France
>>>
>>
>
>
> --
> *Thierry Boileau, Mr B*
> +1 (408) 387-3184 • tboil...@restlet.com
>
> <http://restlet.com/>
> 6 Rue Rose Dieng-Kuntz • Nantes, 44300 • France
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3093134

Reply via email to