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();
}
// -------------------------------------------------
}