集成Spring和Axis

  集成Spring Framework和Axis的一个简单方案,使Axis Web服务引擎可以使用Spring的IoC容器和AOP技术。要使用SpringProvider,Axis的server-config.wsdd配置例子如下:
        <service name="SpringTestService" provider="java:SPRING">
              <parameter name="beanName" value="springTest"/>
              <parameter name="allowedMethods" value="*"/>
        </service>
 
        配置Spring的applicationContext.xml如下:
        <beans>
              <bean id="springTest" class="org.samples.SpringAxisTest"/>
        </beans>
 
        以下是集成Spring Framework和Axis引擎的类结构图,可以使用同样的方法集成Axis和其他IoC容器(如PicoContainer)。
 

Click to view in original size 496 x 444

 

       以上类图中,紫色的是Spring Framework原有的类;草绿和天蓝色的类是Axis原有的类,其中草绿色的类需要做些修改;只有橙色的是需要开发的类。以下是SpringProvider类的代码片断:

public class SpringProvider extends RPCProvider {
      protected static Log log = LogFactory.getLog(SpringProvider.class.getName());

      public static final String OPTION_BEANNAME = "beanName";

      protected Object makeNewServiceObject(MessageContext msgContext, String clsName) throws Exception {
           String beanName = getStrOption(OPTION_BEANNAME, msgContext.getService());
           return getService(beanName, msgContext);
      }

      protected String getServiceClassNameOptionName() {
           return OPTION_BEANNAME;
      }

      protected Object getService(String beanName, MessageContext context) throws AxisFault {
           ApplicationContext appContext = getAppContext(context);
           if (appContext == null) {
                 log.fatal("Spring ApplicationContext is NULL.");
                 throw new AxisFault("get Spring ApplicationContext error.");
           }

           Object bean = appContext.getBean(beanName);
           if (bean == null) {
                 log.error("bean named:" + beanName + " is NULL");
                 throw new AxisFault("bean named:" + beanName + " is NULL");
           }
           return bean;
       }

       protected String getStrOption(String optionName, Handler service) {
            String value = null;
            if (service != null)
                  value = (String) service.getOption(optionName);
            if (value == null)
                  value = (String) getOption(optionName);
            return value;
       }

       protected Class getServiceClass(String beanName, SOAPService service, MessageContext msgContext) throws AxisFault {
            ConfigurableListableBeanFactory beanFactory = getBeanFactory(msgContext);
            if (beanFactory == null) {
                 log.error("BeanFactory is NULL");
                 throw new AxisFault("BeanFactory is NULL");
            }
            Object bean = beanFactory.getBeanDefinition(beanName);
            return bean.getClass();
        }

        protected XmlWebApplicationContext getAppContext(MessageContext msgContext) {
             HttpServlet servlet = (HttpServlet) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLET);
             ServletContext servletContext = servlet.getServletContext();
             XmlWebApplicationContext appContext = (XmlWebApplicationContext) servletContext
                     .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
             return appContext;
        }

        private final ConfigurableListableBeanFactory getBeanFactory(MessageContext msgContext) {
             XmlWebApplicationContext appContext = getAppContext(msgContext);
             return appContext.getBeanFactory();
        }
}

阅读更多

SpringAxis集成 加Handler时的问题。

09-11

我把Spring和Axis结合好了,但是在参照:http://www.jactiongroup.net/reference2/html/remoting.html#d0e38036rn中的:17.5.4:注册自己的处理方法(Handler验证时),配置文件时出错。rn[有意思的是这个文档中handler配置文件和17.5.1中客户访问的配置文件是同一个Bean,如下所示rn但是,Handler配置文件放在服务器端的,怎么能和客户端访问用同一个Bean]rn rn ...rn rn我的配置在文件在:ApplicationContext。xml,但是运行时出错:(注,注释掉这个bean,游览器能访问到这个服务的)rn XML validation disabledrn- Root WebApplicationContext: initialization startedrn- Loading Spring root WebApplicationContextrn- JDK 1.4+ collections availablern- Commons Collections 3.x availablern- Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]rn- Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [helloWorld,fileReception,fileHandlerJRPF]; root of BeanFactory hierarchyrn- 3 beans defined in application context [Root WebApplicationContext]rn- Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@10dc6b5]rn- Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@1de17f4]rn- Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@1cd0888]rn- Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [helloWorld,fileReception,fileHandlerJRPF]; root of BeanFactory hierarchy]rn- Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [helloWorld,fileReception,fileHandlerJRPF]; root of BeanFactory hierarchyrn- Context initialization failedrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileHandlerJRPF' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.xml.rpc.ServiceException: Error processing WSDL document: rnjava.io.IOException: Server returned HTTP response code: 503 for URL: http://localhost/FileReception/services/urn:FileAttachmentsService?wsdlrnCaused by: rnjavax.xml.rpc.ServiceException: Error processing WSDL document: rnjava.io.IOException: Server returned HTTP response code: 503 for URL: http://localhost/FileReception/services/urn:FileAttachmentsService?wsdlrn at org.apache.axis.client.Service.initService(Service.java:250)rn at org.apache.axis.client.Service.(Service.java:165)rn ----------------------------------------------rnApplicationContext。xml文件内容:rn rnrn rn com.memdi.filereception.IFileReceptionrn rn ......rn rn rn http://localhost/FileReception/services/urn:FileAttachmentsService?wsdlrn rn rn rn rn http://localhost/FileReception/services/urn:FileAttachmentsServicern rn rn rn----------------------------------

springaxis集成问题,could not find deserializer

05-15

AxisFaultrn faultCode: http://schemas.xmlsoap.org/soap/envelope/Server.userExceptionrn faultSubcode:rn faultString: org.xml.sax.SAXException: Deserializing parameter 'ValidateUsersResult': could not find deserializer for type http://tempuri.org/RegUserItemrn faultActor:rn faultNode:rn faultDetail:rnrnorg.xml.sax.SAXException: Deserializing parameter 'ValidateUsersResult': could not find deserializer for type http://tempuri.org/RegUserItemrnrnspring的版本是2.0,基本上是安装spring2.0的手册一步步配置的,查了很多资料和论坛发现有不少人遇到这个问题,但就是没有解决方法。。rnrn感觉是导入的包或者是命名空间的问题,wsdl自己又不太熟。。rnrn代码如下:rnrnspring配置文件:rn 1. rn 2. rn 3. com.fortinet.service.openAPI.ticket.model.econnect.TicketServiceBridgeSoap rn 4. rn 5. rn 6. http://172.22.13.2/ForticareWebService/TicketService.asmx?WSDL rn 7. rn 8. rn 9. http://tempuri.org/ rn 10. rn 11. rn 12. TicketService rn 13. rn 14. rn 15. TicketServiceSoap rn 16. rn 17. rn 18. rn 19. rn 20. rn 21. rn 22. rn 23. rnrn实现自定义类注册功能的factorybeanrn 1. package com.fortinet.service.openAPI.ticket.model.econnect; rn 2. rn 3. import javax.xml.namespace.QName; rn 4. import javax.xml.rpc.Service; rn 5. import javax.xml.rpc.encoding.TypeMapping; rn 6. import javax.xml.rpc.encoding.TypeMappingRegistry; rn 7. rn 8. import org.apache.axis.encoding.ser.BeanDeserializerFactory; rn 9. import org.apache.axis.encoding.ser.BeanSerializerFactory; rn 10. import org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean; rn 11. rn 12. import com.fortinet.service.openAPI.ticket.model.RegUserItem; rn 13. rn 14. public class AxisPortProxyFactoryBean extends JaxRpcPortProxyFactoryBean rn 15. protected void postProcessJaxRpcService(Service service) rn 16. TypeMappingRegistry registry = service.getTypeMappingRegistry(); rn 17. TypeMapping mapping = registry.createTypeMapping(); rn 18. registerBeanMapping(mapping, RegUserItem.class, "RegUserItem"); rn 19. registry.register("http://schemas.xmlsoap.org/soap/encoding/", mapping); rn 20. rn 21. rn 22. protected void registerBeanMapping(TypeMapping mapping, Class type, String name) rn 23. QName qName = new QName("http://tempuri.org/", name); rn 24. mapping.register(type, qName, rn 25. new BeanSerializerFactory(type, qName), rn 26. new BeanDeserializerFactory(type, qName)); rn 27. rn 28. rn 29. rnrn供使用的wsdl文件,webservice是用.net由另外一个人实现的:rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# ... rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn# rn#

没有更多推荐了,返回首页