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, submitContext );
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, "" ).split( JMS_ENDPOINT_SEPARATOR );
55 sessionName = getEndpointParameter( 0 );
56 send = getEndpointParameter( 1 );
57 receive = getEndpointParameter( 2 );
58 }
59
60 public static String[] extractEndpointParameters( Request request, SubmitContext context )
61 {
62 resolveOldEndpointPattern( request );
63
64 String endpoint = PropertyExpander.expandProperties( context, request.getEndpoint() );
65 String[] parameters = endpoint.replaceFirst( JMS_ENDPIONT_PREFIX, "" ).split( JMS_ENDPOINT_SEPARATOR );
66 return parameters;
67 }
68
69 private static void resolveOldEndpointPattern( Request request )
70 {
71 String oldEndpoint = request.getEndpoint();
72 if( oldEndpoint.contains( "/queue_" ) || oldEndpoint.contains( "/topic_" ) )
73 {
74 String newEndpoint = request.getEndpoint().replaceAll( JMS_OLD_ENDPOINT_SEPARATOR + "queue_",
75 JMS_ENDPOINT_SEPARATOR + "queue_" ).replaceAll( JMS_OLD_ENDPOINT_SEPARATOR + "topic_",
76 JMS_ENDPOINT_SEPARATOR + "topic_" ).replaceAll( JMS_OLD_ENDPOINT_SEPARATOR + "-",
77 JMS_ENDPOINT_SEPARATOR + "-" );
78
79 request.setEndpoint( newEndpoint );
80
81 refreshEndpointList( request, oldEndpoint, newEndpoint );
82
83 SoapUI.log( "JMS endpoint resolver changed endpoint pattern from " + oldEndpoint + "to " + newEndpoint );
84 }
85 }
86
87 private static void refreshEndpointList( Request request, String oldEndpoint, String newEndpoint )
88 {
89 Interface iface = request.getOperation().getInterface();
90 for( String endpoint : iface.getEndpoints() )
91 {
92 if( endpoint.equals( oldEndpoint ) )
93 {
94 iface.changeEndpoint( endpoint, newEndpoint );
95 }
96 }
97 }
98
99 private String getEndpointParameter( int i )
100 {
101 if( i > parameters.length - 1 )
102 return null;
103 String stripParameter = PropertyExpander.expandProperties( submitContext, parameters[i] ).replaceFirst(
104 QUEUE_ENDPOINT_PREFIX, "" ).replaceFirst( TOPIC_ENDPOINT_PREFIX, "" );
105 return stripParameter;
106 }
107
108 public String getSessionName()
109 {
110 return sessionName;
111 }
112
113 public String getSend()
114 {
115 return send;
116 }
117
118 public String getReceive()
119 {
120 return receive;
121 }
122 }