1   /***
2    *
3    * Copyright 2005 LogicBlaze, Inc.
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   **/
18  package org.logicblaze.lingo.jms;
19  
20  import org.logicblaze.lingo.LingoRemoteInvocationFactory;
21  import org.logicblaze.lingo.SimpleMetadataStrategy;
22  import org.logicblaze.lingo.example.ExampleService;
23  import org.logicblaze.lingo.example.ExampleServiceImpl;
24  import org.logicblaze.lingo.example.TestResultListener;
25  import org.logicblaze.lingo.jms.impl.MultiplexingRequestor;
26  
27  import javax.jms.Destination;
28  import javax.jms.Session;
29  
30  import java.util.List;
31  
32  /***
33   * Uses the multiplexing, multi-threaded requestor
34   *
35   * @version $Revision: 1.4 $
36   */
37  public class JmsMultiplexingRemotingTest extends JmsRemotingTest {
38  
39      public void testJmsProxyFactoryBeanAndAsyncServiceExporter() throws Throwable {
40          ExampleService target = new ExampleServiceImpl();
41          exporter = new JmsServiceExporter();
42          exporter.setServiceInterface(ExampleService.class);
43          exporter.setService(target);
44          configure(exporter);
45          subscribeToQueue(exporter, getDestinationName());
46  
47          pfb = new JmsProxyFactoryBean();
48          pfb.setServiceInterface(ExampleService.class);
49          pfb.setServiceUrl("http://myurl");
50          pfb.setRemoteInvocationFactory(new LingoRemoteInvocationFactory(new SimpleMetadataStrategy(true)));
51          Requestor requestor = createRequestor(getDestinationName());
52          pfb.setRequestor(requestor);
53          configure(pfb);
54          
55          ExampleService proxy = (ExampleService) pfb.getObject();
56  
57          TestResultListener listener = new TestResultListener();
58          proxy.asyncRequestResponse("IBM", listener);
59  
60          listener.waitForAsyncResponses(2);
61  
62          List results = listener.getResults();
63          System.out.println("Found results: " + results);
64  
65          assertEquals("size of results: " + results, 2, results.size());
66      }
67  
68      protected Requestor createRequestor(String name) throws Exception {
69          Session session = createSession();
70          JmsProducer producer = createJmsProducer();
71          return new MultiplexingRequestor(connection, session, producer.getMessageProducer(), session.createQueue(name), null, false);
72      }
73  }