1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.submit.transports.jms;
13
14 import com.eviware.soapui.SoapUI;
15 import com.eviware.soapui.model.iface.Interface;
16 import com.eviware.soapui.model.iface.Request;
17 import com.eviware.soapui.model.iface.SubmitContext;
18 import com.eviware.soapui.model.propertyexpansion.PropertyExpander;
19
20 public class JMSEndpoint
21 {
22 public static final String JMS_OLD_ENDPOINT_SEPARATOR = "/";
23 public static final String JMS_ENDPOINT_SEPARATOR = "::";
24 public static final String QUEUE_ENDPOINT_PREFIX = "queue_";
25 public static final String TOPIC_ENDPOINT_PREFIX = "topic_";
26 public static final String JMS_EMPTY_DESTIONATION = "-";
27 public static final String JMS_ENDPIONT_PREFIX = "jms://";
28 Request request;
29 SubmitContext submitContext;
30 String[] parameters;
31 String sessionName;
32 String send;
33 String receive;
34
35 public JMSEndpoint( Request request, SubmitContext submitContext )
36 {
37 this.request = request;
38 this.submitContext = submitContext;
39 parameters = extractEndpointParameters( request );
40 sessionName = getEndpointParameter( 0 );
41 send = getEndpointParameter( 1 );
42 receive = getEndpointParameter( 2 );
43 }
44
45 public JMSEndpoint( String sessionName, String send, String receive )
46 {
47 this.sessionName = sessionName;
48 this.send = send;
49 this.receive = receive;
50 }
51
52 public JMSEndpoint( String jmsEndpointString )
53 {
54 parameters = jmsEndpointString.replaceFirst( JMS_ENDPIONT_PREFIX, "" )
55 .split( JMS_ENDPOINT_SEPARATOR );
56 sessionName = getEndpointParameter( 0 );
57 send = getEndpointParameter( 1 );
58 receive = getEndpointParameter( 2 );
59 }
60
61 public static String[] extractEndpointParameters( Request request )
62 {
63 resolveOldEndpointPattern( request );
64
65 String[] parameters = request.getEndpoint().replaceFirst( JMS_ENDPIONT_PREFIX, "" )
66 .split( JMS_ENDPOINT_SEPARATOR );
67 return parameters;
68 }
69
70 private static void resolveOldEndpointPattern( Request request )
71 {
72 String oldEndpoint = request.getEndpoint();
73 if( oldEndpoint.contains( "/queue_" ) || oldEndpoint.contains( "/topic_" ) )
74 {
75 String newEndpoint = request.getEndpoint().replaceAll( JMS_OLD_ENDPOINT_SEPARATOR + "queue_",
76 JMS_ENDPOINT_SEPARATOR + "queue_" ).replaceAll( JMS_OLD_ENDPOINT_SEPARATOR + "topic_",
77 JMS_ENDPOINT_SEPARATOR + "topic_" ).replaceAll( JMS_OLD_ENDPOINT_SEPARATOR + "-",
78 JMS_ENDPOINT_SEPARATOR + "-" );
79
80 request.setEndpoint( newEndpoint );
81
82 refreshEndpointList( request, oldEndpoint, newEndpoint );
83
84 SoapUI.log( "JMS endpoint resolver changed endpoint pattern from " + oldEndpoint + "to " + newEndpoint );
85 }
86 }
87
88 private static void refreshEndpointList( Request request, String oldEndpoint, String newEndpoint )
89 {
90 Interface iface = request.getOperation().getInterface();
91 for( String endpoint : iface.getEndpoints() )
92 {
93 if( endpoint.equals( oldEndpoint ) )
94 {
95 iface.changeEndpoint( endpoint, newEndpoint );
96 }
97 }
98 }
99
100 private String getEndpointParameter( int i )
101 {
102 if( i > parameters.length - 1 )
103 return null;
104 String stripParameter = PropertyExpander.expandProperties( submitContext, parameters[i] ).replaceFirst(
105 QUEUE_ENDPOINT_PREFIX, "" ).replaceFirst( TOPIC_ENDPOINT_PREFIX, "" );
106 return stripParameter;
107 }
108
109 public String getSessionName()
110 {
111 return sessionName;
112 }
113
114 public String getSend()
115 {
116 return send;
117 }
118
119 public String getReceive()
120 {
121 return receive;
122 }
123 }