cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dennis Sosnoski <...@sosnoski.com>
Subject Re: local transport testing
Date Fri, 09 Jul 2010 01:19:38 GMT
I think Brandon is trying to use the local transport, not HTTP transport 
with localhost.

The CXF test code uses local transport, though mainly with canned XML 
responses (for testing client) or requests (for testing server). I was 
able to make local transport work for testing between client and server 
by modifying the org.apache.cxf.jaxws.holder.HolderTest (from 
rt/frontend/jaxws/src/test) to first create the server and then connect 
the client:

    private final String address = "local://HolderService";

    @Override
    protected Bus createBus() throws BusException {
        return new CXFBusFactory().createBus();
    }

    @Test
    public void testClient() throws Exception {
        JaxWsServerFactoryBean svr = new JaxWsServerFactoryBean();
        svr.setBus(getBus());
        svr.setServiceBean(new HolderServiceImpl());
        svr.setAddress(address);
        svr.create();

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.getClientFactoryBean().setServiceClass(HolderService.class);
        factory.getClientFactoryBean().setBus(getBus());
        factory.getClientFactoryBean().setAddress(address);

        HolderService h = (HolderService)factory.create();
        Holder<String> holder = new Holder<String>();
        assertEquals("one", h.echo("one", "two", holder));
        assertEquals("two", holder.value);
    }

Using HTTP ports for unit testing is often a source of problems, so the 
local transport is great for this purpose.

  - Dennis

Dennis M. Sosnoski
XML and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Glen Mazza wrote:
> Shouldn't you be using "localhost" instead of just "local" in the URL?  But
> anyway, Step #1 here[1] might help you get Endpoint to work correctly.
>
> HTH,
> Glen
>
> [1] http://www.jroller.com/gmazza/entry/writing_junit_test_cases_for
>
>
> Brandon Richins-2 wrote:
>   
>> I would like to create a test for calling a service that is created from a
>> Java first approach.  I have tried the below test code as an example
>> without success.  I get an error complaining about the local protocol.
>>
>>     
>
>   

Mime
View raw message