« Return to Thread: Metro 2.0 and tubes

Re: Metro 2.0 and tubes

by metro-3 :: Rate this Message:

Reply to Author | View in Thread

ramapulavarthi, your blog shows the old way of plugging the tubes and in fact I could not get it to work that way with Metro 2.0.

Anyway, after looking at the wiki and checking out some of the existing metro tubes I've managed to get it working.  

Here's the basic for anybody else that's interested.

1.  Create your tube, extending com.sun.xml.ws.api.pipe.helper.AbstractFilterTubeImpl is probably easiest.  e.g.

public class MyTube extends AbstractFilterTubeImpl {

    MyTube(Tube next) {
        super(next);
    }

    MyTube(MyTube that, TubeCloner cloner) {
        super(that, cloner);
    }

    @Override
    public NextAction processRequest(Packet packet) {
         // do something with the request
        return super.processRequest(packet);
    }

    @Override
    public NextAction processResponse(Packet packet) {
        // do something with the response        
        return super.processResponse(packet);
    }    

    @Override
    public MyTube copy(TubeCloner cloner) {
        return new MyTube(this, cloner);
    }
}

2.  Create an implementation of TubeFactory.  For the Server tubeline you need to get the Terminal tube and not the Tubeline Head as I did originally which created strange result, such as the request message being returned as the response message.

public class CustomTubeFactory implements TubeFactory {

    public Tube createTube(ClientTubelineAssemblyContext context) throws WebServiceException {        
        return new MyTube(context.getTubelineHead());            
    }

    public Tube createTube(ServerTubelineAssemblyContext context) throws WebServiceException {        
        return new MyTube(context.getTerminalTube());
    }
}

3.  Create a metro.xml file and place in META-INF directory. You can put your TubeFactory implementation in client-side, endpoint-side or both.

<?xml version="1.0" encoding="UTF-8"?>
<metro  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://java.sun.com/xml/ns/metro/config' version="1.0">
    <tubelines default="#test-tubline">
        <tubeline name="test-tubeline">
        <client-side>
        <tube-factory className="test.CustomTubeFactory" />
        </client-side>
          <endpoint-side>
             <tube-factory className="test.CustomTubeFactory" />
          </endpoint-side>
        </tubeline>
    </tubelines>
</metro>

thats it.
[Message sent by forum member 'ruroshin' (ruroshin)]

http://forums.java.net/jive/thread.jspa?messageID=354299

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

 « Return to Thread: Metro 2.0 and tubes