1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.proxy.provider.remoting;
19
20 import org.apache.commons.proxy.ObjectProvider;
21 import org.apache.commons.proxy.exception.ObjectProviderException;
22
23 import javax.xml.namespace.QName;
24 import javax.xml.rpc.Service;
25 import javax.xml.rpc.ServiceException;
26 import javax.xml.rpc.ServiceFactory;
27 import java.net.MalformedURLException;
28 import java.net.URL;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class JaxRpcProvider implements ObjectProvider
43 {
44
45
46
47
48 private Class serviceInterface;
49 private String wsdlUrl;
50 private String serviceNamespaceUri;
51 private String serviceLocalPart;
52 private String servicePrefix;
53 private String portNamespaceUri;
54 private String portLocalPart;
55 private String portPrefix;
56
57
58
59
60
61 public JaxRpcProvider()
62 {
63 }
64
65 public JaxRpcProvider( Class serviceInterface )
66 {
67 this.serviceInterface = serviceInterface;
68 }
69
70
71
72
73
74 public Object getObject()
75 {
76 try
77 {
78 final Service service = ( wsdlUrl == null ?
79 ServiceFactory.newInstance().createService( getServiceQName() ) : ServiceFactory
80 .newInstance().createService( new URL( wsdlUrl ), getServiceQName() ) );
81 final QName portQName = getPortQName();
82 return portQName == null ? service.getPort( serviceInterface ) :
83 service.getPort( portQName, serviceInterface );
84 }
85 catch( ServiceException e )
86 {
87 throw new ObjectProviderException( "Unable to create JAX-RPC service proxy.", e );
88 }
89 catch( MalformedURLException e )
90 {
91 throw new ObjectProviderException( "Invalid URL given.", e );
92 }
93 }
94
95
96
97
98
99 public void setPortLocalPart( String portLocalPart )
100 {
101 this.portLocalPart = portLocalPart;
102 }
103
104 public void setPortNamespaceUri( String portNamespaceUri )
105 {
106 this.portNamespaceUri = portNamespaceUri;
107 }
108
109 public void setPortPrefix( String portPrefix )
110 {
111 this.portPrefix = portPrefix;
112 }
113
114 public void setServiceInterface( Class serviceInterface )
115 {
116 this.serviceInterface = serviceInterface;
117 }
118
119 public void setServiceLocalPart( String serviceLocalPart )
120 {
121 this.serviceLocalPart = serviceLocalPart;
122 }
123
124 public void setServiceNamespaceUri( String serviceNamespaceUri )
125 {
126 this.serviceNamespaceUri = serviceNamespaceUri;
127 }
128
129 public void setServicePrefix( String servicePrefix )
130 {
131 this.servicePrefix = servicePrefix;
132 }
133
134 public void setWsdlUrl( String wsdlUrl )
135 {
136 this.wsdlUrl = wsdlUrl;
137 }
138
139
140
141
142
143 private QName getPortQName()
144 {
145 return getQName( portNamespaceUri, portLocalPart, portPrefix );
146 }
147
148 private QName getQName( String namespaceUri, String localPart, String prefix )
149 {
150 if( namespaceUri != null && localPart != null && prefix != null )
151 {
152 return new QName( namespaceUri, localPart, prefix );
153 }
154 else if( namespaceUri != null && localPart != null )
155 {
156 return new QName( namespaceUri, localPart );
157 }
158 else if( localPart != null )
159 {
160 return new QName( localPart );
161 }
162 return null;
163 }
164
165 private QName getServiceQName()
166 {
167 return getQName( serviceNamespaceUri, serviceLocalPart, servicePrefix );
168 }
169 }
170