View Javadoc

1   package org.codehaus.xfire.test;
2   
3   import java.lang.reflect.Method;
4   
5   import javax.xml.namespace.QName;
6   
7   import org.codehaus.xfire.XFireRuntimeException;
8   import org.codehaus.xfire.service.FaultInfo;
9   import org.codehaus.xfire.service.MessageInfo;
10  import org.codehaus.xfire.service.OperationInfo;
11  import org.codehaus.xfire.service.Service;
12  import org.codehaus.xfire.service.ServiceInfo;
13  
14  /***
15   * Contains various <code>ServiceEndpoint</code> implementations. Mainly used throughout all the test classes which need
16   * <code>ServiceEndpoint</code> to test their code.
17   *
18   * @author <a href="mailto:poutsma@mac.com">Arjen Poutsma</a>
19   * @see Service
20   */
21  public class ServiceEndpoints
22  {
23      private ServiceEndpoints()
24      {
25      }
26  
27      /***
28       * Returns the endpoint for an echo service. The returned endpoint has the namespace
29       * <code>http://test.xfire.codehaus.org</code>, and it's name is <code>Echo</code>. It has on operation named
30       * <code>echo</code>, with an input message <code>echoRequest</code> and an output message
31       * <code>echoResponse</code>. Both messages contain a single part, named <code>echoRequestin0</code> and
32       * <code>echoResponseout</code> respectively.
33       * <p/>
34       * The endpoints <code>Class</code> and <code>Method</code> are mapped to {@link EchoImpl}.
35       *
36       * @return an echo service endpoint.
37       */
38      public static Service getEchoService()
39      {
40          Class echoClass = EchoImpl.class;
41          Method echoMethod = null;
42          try
43          {
44              echoMethod = echoClass.getMethod("echo", new Class[]{String.class});
45          }
46          catch (NoSuchMethodException e)
47          {
48              throw new XFireRuntimeException("Could not find echo method on Echo class", e);
49          }
50          ServiceInfo service = new ServiceInfo(new QName("http://test.xfire.codehaus.org", "Echo"), echoClass);
51          OperationInfo operation = service.addOperation("echo", echoMethod);
52          MessageInfo inputMessage = operation.createMessage(new QName("echoRequest"));
53          operation.setInputMessage(inputMessage);
54          MessageInfo outputMessage = operation.createMessage(new QName("echoResponse"));
55          operation.setOutputMessage(outputMessage);
56          inputMessage.addMessagePart(new QName("echoRequestin0"), String.class);
57          outputMessage.addMessagePart(new QName("echoResponseout"), String.class);
58  
59          return new Service(service);
60      }
61  
62      /***
63       * Returns the endpoint for an echo service with faults. This method returns the same as {@link #getEchoService()},
64       * but adds a fault to the operation. The fault is named <code>echoFault</code>, and has one part
65       * <code>echoFault0</code>.
66       *
67       * @return the echo service endpoint.
68       */
69      public static Service getEchoFaultService()
70      {
71          Service endpoint = getEchoService();
72          OperationInfo operation = endpoint.getServiceInfo().getOperation("echo");
73          FaultInfo fault = operation.addFault("echoFault");
74          fault.addMessagePart(new QName("echoFault0"), String.class);
75  
76          return endpoint;
77      }
78  }