[ 
http://issues.apache.org/jira/browse/AXIS2-546?page=comments#action_12374174 ] 

rnell commented on AXIS2-546:
-----------------------------

Please close, threads trying to launch separate listeners on same port.  I 
needed to configure a new Context for each thread or reuse an existing one as 
by default a new context is created for each thread all competing for the same 
port.

> Multithreaded client dies with JVM_BIND address already in use
> --------------------------------------------------------------
>
>          Key: AXIS2-546
>          URL: http://issues.apache.org/jira/browse/AXIS2-546
>      Project: Apache Axis 2.0 (Axis2)
>         Type: Bug

>   Components: client-api
>     Versions: 0.95
>     Reporter: rnell
>  Attachments: test.zip
>
> I created a multithreaded client using junitperf on the samples provided with 
> axis2.  I launch 10 copies of the client and each tries to bind to the same 
> port.  Seems each client (thread) should use the same listener.  Self 
> contained demonstration code is provided in attached zip.
> The blocking/single transport code works.  The nonblocking/dual transport 
> fails.
> Exception and code below.  I'll try to attach zip of code as well.
> 16:12:58,311 DEBUG [SimpleHttpServer] Starting test HTTP server on port 6060
> 16:12:58,326 ERROR [SimpleHTTPServer] java.net.BindException: Address already 
> in use: JVM_Bind
> org.apache.axis2.AxisFault: Address already in use: JVM_Bind; nested 
> exception is: 
>       java.net.BindException: Address already in use: JVM_Bind
>       at 
> org.apache.axis2.transport.http.SimpleHTTPServer.start(SimpleHTTPServer.java:193)
> import com.clarkware.junitperf.LoadTest;
> import com.clarkware.junitperf.TestFactory;
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
> public class EchoNonBlockingDualClientPerfTester extends TestCase {
>     public static Test suite() {
>         TestSuite suite = new TestSuite();
>         suite.addTest( makeLoadTest( 10, 1 ) );
>         return suite;
>     }
>     public static Test makeLoadTest( int users, int iterations ) {
>         Test factory = new TestFactory( EchoNonBlockingDualClientTester.class 
> );
>         Test loadTest = new LoadTest( factory, users, iterations );
>         return loadTest;
>     }
>     public static void main( String[] args ) {
>         junit.textui.TestRunner.run( suite() );
>     }
> }
> import com.sempra.client.ClientUtil;
> import org.apache.axis2.AxisFault;
> import org.apache.axis2.addressing.EndpointReference;
> import org.apache.axis2.client.Options;
> import org.apache.axis2.client.ServiceClient;
> import org.apache.axis2.client.async.AsyncResult;
> import org.apache.axis2.client.async.Callback;
> import org.apache.ws.commons.om.OMElement;
> import javax.xml.namespace.QName;
> import javax.xml.stream.XMLOutputFactory;
> import javax.xml.stream.XMLStreamException;
> import java.io.StringWriter;
> import java.net.URL;
> public class EchoNonBlockingDualClientTester extends junit.framework.TestCase 
> {
>     private static EndpointReference targetEPR = new EndpointReference( 
> "http://localhost:8080/axis2/services/MyService"; );
>     static int seq = 0;
>     static int getSequence() {
>         return seq++;
>     }
>     public void test() throws Throwable {
>         try {
>             final OMElement payload = TestClientUtil.getEchoOMElement( 
> getSequence() );
>             Options options = new Options();
>             options.setTo( targetEPR );
>             options.setTransportInProtocol( new URL( targetEPR.getAddress() 
> ).getProtocol() );
>             options.setUseSeparateListener( true );
>             options.setAction( "urn:echo" );
>             //Callback to handle the response
>             Callback callback = new Callback() {
>                 public void onComplete( AsyncResult result ) {
>                     try {
>                         StringWriter writer = new StringWriter();
>                         result.getResponseEnvelope().serialize( 
> XMLOutputFactory.newInstance().createXMLStreamWriter( writer ) );
>                         writer.flush();
>                         System.out.println( writer.toString() );
>                         String request = payload.getFirstChildWithName( new 
> QName( "Text" ) ).getText();
>                         OMElement body = 
> result.getResponseEnvelope().getBody();
>                         OMElement echo = body.getFirstChildWithName( new 
> QName( "echo" ) );
>                         OMElement text = echo.getFirstChildWithName( new 
> QName( "Text" ) );
>                         String response = text.getText();
>                         assertEquals( request, response );
>                     }
>                     catch( XMLStreamException e ) {
>                         onError( e );
>                     }
>                 }
>                 public void onError( Exception e ) {
>                     e.printStackTrace();
>                 }
>             };
>             //Non-Blocking Invocation
>             ServiceClient sender = new ServiceClient();
>             sender.setOptions( options );
>             sender.sendReceiveNonBlocking( payload, callback );
>             ClientUtil.waitForCallback( callback, 30000 );
>             assertTrue( callback.isComplete() );
>             //Need to close the Client Side Listener.
>             System.exit( 0 );
>         }
>         catch( AxisFault axisFault ) {
>             axisFault.printStackTrace();
>         }
>         catch( Exception ex ) {
>             ex.printStackTrace();
>         }
>     }
>     public static void main( String[] args ) {
>         junit.textui.TestRunner.run( EchoNonBlockingDualClientTester.class );
>     }
> }
> import org.apache.ws.commons.om.OMElement;
> import org.apache.ws.commons.om.OMFactory;
> import org.apache.ws.commons.om.OMAbstractFactory;
> import org.apache.ws.commons.om.OMNamespace;
> public class TestClientUtil {
>         public static OMElement getEchoOMElement( int clientId ) {
>         OMFactory fac = OMAbstractFactory.getOMFactory();
>         OMNamespace omNs = fac.createOMNamespace( 
> "http://example1.org/example1";, "example1" );
>         OMElement method = fac.createOMElement( "echo", omNs );
>         OMElement value = fac.createOMElement( "Text", omNs );
>         value.addChild( fac.createText( value, "Axis2 Echo String clientId=" 
> + clientId ) );
>         method.addChild( value );
>         return method;
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to