You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Stefan Hübner <st...@googlemail.com> on 2007/04/06 17:21:15 UTC

HttpCore to mock remote servers in unit tests?

Hi,

The recent release of HttpCore's alpha release made me think, I could
use this library as a very lightweight server to mock remote services
in scenarios where I want my code to be integration tested. E.g. I
maintain a web application, which communicates with some backend
services via HTTP. In order to test the application's behaviour I want
to be able to create an environment where the application's requests
to it's backend services can actualy be monitored.

So I thought, I could set up a small server based on
HttpCore-components. I progressed up to the point where I actually
were about to check parameters of the requests, the mocked server
received. There I stuck since HttpCore's HttpRequest-Interface is
lacking any higher level API to read it's parameters.

Maybe, that interface is just not intended to serve use cases like the
one described above? Or did I miss something?

Anyone out there who tried something like this before?

Regards,
Stefan Hübner

Re: HttpCore to mock remote servers in unit tests?

Posted by Ole Matzura <ol...@eviware.com>.
Thanks Stefan

I'll check out simple as well.. it seems really cool..  as you say, who 
can say no to another good tool?

regards,

/Ole
eviware.com

Stefan Hübner wrote:
> 2007/4/6, Ole Matzura <ol...@eviware.com>:
>> Hi Stefan,
>>
>> I recommend you to use Jetty for this, it will allow you to do exactly
>> what you want (ie start a small service with few lines of code and
>> inject some handlers..), we use it in soapUI for mocking webservices and
>> it works just great..
>
> Yes, I was considering Jetty, but gave Simple a shot first
> (www.simpleframework.org) and I must say, it's great too!
>
> Another colleague of mine mentioned Jetty would be an option. See I
> didn't want too blow up a full servlet implementation to just do what
> I wanted to, but maybe Jetty is more (or less or something else too)
> than a plain Servlet engine.
>
> Thanks for giving me a spin to have a second look at it! It's always
> good, to have two or three sharp knifes in one's personal toolbox.
>
>
> Cheers,
> Stefan
>>
>> regards,
>>
>> /Ole
>> eviware.com
>>
>>
>> Stefan Hübner wrote:
>> > Thanks for clarifying that to me, Roland!
>> >
>> > Tomcat on the other hand is way too oversized, since I just want to
>> > start a small service with a few lines of code, inject a
>> > request/response-handler (e.g. based on JMock) run a test and shut
>> > that thing down again. Thought, HttpCore could provide me with the
>> > service part of it, but ok, that's what prototypes are good for,
>> > right?
>> >
>> > Regards,
>> > Stefan
>> >
>> > 2007/4/6, Roland Weber <os...@dubioso.net>:
>> >> Hi Stefan,
>> >>
>> >> > So I thought, I could set up a small server based on
>> >> > HttpCore-components.
>> >>
>> >> There's one in the test code for HttpCore, and a slightly different
>> >> one in the test code for HttpClient (though the latter still lacks
>> >> some pieces for expect-continue handling). Both are based on the
>> >> HttpService class and the ElementalHttpServer example.
>> >>
>> >> > I progressed up to the point where I actually
>> >> > were about to check parameters of the requests, the mocked server
>> >> > received. There I stuck since HttpCore's HttpRequest-Interface is
>> >> > lacking any higher level API to read it's parameters.
>> >> >
>> >> > Maybe, that interface is just not intended to serve use cases 
>> like the
>> >> > one described above?
>> >>
>> >> Exactly. "Core" is not a higher level API. See our project charter,
>> >> section "Project Scope", item 2:
>> >>
>> >>    Jakarta HttpComponents will provide ONLY a toolset of low level
>> >>    generic transport APIs. In particular, server side application
>> >>    layer APIs WILL NOT be developed.
>> >>    http://jakarta.apache.org/httpcomponents/charter.html
>> >>
>> >> Please use the Servlet API for that purpose, for example in Tomcat:
>> >>         http://tomcat.apache.org/
>> >> Our project charter was specifically drafted to avoid scope clashes
>> >> with other Apache projects.
>> >>
>> >> cheers,
>> >>   Roland
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: 
>> httpclient-user-unsubscribe@jakarta.apache.org
>> >> For additional commands, e-mail: 
>> httpclient-user-help@jakarta.apache.org
>> >>
>> >>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>> > For additional commands, e-mail: 
>> httpclient-user-help@jakarta.apache.org
>> >
>> >
>> >
>> >
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>>
>>



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpCore to mock remote servers in unit tests?

Posted by Tatu Saloranta <co...@yahoo.com>.
--- Stefan H�bner <st...@googlemail.com> wrote:

> 2007/4/6, Ole Matzura <ol...@eviware.com>:
,...
> Yes, I was considering Jetty, but gave Simple a shot
> first
> (www.simpleframework.org) and I must say, it's great
> too!
> 
> Another colleague of mine mentioned Jetty would be
> an option. See I
> didn't want too blow up a full servlet
> implementation to just do what
> I wanted to, but maybe Jetty is more (or less or
> something else too)
> than a plain Servlet engine.

Yes, it is possible to use Jetty as "raw" HTTP server
instead of going through Servlet interface (routing
and path mapping). It's rather simple thing to do, if
you prefer that. This can be used, for example, when
serving static or mostly static resources (images,
from files or generated). I have used it for such
purpose (exposing published xml product metadata
similar to an ftp server, but doing little bit of
caching and pre-fecthing from backend server) at work,
and it has worked well.

Of course, overhead of Servlet API implementation is
rather small, but if you really want to go commando,
it is possible.

-+ Tatu +-



 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpCore to mock remote servers in unit tests?

Posted by Stefan Hübner <st...@googlemail.com>.
2007/4/6, Ole Matzura <ol...@eviware.com>:
> Hi Stefan,
>
> I recommend you to use Jetty for this, it will allow you to do exactly
> what you want (ie start a small service with few lines of code and
> inject some handlers..), we use it in soapUI for mocking webservices and
> it works just great..

Yes, I was considering Jetty, but gave Simple a shot first
(www.simpleframework.org) and I must say, it's great too!

Another colleague of mine mentioned Jetty would be an option. See I
didn't want too blow up a full servlet implementation to just do what
I wanted to, but maybe Jetty is more (or less or something else too)
than a plain Servlet engine.

Thanks for giving me a spin to have a second look at it! It's always
good, to have two or three sharp knifes in one's personal toolbox.


Cheers,
Stefan
>
> regards,
>
> /Ole
> eviware.com
>
>
> Stefan Hübner wrote:
> > Thanks for clarifying that to me, Roland!
> >
> > Tomcat on the other hand is way too oversized, since I just want to
> > start a small service with a few lines of code, inject a
> > request/response-handler (e.g. based on JMock) run a test and shut
> > that thing down again. Thought, HttpCore could provide me with the
> > service part of it, but ok, that's what prototypes are good for,
> > right?
> >
> > Regards,
> > Stefan
> >
> > 2007/4/6, Roland Weber <os...@dubioso.net>:
> >> Hi Stefan,
> >>
> >> > So I thought, I could set up a small server based on
> >> > HttpCore-components.
> >>
> >> There's one in the test code for HttpCore, and a slightly different
> >> one in the test code for HttpClient (though the latter still lacks
> >> some pieces for expect-continue handling). Both are based on the
> >> HttpService class and the ElementalHttpServer example.
> >>
> >> > I progressed up to the point where I actually
> >> > were about to check parameters of the requests, the mocked server
> >> > received. There I stuck since HttpCore's HttpRequest-Interface is
> >> > lacking any higher level API to read it's parameters.
> >> >
> >> > Maybe, that interface is just not intended to serve use cases like the
> >> > one described above?
> >>
> >> Exactly. "Core" is not a higher level API. See our project charter,
> >> section "Project Scope", item 2:
> >>
> >>    Jakarta HttpComponents will provide ONLY a toolset of low level
> >>    generic transport APIs. In particular, server side application
> >>    layer APIs WILL NOT be developed.
> >>    http://jakarta.apache.org/httpcomponents/charter.html
> >>
> >> Please use the Servlet API for that purpose, for example in Tomcat:
> >>         http://tomcat.apache.org/
> >> Our project charter was specifically drafted to avoid scope clashes
> >> with other Apache projects.
> >>
> >> cheers,
> >>   Roland
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>

Re: HttpCore to mock remote servers in unit tests?

Posted by Ole Matzura <ol...@eviware.com>.
Hi Stefan,

I recommend you to use Jetty for this, it will allow you to do exactly 
what you want (ie start a small service with few lines of code and 
inject some handlers..), we use it in soapUI for mocking webservices and 
it works just great..

regards,

/Ole
eviware.com


Stefan Hübner wrote:
> Thanks for clarifying that to me, Roland!
>
> Tomcat on the other hand is way too oversized, since I just want to
> start a small service with a few lines of code, inject a
> request/response-handler (e.g. based on JMock) run a test and shut
> that thing down again. Thought, HttpCore could provide me with the
> service part of it, but ok, that's what prototypes are good for,
> right?
>
> Regards,
> Stefan
>
> 2007/4/6, Roland Weber <os...@dubioso.net>:
>> Hi Stefan,
>>
>> > So I thought, I could set up a small server based on
>> > HttpCore-components.
>>
>> There's one in the test code for HttpCore, and a slightly different
>> one in the test code for HttpClient (though the latter still lacks
>> some pieces for expect-continue handling). Both are based on the
>> HttpService class and the ElementalHttpServer example.
>>
>> > I progressed up to the point where I actually
>> > were about to check parameters of the requests, the mocked server
>> > received. There I stuck since HttpCore's HttpRequest-Interface is
>> > lacking any higher level API to read it's parameters.
>> >
>> > Maybe, that interface is just not intended to serve use cases like the
>> > one described above?
>>
>> Exactly. "Core" is not a higher level API. See our project charter,
>> section "Project Scope", item 2:
>>
>>    Jakarta HttpComponents will provide ONLY a toolset of low level
>>    generic transport APIs. In particular, server side application
>>    layer APIs WILL NOT be developed.
>>    http://jakarta.apache.org/httpcomponents/charter.html
>>
>> Please use the Servlet API for that purpose, for example in Tomcat:
>>         http://tomcat.apache.org/
>> Our project charter was specifically drafted to avoid scope clashes
>> with other Apache projects.
>>
>> cheers,
>>   Roland
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpCore to mock remote servers in unit tests?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2007-04-06 at 18:26 +0200, Stefan Hübner wrote:
> Thanks for clarifying that to me, Roland!
> 
> Tomcat on the other hand is way too oversized, since I just want to
> start a small service with a few lines of code, inject a
> request/response-handler (e.g. based on JMock) run a test and shut
> that thing down again. Thought, HttpCore could provide me with the
> service part of it, but ok, that's what prototypes are good for,
> right?
> 
> Regards,
> Stefan
> 

Stefan and all,

HttpCore is not meant to be a replacement or a competitor to Servlet
API. It is a merely bunch of low level components one can use to put
together a custom client, proxy or server side HTTP service. If all you
want is a lightweight Servlet container Jetty indeed appears to be the
best choice. At the same one can easily emulate Servlet API on top of
HttpCore (see to SimpleHttpServer used in Axis2 [1] for example)   

One may still consider using HttpCore 
(1) to be able to use the same API and the same components on the client
and the server side  
(2) to have a greater control over HTTP protocol than it is possible
with Servlet API
(3) to emulate various HTTP spec non-compliant behaviors 
(4) to take a full advantage of NIO buffering primitives

Hope this helps

Oleg

[1]
http://svn.apache.org/repos/asf/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/http/server/



> 2007/4/6, Roland Weber <os...@dubioso.net>:
> > Hi Stefan,
> >
> > > So I thought, I could set up a small server based on
> > > HttpCore-components.
> >
> > There's one in the test code for HttpCore, and a slightly different
> > one in the test code for HttpClient (though the latter still lacks
> > some pieces for expect-continue handling). Both are based on the
> > HttpService class and the ElementalHttpServer example.
> >
> > > I progressed up to the point where I actually
> > > were about to check parameters of the requests, the mocked server
> > > received. There I stuck since HttpCore's HttpRequest-Interface is
> > > lacking any higher level API to read it's parameters.
> > >
> > > Maybe, that interface is just not intended to serve use cases like the
> > > one described above?
> >
> > Exactly. "Core" is not a higher level API. See our project charter,
> > section "Project Scope", item 2:
> >
> >    Jakarta HttpComponents will provide ONLY a toolset of low level
> >    generic transport APIs. In particular, server side application
> >    layer APIs WILL NOT be developed.
> >    http://jakarta.apache.org/httpcomponents/charter.html
> >
> > Please use the Servlet API for that purpose, for example in Tomcat:
> >         http://tomcat.apache.org/
> > Our project charter was specifically drafted to avoid scope clashes
> > with other Apache projects.
> >
> > cheers,
> >   Roland
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpCore to mock remote servers in unit tests?

Posted by Stefan Hübner <st...@googlemail.com>.
Thanks for clarifying that to me, Roland!

Tomcat on the other hand is way too oversized, since I just want to
start a small service with a few lines of code, inject a
request/response-handler (e.g. based on JMock) run a test and shut
that thing down again. Thought, HttpCore could provide me with the
service part of it, but ok, that's what prototypes are good for,
right?

Regards,
Stefan

2007/4/6, Roland Weber <os...@dubioso.net>:
> Hi Stefan,
>
> > So I thought, I could set up a small server based on
> > HttpCore-components.
>
> There's one in the test code for HttpCore, and a slightly different
> one in the test code for HttpClient (though the latter still lacks
> some pieces for expect-continue handling). Both are based on the
> HttpService class and the ElementalHttpServer example.
>
> > I progressed up to the point where I actually
> > were about to check parameters of the requests, the mocked server
> > received. There I stuck since HttpCore's HttpRequest-Interface is
> > lacking any higher level API to read it's parameters.
> >
> > Maybe, that interface is just not intended to serve use cases like the
> > one described above?
>
> Exactly. "Core" is not a higher level API. See our project charter,
> section "Project Scope", item 2:
>
>    Jakarta HttpComponents will provide ONLY a toolset of low level
>    generic transport APIs. In particular, server side application
>    layer APIs WILL NOT be developed.
>    http://jakarta.apache.org/httpcomponents/charter.html
>
> Please use the Servlet API for that purpose, for example in Tomcat:
>         http://tomcat.apache.org/
> Our project charter was specifically drafted to avoid scope clashes
> with other Apache projects.
>
> cheers,
>   Roland
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpCore to mock remote servers in unit tests?

Posted by Roland Weber <os...@dubioso.net>.
Hi Stefan,

> So I thought, I could set up a small server based on
> HttpCore-components.

There's one in the test code for HttpCore, and a slightly different
one in the test code for HttpClient (though the latter still lacks
some pieces for expect-continue handling). Both are based on the
HttpService class and the ElementalHttpServer example.

> I progressed up to the point where I actually
> were about to check parameters of the requests, the mocked server
> received. There I stuck since HttpCore's HttpRequest-Interface is
> lacking any higher level API to read it's parameters.
> 
> Maybe, that interface is just not intended to serve use cases like the
> one described above?

Exactly. "Core" is not a higher level API. See our project charter,
section "Project Scope", item 2:

   Jakarta HttpComponents will provide ONLY a toolset of low level
   generic transport APIs. In particular, server side application
   layer APIs WILL NOT be developed.
   http://jakarta.apache.org/httpcomponents/charter.html

Please use the Servlet API for that purpose, for example in Tomcat:
	http://tomcat.apache.org/
Our project charter was specifically drafted to avoid scope clashes
with other Apache projects.

cheers,
  Roland


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org