【问题标题】:Injecting services in Grails Cxf web services causes getter/setter generation在 Grails Cxf Web 服务中注入服务会导致生成 getter/setter
【发布时间】:2013-10-17 02:45:17
【问题描述】:

我有一个简化如下的 cxf 网络服务。我的问题是,如果我像下面这样注入服务,生成的 wsdl 也会有 setParameterService/getParameterService 和 getMessageSource/setMessageSource 方法。如果我不想将它们公开为 Web 服务,我应该怎么做?

@WebService(portName = "OrganizationPort", serviceName = "OrganizationService", name = "OrganizationService", targetNamespace = "http://akum.compugroup.com")
@SOAPBinding(parameterStyle = ParameterStyle.WRAPPED, use = Use.LITERAL, style = Style.DOCUMENT)
class OrganizationWebService {

def parameterService
def messageSource

static expose = EndpointType.JAX_WS

@WebMethod
@WebResult
Organization kurumSorgulama(@WebParam(partName = "KurumSorgulamaTalep", name = "KurumSorgulamaTalep", targetNamespace = "http://akum.compugroup.com") String kurumKodu) { 

    return organization
}

@WebMethod
@WebResult
Organization authorize(@WebParam(partName = "KurumSorgulamaTalep", name = "KurumSorgulamaTalep", targetNamespace = "http://akum.compugroup.com") String kurumKodu) {

    return organization
}

}

【问题讨论】:

    标签: grails dependency-injection cxf


    【解决方案1】:

    我稍微简化了代码,但这应该能让你运行起来。将服务端点设为私有,然后使用 @AutoWired 注释它们

    @WebService(portName = "OrganizationPort", serviceName = "OrganizationService", name = "OrganizationService", targetNamespace = "http://akum.compugroup.com")
    @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED, use = SOAPBinding.Use.LITERAL, style = SOAPBinding.Style.DOCUMENT)
    class OrganizationService {
    
        @Autowired
        private BoatService boatService
        @Autowired
        private CarService carService
    
        static expose = EndpointType.JAX_WS
    
        @WebMethod
        @WebResult
        String goFish(@WebParam(partName = "KurumSorgulamaTalep", name = "KurumSorgulamaTalep", targetNamespace = "http://akum.compugroup.com") String kurumKodu) {
            boatService.fish()
        }
    
        @WebMethod
        @WebResult
        String goHonk(@WebParam(partName = "KurumSorgulamaTalep", name = "KurumSorgulamaTalep", targetNamespace = "http://akum.compugroup.com") String kurumKodu) {
            carService.honkHorn()
        }
    }
    

    【讨论】:

    • 你也可以删除静态的expose = EndpointType.JAX_WS,因为你有@WebService注解可以做同样的事情。
    • 我将此示例添加到github.com/Grails-Plugin-Consortium/grails-cxf/blob/master/… 的 github 项目中,如果您获得项目源并在其上运行应用程序并使用 localhost:8080/grails-cxf,则可以使用 SOAP UI 调用它/services/organization?wsdl
    【解决方案2】:

    我从来没有为 Grails 应用程序这样做过,但通常你可以使用 @XmlTransient。此外,您可能需要在班级级别使用@XmlAccessorType(XmlAccessType.FIELD)

    【讨论】:

      【解决方案3】:

      你可以替换:

      @WebService(portName = "OrganizationPort", serviceName = "OrganizationService", name = "OrganizationService", targetNamespace = "http://akum.compugroup.com")
      

      与:

      @GrailsCxfEndpoint
      

      @GrailsCxfEndpoint 自动排除所有的 getter 和 setter。

      但是您将失去设置 portNameserviceNamenametargetNamespace 的能力。这正是我目前遇到的问题。

      @GrailsCxfEndpoint@WebService 混合也不是解决方案,因为它再次暴露了 getter 和 setter。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-27
        • 1970-01-01
        • 2012-11-02
        • 1970-01-01
        • 2013-01-03
        相关资源
        最近更新 更多