Wiki source code of Web Services-Problems

Version 3.1 by Pascal Robert on 2007/09/03 19:32

Show last authors
1 = Problems =
2
3 This section describes some problems and bugs that sometimes occur when using //WebObjects Web Services//.
4
5 == DirectToWebService can't return a WSDL with secure HTTPS references in it ==
6
7 **Authors:** Francis Labrie
8
9 **Affected products:** //WebObjects// 5.2.x, 5.3.x
10
11 **Bug reference:** rdar:~/~/3546304
12
13 === Problem: ===
14
15 A //DirectToWebService// defined Web Services doesn't return correct WSDL document, even if the correct procedure (see Secure Web Services) is followed. So only classes oriented Web Services manually registered with the
16
17 {{code}}
18
19 com.webobjects.appserver.WOWebServiceRegistrar
20
21 {{/code}}
22
23 class seems to generate a correct WSDL.
24
25 === Solution: ===
26
27 Darel Lee from Apple told me that right now, the dynamic WSDL generation is not exposed to developers so there currently isn't a clean solution to perform this. One workaround is to hardcode rules (ofcom.webobjects.directtoweb.Assignment type) with the serviceLocationURL key for each operation that you want to use secure HTTPS references. For instance:
28
29 {{code}}
30
31 ((operationName="anOperation") and (serviceName="Service")) ->
32 serviceLocationURL="https://host.net/cgi-bin/Service.woa/ws/Service"
33
34 {{/code}}
35
36 If you need all operation to be called using the secure protocol, you can also define a more generic rule like this one:
37
38 {{code}}
39
40 (serviceName="Service") ->
41 serviceLocationURL="https://host.net/cgi-bin/Service.woa/ws/Service"
42
43 {{/code}}
44
45 === SOAP serializers and deserializers registered with WOWebServiceRegistrar class doesn't appear in the WSDL schema ===
46
47 Authors:Francis Labrie
48 Affected products:WebObjects5.2.x, 5.3.x
49 Bug reference:rdar:~/~/3546330
50
51 ==== Problem: ====
52
53 Custom SOAP serializers and deserializers registered to Web Services with com.webobjects.appserver.WOWebServiceRegistrar class are never added to the types / schema definition of the WSDL. The only type definitions shown are the following:
54
55 {{code}}
56
57 <types>
58 <schema targetNamespace="http://lang.java/" xmlns:soapenc=
59 "http://schemas.xmlsoap.org/soap/encoding/" xmlns=
60 "http://www.w3.org/2001/XMLSchema">
61 <complexType name="Class">
62 <sequence/>
63 </complexType>
64 <complexType name="ArrayOf_xsd_any">
65 <complexContent>
66 <restriction base="soapenc:Array">
67 <attribute ref="soapenc:arrayType" wsdl:arrayType=
68 "xsd:any[]"/>
69 </restriction>
70 </complexContent>
71 </complexType>
72 <element name="ArrayOf_xsd_any" nillable="true" type=
73 "lang:ArrayOf_xsd_any"/>
74 </schema>
75 <schema targetNamespace="http://www.apple.com/webobjects/
76 webservices/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/
77 soap/encoding/" xmlns="http://www.w3.org/2001/XMLSchema">
78 <complexType name="EOGlobalID">
79 <element name="entityName" type="xsd:string"/>
80 <element name="primaryKeys" type="lang:ArrayOf_xsd_any"/>
81 </complexType>
82 <element name="EOGlobalID" type="tns:EOGlobalID"/>
83 <complexType name="EOEnterpriseObject">
84 <element name="entityName" type="xsd:string"/>
85 <element name="globalID" type="webobjects:EOGlobalID"/>
86 <element name="properties" type="soapenc:Struct"/>
87 </complexType>
88 </schema>
89 </types>
90
91 {{/code}}
92
93 ==== Solution: ====
94
95 I don't know any dynamic workaround right now... But a static and complete WSDL can be shared through a direct action. It's not very handy though...
96
97 === DirectToWebService can't return a WSDL with custom namespace and definitions name in it ===
98
99 Authors:Francis Labrie
100 Affected products:WebObjects5.2.x, 5.3.x
101 Bug reference:
102
103 ==== Problem: ====
104
105 A //DirectToWebService// defined Web Services can't return a WSDL with custom values for properties like namespaces and definitions name. Worse, the generated namespace can even contains WebObjects application instance number or the wrong hostname.
106
107 ==== Solution: ====
108
109 Base on a tips from Darel Lee, I've found in the com.webobjects.webservices.generation.//private.WOWSDLTemplate class some extras key definitions read from the user.d2wmodel DirectToWebService rule file. For instance~://
110
111 * **serviceLocationURL:** a key that allow the setting of the location URL for an operation. This is usefull if you need your WebServices to be reached using a secure HTTPS reference;
112 * **WSDLDefinitionName:** a key that allow the definitions name change. So instead of having "ServiceNameDefinition", you can set this value;
113 * **WSDLTargetNamespace:** a key that allow the namespace change. This is the most usefull: you can avoid dynamic generation depending on WebObjects HTTP Adaptor? with this.
114
115 Here is an example of rule definition changing the above values:
116
117 {{code}}
118
119 (se(serviceName="Service") ->
120 WSDLTargetNamespace="https://host.net/cgi-bin/Service.woa/ws/Service"
121 (serviceName="Service") ->
122 WSDLDefinitionName="AnotherDefinition"
123 ((operationName="anOperation") and (serviceName="Service")) ->
124 serviceLocationURL="https://host.net/cgi-bin/Service.woa/ws/Service"
125
126 {{/code}}
127
128 === WOWebServiceClient class can't connect to a server that requires an authentication (WO 5.2.x, Bug ID 3568441) ===
129
130 Authors:Francis Labrie
131 Affected products:WebObjects5.2.x, 5.3.x
132 Bug reference:rdar:~/~/3568441
133
134 ==== Problem: ====
135
136 The com.webobjects.webservices.client.WOWebServiceClientclass can't connect to a server that requires a Basic HTTP Authentication despite the fact this class offers a way to register a security delegate (see setSecurityDelegateForServiceNamed(Object, String) instance method).
137
138 Normally, the processClientRequest(MessageContext) delegate method (see com.webobjects.webservices.support.WOSecurityDelegateinterface documentation) would allow an easy way to set a username and a password to the message context. But there is a problem related to the design of the class: to register a security delegate, the WOWebServiceClientclass has to fetch the Web Services Definition Language (WSDL) XML document. But to get access to this WSDL, an authentication header must be set. This is the classic chicken and egg problem...
139
140 ==== Solution: ====
141
142 The best would be to add a default method to WOWebServiceClientclass to register a default security delegate that is not related to a service name before the class fetch the WSDL. But unfortunately, all key methods that would allow this kind of behavior change are privates, so subclassing is not a solution...
143
144 But a workaround is still possible:
145
146 1. Fetch the WSDL document yourself and store it to the local filesystem, using the java.net.URL instance and setting up the Basic HTTP Authentication header field of the java.net.URLConnection yourself;
147 1. Instanciate another java.net.URL class that refer to the local WSDL document file;
148 1. Instanciate the com.webobjects.webservices.client.WOWebServiceClient<>code> class using the file URL;
149 1. Set for each service a security delegate that will add the proper credential information for the Basic HTTP Authentication.
150
151 That's it. It looks like a big hack, but it works...
152
153 === Web Services can't return a WSDL with secure HTTPS references specifying port other than the default 443 ===
154
155 Authors:Francis Labrie
156 Affected products:WebObjects5.2.x, 5.3.x
157 Bug reference:rdar:~/~/4196417
158
159 ==== Problem: ====
160
161 HTTPS protocol references can be published in Web Services WSDL. But unfortunately, WebObjects seems to ignore ports other than the default 443.
162
163 This problem is related to the bad waycom.webobjects.appserver.WORequestbuild the URL prefix: if the protocol is secure and no port (i.e. 0) is set when calling the//completeURLPrefix(StringBuffer,boolean,int)method, the port will always be 443. Unfortunately, Web Servicescom.webobjects.appserver.//private.WOWebServiceclass seems to call this method without setting the port number.
164
165 ==== Solution: ====
166
167 To work around this bug, you can subclass the com.webobjects.appserver.WORequest class like this:
168
169 {{code}}
170
171  package com.smoguli.appserver;
172
173 import com.webobjects.appserver.WORequest;
174 import com.webobjects.foundation.NSData;
175 import com.webobjects.foundation.NSDictionary;
176
177 /**
178 * This class provide fixed {@link com.webobjects.appserver.WORequest} methods.
179 * To use it, just overload the {@link com.webobjects.appserver.WOApplication.
180 * createRequest(String,String,String,NSDictionary,NSData,NSDictionary)} method
181 * to instanciate this class instead.
182 *
183 * @author Francis Labrie <francis.labrie at smoguli.com>
184 */
185 public class WOFixedRequest extends WORequest {
186
187 /**
188 * @see com.webobjects.appserver.WORequest#WORequest(String,String,String,
189 * NSDictionary,NSData,NSDictionary)
190 */
191 public WOFixedRequest(String method, String url, String httpVersion, NSDictionary headers, NSData content, NSDictionary info) {
192 super(method, url, httpVersion, headers, content, info);
193 } // WOFixedRequest
194
195 /**
196 * This method builds the URL prefix into the <code>urlPrefix</code> buffer
197 * with the appropriate protocol (<code>http</code> or <code>https</code>)
198 * and the right TCP port. But unlike the {@link com.webobjects.appserver.
199 * WORequest#_completeURLPrefix(StringBuffer,boolean,int} method, it
200 * supports secure HTTP protocol (<code>https</code>) with port other than
201 * <code>443</code>, even if the <code>port</code> parameter is set
202 * <code>0</code>.
203 *
204 * @param urlPrefix the buffer that receives the contructed URL.
205 * @param isSecure a flag indicating if the protocol is secure.
206 * @param port the port number.
207 */
208 public void _completeURLPrefix(StringBuffer urlPrefix, boolean isSecure, int port) {
209 if(isSecure && (port == 0)) {
210 String serverPort;
211
212 serverPort = _serverPort();
213 if((serverPort != null) && !serverPort.equals("443")) {
214 try {
215 port = Integer.parseInt(serverPort);
216 } catch(NumberFormatException exception) {} // catch
217 } // if
218 } // if
219
220 super._completeURLPrefix(urlPrefix, isSecure, port);
221 } // _completeURLPrefix
222 } // WOFixedRequest
223
224 {{/code}}