WebObjects/Web 服务/在 MacOS-X 上与 WebServicesCore 集成
此文档由 Andrew Lindesay(http://www.lindesay.co.nz)于 2006 年撰写,作为 LEWOStuff 框架中支持代码的一部分,但此材料已在此处转录。它是在 WebObjects 5.2 和 5.3 以及 1.4 JVM 上编写。WebServicesCore 是 MacOS-X 中用于与互联网上提供的 SOAP 服务通信的框架。本页描述了在撰写本文时,在使 WebServicesCore 与 WebObjects 的 WebServices 框架正确通信方面存在的一些问题。
WebServicesCore 似乎无法处理从 AXIS 引擎返回的“多引用”值。要解决此问题,请在 WebObjects 应用程序中关闭多引用支持。为此,请找到server.wsdd文件以及元素 "parameter",其名称为 "sendMultiRefs"。修改此元素以使其值为 "false".
这是一个非常简单的反序列化器,可用于反序列化为nil。虽然这可能看起来不太有用,但在你使用 MacOS-X 的一部分 WebServicesCore 的情况下,它非常有用。
WebServicesCore 框架倾向于序列化一个nil参数为<xyz xsi:type="nil"/>。不幸的是,这缺少类型,因此 SOAP 引擎无法为该类型实例化正确反序列化器。正确的输出应该是<xyz xsi:type="xsd:timeInstant" xsi:nil="true"/>,但似乎很难让 WebServicesCore 执行此操作。
但是,无论传入类型如何,此反序列化器都能够将编码不当的nil转换为null在 Java 环境中。
你可以使用registerWebServicesCoreNilDeserialiserFactoryForKnownTypes在类LEWOWebServicesCoreNilDeserializerFactory上轻松设置常见的已知类。
package nz.co.lindesay.common.webobjects; /* ------------------------------------------------------------ LICENSE ------------------------------------------------------------ Copyright (c) 2006, Andrew Lindesay All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------ */ /** * <P>This is a <B>very</B> simple deserialiser that can be used * to deserialise to <TT>nil</TT>. Although this may seem less * than useful, it proves very useful in the situation where you * are using WebServicesCore which is a part of MacOS-X.</P> * * <P>The WebServicesCore framework tends to serialise a <TT>nil</TT> * argument as <TT><xyz xsi:type="nil"/></TT>. This is * unfortunately missing type and so the SOAP engine is not able * to instantiate the correct deserialiser for the type. The * correct output would be <TT><xyz xsi:type="xsd:timeInstant" xsi:nil="true"/></TT>, * but it appears that it may be difficult to get WebServicesCore * to do this.</P> * * <P>Regardless of the inbound type however, this serialiser will * be able to convert the poorly encoded <TT>nil</TT> to <TT>null</TT> * in the java environment.</P> * * <P>You can use the <TT>registerWebServicesCoreNilDeserialiserFactoryForKnownTypes</TT> * method on the class <TT>LEWOWebServicesCoreNilDeserializerFactory</TT> * to setup easily for common known classes.</P> */ public class LEWOWebServicesCoreNilDeserializer extends org.apache.axis.encoding.DeserializerImpl { // ------------------------------------------------- public LEWOWebServicesCoreNilDeserializer() { super(); } // ------------------------------------------------- public Object getValue() { return null; } // ------------------------------------------------- }
package nz.co.lindesay.common.webobjects; /* ------------------------------------------------------------ LICENSE ------------------------------------------------------------ Copyright (c) 2006, Andrew Lindesay All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------ */ import com.webobjects.foundation.*; import com.webobjects.appserver.*; import com.webobjects.eocontrol.*; import javax.xml.namespace.*; import java.util.*; /** * <P>See the class <TT>LEWOWebServicesCoreNilDeserializer</TT> * for more details about this class.</P> */ public class LEWOWebServicesCoreNilDeserializerFactory implements org.apache.axis.encoding.DeserializerFactory { public final static String NAMESPACEURI_ANON = "http://anonuri/"; private Set mechanisms = null; // ------------------------------------------------- /** * <P>This method will setup the deserialiser for * classes commonly encountered in development * of web services. This is a quick-setup that * might be invoked from the application setup.</P> */ public static void registerWebServicesCoreNilDeserialiserFactoryForCommonClasses(String namespaceURI) { Set classesS = new HashSet(); classesS.add(NSTimestamp.class); classesS.add(NSData.class); classesS.add(EOGlobalID.class); classesS.add(String.class); classesS.add(Number.class); classesS.add(Integer.class); classesS.add(Float.class); classesS.add(java.math.BigDecimal.class); classesS.add(java.util.Date.class); registerWebServicesCoreNilDeserialiserFactoryForClasses(classesS.iterator(),namespaceURI); } // ------------------------------------------------- /** * <P>This method will setup the deserialiser for the * classes supplied. This is a quick-setup that might * be invoked from the application startup.</P> */ public static void registerWebServicesCoreNilDeserialiserFactoryForClasses(Iterator classesI, String namespaceURI) { if(null==namespaceURI) namespaceURI = NAMESPACEURI_ANON; QName qn = new QName("http://anonuri/","nil"); LEWOWebServicesCoreNilDeserializerFactory factory = new LEWOWebServicesCoreNilDeserializerFactory(); while(classesI.hasNext()) WOWebServiceRegistrar.registerFactoriesForClassWithQName( null, factory, (Class) classesI.next(), qn); } // ------------------------------------------------- public LEWOWebServicesCoreNilDeserializerFactory() { super(); } // ------------------------------------------------- public javax.xml.rpc.encoding.Deserializer getDeserializerAs(String mechanismType) { return new LEWOWebServicesCoreNilDeserializer(); } // ------------------------------------------------- public Iterator getSupportedMechanismTypes() { if(null==mechanisms) { mechanisms = new HashSet(); mechanisms.add(org.apache.axis.Constants.AXIS_SAX); } return mechanisms.iterator(); } // ------------------------------------------------- }