Wiki source code of Web Services-Problems

Version 6.1 by Francis Labrie on 2007/09/26 11:17

Hide last authors
Francis Labrie 6.1 1 = Problems =
Pascal Robert 2.1 2
3 This section describes some problems and bugs that sometimes occur when using //WebObjects Web Services//.
4
Francis Labrie 6.1 5 == DirectToWebService can't return a WSDL with secure HTTPS references in it ==
Pascal Robert 2.1 6
Francis Labrie 6.1 7 **Authors:** Francis Labrie
8 **Affected products:** //WebObjects// 5.2.x, 5.3.x
9 **Bug reference:** [[rdar://3546304]]
Pascal Robert 2.1 10
Francis Labrie 6.1 11 === Problem: ===
Pascal Robert 2.1 12
Francis Labrie 6.1 13 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 ##com.webobjects.appserver.WOWebServiceRegistrar## class seems to generate a correct WSDL.
Pascal Robert 2.1 14
Francis Labrie 6.1 15 === Solution: ===
Pascal Robert 2.1 16
Francis Labrie 6.1 17 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 (of ##com.webobjects.directtoweb.Assignment## type) with the ##serviceLocationURL## key for each operation that you want to use secure HTTPS references. For instance:
Pascal Robert 2.1 18
19 {{code}}
20
Francis Labrie 6.1 21 ((operationName="anOperation") and (serviceName="Service")) ->
22 serviceLocationURL="https://host.net/cgi-bin/Service.woa/ws/Service"
Pascal Robert 2.1 23
24 {{/code}}
25
Francis Labrie 6.1 26 If you need all operation to be called using the secure protocol, you can also define a more generic rule like this one:
Pascal Robert 2.1 27
28 {{code}}
29
Francis Labrie 6.1 30 (serviceName="Service") ->
31 serviceLocationURL="https://host.net/cgi-bin/Service.woa/ws/Service"
Pascal Robert 2.1 32
33 {{/code}}
34
Francis Labrie 6.1 35 === SOAP serializers and deserializers registered with ##WOWebServiceRegistrar## class doesn't appear in the WSDL schema ===
Pascal Robert 2.1 36
Francis Labrie 6.1 37 **Authors:** Francis Labrie
38 **Affected products:** //WebObjects// 5.2.x, 5.3.x
39 **Bug reference:** [[rdar://3546330]]
Pascal Robert 2.1 40
Francis Labrie 6.1 41 ==== Problem: ====
Pascal Robert 2.1 42
Francis Labrie 6.1 43 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:
Pascal Robert 2.1 44
Francis Labrie 6.1 45 {{code}}
Pascal Robert 2.1 46
Francis Labrie 6.1 47 <types>
Pascal Robert 2.1 48 <schema targetNamespace="http://lang.java/" xmlns:soapenc=
49 "http://schemas.xmlsoap.org/soap/encoding/" xmlns=
50 "http://www.w3.org/2001/XMLSchema">
51 <complexType name="Class">
52 <sequence/>
53 </complexType>
54 <complexType name="ArrayOf_xsd_any">
55 <complexContent>
56 <restriction base="soapenc:Array">
57 <attribute ref="soapenc:arrayType" wsdl:arrayType=
58 "xsd:any[]"/>
59 </restriction>
60 </complexContent>
61 </complexType>
62 <element name="ArrayOf_xsd_any" nillable="true" type=
Francis Labrie 6.1 63 "lang:ArrayOf_xsd_any"/>
Pascal Robert 2.1 64 </schema>
65 <schema targetNamespace="http://www.apple.com/webobjects/
66 webservices/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/
67 soap/encoding/" xmlns="http://www.w3.org/2001/XMLSchema">
68 <complexType name="EOGlobalID">
69 <element name="entityName" type="xsd:string"/>
70 <element name="primaryKeys" type="lang:ArrayOf_xsd_any"/>
71 </complexType>
Francis Labrie 6.1 72 <element name="EOGlobalID" type="tns:EOGlobalID"/>
Pascal Robert 2.1 73 <complexType name="EOEnterpriseObject">
74 <element name="entityName" type="xsd:string"/>
75 <element name="globalID" type="webobjects:EOGlobalID"/>
76 <element name="properties" type="soapenc:Struct"/>
77 </complexType>
78 </schema>
79 </types>
80
Francis Labrie 6.1 81 {{/code}}
Pascal Robert 2.1 82
Francis Labrie 6.1 83 ==== Solution: ====
84
85 You must know that all complexe data types referred in operations will be added to the WSDL types definition. But if a complexe type makes references to others complexe types, you should make sure you add proper calls in the ##writeSchema(Types)## method of the class serializer. For example:
86
smmccraw 4.1 87 {{code}}
Pascal Robert 2.1 88
Francis Labrie 6.1 89 public boolean writeSchema(Types types)
90 throws Exception {
91 ...
92 // Add type for Foo
93 types.writeType(Foo.class, _FooQName);
94 ...
smmccraw 4.1 95
Francis Labrie 6.1 96 return true;
97 }
Pascal Robert 2.1 98
Francis Labrie 6.1 99 {{/code}}
Pascal Robert 2.1 100
Francis Labrie 6.1 101 Unfortunately, I don't know a dynamic workaround for all possible cases right now. At least a static and complete WSDL can be shared through a direct action, but it's not very handy though...
Pascal Robert 2.1 102
Francis Labrie 6.1 103 === DirectToWebService can't return a WSDL with custom namespace and definitions name in it ===
Pascal Robert 2.1 104
Francis Labrie 6.1 105 **Authors:** Francis Labrie
106 **Affected products:** //WebObjects// 5.2.x, 5.3.x
107 **Bug reference:**
Pascal Robert 2.1 108
Francis Labrie 6.1 109 ==== Problem: ====
Pascal Robert 2.1 110
Francis Labrie 6.1 111 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.
Pascal Robert 2.1 112
Francis Labrie 6.1 113 ==== Solution: ====
Pascal Robert 2.1 114
Francis Labrie 6.1 115 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:
smmccraw 4.1 116
Francis Labrie 6.1 117 * **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;
118 * **WSDLDefinitionName:** a key that allow the definitions name change. So instead of having "ServiceNameDefinition", you can set this value;
119 * **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.
120
Pascal Robert 2.1 121 Here is an example of rule definition changing the above values:
122
123 {{code}}
124
Francis Labrie 6.1 125 (se(serviceName="Service") ->
126 WSDLTargetNamespace="https://host.net/cgi-bin/Service.woa/ws/Service"
127 (serviceName="Service") ->
128 WSDLDefinitionName="AnotherDefinition"
129 ((operationName="anOperation") and (serviceName="Service")) ->
130 serviceLocationURL="https://host.net/cgi-bin/Service.woa/ws/Service"
Pascal Robert 2.1 131
Francis Labrie 6.1 132 {{/code}}
Pascal Robert 2.1 133
Francis Labrie 6.1 134 === WOWebServiceClient class can't connect to a server that requires an authentication (WO 5.2.x, Bug ID 3568441) ===
Pascal Robert 2.1 135
Francis Labrie 6.1 136 **Authors:** Francis Labrie
137 **Affected products:** //WebObjects// 5.2.x, 5.3.x
138 **Bug reference:** [[rdar://3568441]]
Pascal Robert 2.1 139
Francis Labrie 6.1 140 ==== Problem: ====
Pascal Robert 2.1 141
Francis Labrie 6.1 142 The ##com.webobjects.webservices.client.WOWebServiceClient## class 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).
Pascal Robert 2.1 143
Francis Labrie 6.1 144 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 ##WOWebServiceClient## class 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...
Pascal Robert 2.1 145
Francis Labrie 6.1 146 ==== Solution: ====
Pascal Robert 2.1 147
Francis Labrie 6.1 148 The best would be to add a default method to ##WOWebServiceClient## class 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...
Pascal Robert 2.1 149
Francis Labrie 6.1 150 But a workaround is still possible:
Pascal Robert 2.1 151
Francis Labrie 6.1 152 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;
153 1. Instanciate another ##java.net.URL## class that refer to the local WSDL document file;
154 1. Instanciate the ##com.webobjects.webservices.client.WOWebServiceClient## class using the file URL;
Pascal Robert 2.1 155 1. Set for each service a security delegate that will add the proper credential information for the Basic HTTP Authentication.
156
157 That's it. It looks like a big hack, but it works...
158
Francis Labrie 6.1 159 === Web Services can't return a WSDL with secure HTTPS references specifying port other than the default 443 ===
Pascal Robert 2.1 160
Francis Labrie 6.1 161 **Authors:** Francis Labrie
162 **Affected products:** //WebObjects// 5.2.x, 5.3.x
163 **Bug reference:** [[rdar://4196417]]
164
165 ==== Problem: ====
166
Pascal Robert 2.1 167 HTTPS protocol references can be published in Web Services WSDL. But unfortunately, WebObjects seems to ignore ports other than the default 443.
168
Francis Labrie 6.1 169 This problem is related to the bad way ##com.webobjects.appserver.WORequest## builds 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 Services ##com.webobjects.appserver.##//##private.WOWebService## class seems to call this method without setting the port number.
Pascal Robert 2.1 170
Francis Labrie 6.1 171 ==== Solution: ====
Pascal Robert 2.1 172
Francis Labrie 6.1 173 To work around this bug, you can subclass the ##com.webobjects.appserver.WORequest## class like this:
174
175 {{code}}
176
smmccraw 4.1 177 package com.smoguli.appserver;
Pascal Robert 2.1 178
179 import com.webobjects.appserver.WORequest;
180 import com.webobjects.foundation.NSData;
181 import com.webobjects.foundation.NSDictionary;
182
Francis Labrie 6.1 183 /**
Pascal Robert 2.1 184 * This class provide fixed {@link com.webobjects.appserver.WORequest} methods.
185 * To use it, just overload the {@link com.webobjects.appserver.WOApplication.
Francis Labrie 6.1 186 * createRequest(String,String,String,NSDictionary,NSData,NSDictionary)} method
Pascal Robert 2.1 187 * to instanciate this class instead.
188 *
Francis Labrie 6.1 189 * @author Francis Labrie <francis.labrie at smoguli.com>
Pascal Robert 2.1 190 */
191 public class WOFixedRequest extends WORequest {
192
Francis Labrie 6.1 193 /**
194 * @see com.webobjects.appserver.WORequest#WORequest(String,String,String,
195 * NSDictionary,NSData,NSDictionary)
196 */
197 public WOFixedRequest(String method, String url, String httpVersion, NSDictionary headers, NSData content, NSDictionary info) {
198 super(method, url, httpVersion, headers, content, info);
199 } // WOFixedRequest
Pascal Robert 2.1 200
Francis Labrie 6.1 201 /**
202 * This method builds the URL prefix into the <code>urlPrefix</code> buffer
203 * with the appropriate protocol (<code>http</code> or <code>https</code>)
204 * and the right TCP port. But unlike the {@link com.webobjects.appserver.
205 * WORequest#_completeURLPrefix(StringBuffer,boolean,int} method, it
206 * supports secure HTTP protocol (<code>https</code>) with port other than
207 * <code>443</code>, even if the <code>port</code> parameter is set
208 * <code>0</code>.
209 *
210 * @param urlPrefix the buffer that receives the contructed URL.
211 * @param isSecure a flag indicating if the protocol is secure.
212 * @param port the port number.
213 */
214 public void _completeURLPrefix(StringBuffer urlPrefix, boolean isSecure, int port) {
215 if(isSecure && (port == 0)) {
216 String serverPort;
Pascal Robert 2.1 217
Francis Labrie 6.1 218 serverPort = _serverPort();
219 if((serverPort != null) && !serverPort.equals("443")) {
220 try {
221 port = Integer.parseInt(serverPort);
222 } catch(NumberFormatException exception) {} // catch
223 } // if
224 } // if
Pascal Robert 2.1 225
Francis Labrie 6.1 226 super._completeURLPrefix(urlPrefix, isSecure, port);
227 } // _completeURLPrefix
228 } // WOFixedRequest
Pascal Robert 2.1 229
230 {{/code}}