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.Session;
28  import java.util.List;
29  
30  /***
31   * Uses the multiplexing, multi-threaded requestor
32   *
33   * @version $Revision: 1.1 $
34   */
35  public class JmsMultiplexingRemotingTest extends JmsRemotingTest {
36  
37      public void testJmsProxyFactoryBeanAndAsyncServiceExporter() throws Throwable {
38          ExampleService target = new ExampleServiceImpl();
39          exporter = new JmsServiceExporter();
40          exporter.setServiceInterface(ExampleService.class);
41          exporter.setService(target);
42          exporter.setProducer(createJmsProducer());
43          configure(exporter);
44          subscribeToQueue(exporter, getDestinationName());
45  
46          pfb = new JmsProxyFactoryBean();
47          pfb.setServiceInterface(ExampleService.class);
48          pfb.setServiceUrl("http://myurl");
49          pfb.setRemoteInvocationFactory(new LingoRemoteInvocationFactory(new SimpleMetadataStrategy(true)));
50          pfb.setRequestor(createRequestor(getDestinationName()));
51          pfb.afterPropertiesSet();
52  
53          ExampleService proxy = (ExampleService) pfb.getObject();
54  
55          TestResultListener listener = new TestResultListener();
56          proxy.asyncRequestResponse("IBM", listener);
57  
58          listener.waitForAsyncResponses(2);
59  
60          List results = listener.getResults();
61          System.out.println("Found results: " + results);
62  
63          assertEquals("size of results: " + results, 2, results.size());
64      }
65  
66      protected Requestor createRequestor(String name) throws Exception {
67          Session session = createSession();
68          JmsProducer producer = createJmsProducer();
69          return new MultiplexingRequestor(session, producer, session.createQueue(name));
70      }
71  }