ServerOutInterceptor extends AbstractPhaseInterceptor<Message> { @Override public void handleMessage( final Message message ) { try { if ( InterceptorState.SERVER_OUT.isActive( message ) ) { HttpServletRequest req = ( HttpServletRequest ) message.getExchange().getInMessage() .get( AbstractHTTPDestination.HTTP_REQUEST ); if ( req.getLocalPort() == Common.DEFAULT_PUBLIC_SECURE_PORT ) { HttpHeaders headers = new HttpHeadersImpl( message.getExchange().getInMessage() ); String subutaiHeader = headers.getHeaderString( Common.SUBUTAI_HTTP_HEADER ); String path = req.getRequestURI(); if ( path.startsWith( "/rest/v1/peer" ) ) { handlePeerMessage( subutaiHeader, message ); } else { final String prefix = "/rest/v1/env"; if ( path.startsWith( prefix ) ) { String s = path.substring( prefix.length() + 1 ); String environmentId = s.substring( 0, s.indexOf( "/" ) ); handleEnvironmentMessage( subutaiHeader, environmentId, message ); } } } } } catch ( Exception e ) { throw new Fault( e ); } } ServerOutInterceptor( SecurityManager securityManager, PeerManager peerManager ); @Override void handleMessage( final Message message );  }
@Test public void testHandleMessage() throws Exception { Message message = InterceptorStateHelper.getMessage( InterceptorState.SERVER_OUT ); Exchange exchange = message.getExchange(); doReturn( message ).when( exchange ).getInMessage(); doReturn( request ).when( message ).get( AbstractHTTPDestination.HTTP_REQUEST ); doReturn( Common.DEFAULT_PUBLIC_SECURE_PORT ).when( request ).getLocalPort(); doReturn( "/rest/v1/peer" ).when( request ).getRequestURI(); try { interceptor.handleMessage( message ); } catch ( RuntimeException e ) { } verify( interceptor ).handlePeerMessage( anyString(), eq( message ) ); doReturn( "/rest/v1/env/123/" ).when( request ).getRequestURI(); try { interceptor.handleMessage( message ); } catch ( RuntimeException e ) { } verify( interceptor ).handleEnvironmentMessage( anyString(), anyString(), eq( message ) ); }