之前,有些朋友从开源的WS*应用(比如说Axis、CXF)迁移到WebLogic 9、10上,经常遇到类似下面的异常:
java.lang.UnsupportedOperationException: This
class
does not support SAAJ
1.3
at weblogic.webservice.core.soap.SOAPElementImpl.getElementQName(SOAPElementImpl.java:
651
)
at org.springframework.ws.soap.saaj.Saaj13Implementation.getName(Saaj13Implementation.java:
67
)
at org.springframework.ws.soap.saaj.SaajSoapEnvelope.getBody(SaajSoapEnvelope.java:
49
)
at org.springframework.ws.soap.AbstractSoapMessage.getSoapBody(AbstractSoapMessage.java:
35
)
at org.springframework.ws.soap.AbstractSoapMessage.getPayloadResult(AbstractSoapMessage.java:
56
)
这有一些历史因素在内,WebLogic 8.1的WebService协议栈,包含在weblogic.jar中。
SOAP栈的全部实现,都在weblogic.webservice.core.soap.* 这个Package中。
进入了Java5的时代后,JWS依靠Annotation方式,已经彻底改变WebService编程的外观,于是,随之而来的是,基于Java5的WebLogic 9/10,基本上使用Sun JWS方式实现Web Services,且WebLogic开始兼容新的WS* API,WebLogic的做法是deprecated以前的WS API(weblogic.webservice.core.soap.*),但为了8.1应用升级的兼容性考虑,用户依然使用较旧的包。
比如上述的NotSupport异常,在默认的WebLogic 9、10中%BEA_HOME%\modules\com.bea.core.weblogic.saaj_1.0.1.0.jar其实是Support的。
对WebLogic 8.1老用户来说,他们的WS*应用无需重新编码即可运行在WebLogic 9.2,此时默认使用老的协议栈【weblogic.webservice.core.soap.*】
对WebLogic 9.2新用户来说,他们也可以使用老协议栈,也可以使用新的协议栈,使用【weblogic.xml.saaj.*】
针对上述的NotSupport异常,有两种方式可以让应用使用新的API实现:
System.setProperty("javax.xml.soap.MessageFactory", "weblogic.xml.saaj.MessageFactoryImpl");
-Djavax.xml.soap.MessageFactory=weblogic.xml.saaj.MessageFactoryImpl
java.lang.UnsupportedOperationException: This
class
does not support
SAAJ
1.1
The actual
class
/
method in question is javax.xml.soap.Text.isComment(), which
appears to be implemented by
weblogic.webservice.core.soap.SOAPTextElement.isComment().
Stack trace is as follows:
DemoServlet received an unexpected exception:
java.lang.UnsupportedOperationException: This
class
does not support SAAJ
1.1
java.lang.UnsupportedOperationException: This
class
does not support SAAJ
1.1
at
weblogic.webservice.core.soap.SOAPTextElement.isComment(SOAPTextElement.java:
43
)
at
com.company.demo.servlet.DemoServlet.treeWalk(DemoServlet.java:
209
)
at
com.company.demo.servlet.DemoServlet.treeWalk(DemoServlet.java:
225
)
at
com.company.demo.servlet.DemoServlet.treeWalk(DemoServlet.java:
225
)
at
com.company.demo.servlet.DemoServlet.treeWalk(DemoServlet.java:
225
)
at
com.company.demo.servlet.DemoServlet.treeWalk(DemoServlet.java:
225
)
at
com.company.demo.servlet.DemoServlet.treeWalk(DemoServlet.java:
225
)
at
com.company.demo.servlet.DemoServlet.treeWalk(DemoServlet.java:
225
)
at
com.company.demo.servlet.DemoServlet.treeWalk(DemoServlet.java:
225
)
at
com.company.demo.servlet.DemoServlet.doGetOrPost(DemoServlet.java:
119
)
at com.company.demo.servlet.DemoServlet.doGet(DemoServlet.java:
44
)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
743
)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
856
)
at
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:
225
)
at
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:
127
)
at
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:
283
)
at
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:
175
)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:
3214
)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:
321
)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
121
)
at
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:
1983
)
at
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:
1890
)
at
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:
1344
)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:
209
)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:
181
)
很好,因为它们使用了更多的API,这些API在WebLogic的老协议栈【weblogic.webservice.core.soap.*】中没有被支持,使用新的即可。
我一般在重启WebLogic的时候,在startWebLogic.sh脚本中加入:
-Djavax.xml.soap.MessageFactory=weblogic.webservice.core.soap.MessageFactoryImpl -Djavax.xml.soap.SOAPFactory=weblogic.webservice.core.soap.SOAPFactoryImpl