在Grails应用程序中编写合同优先SOAP Web服务的最佳方法是什么?我发现有两个插件可以写合同第一个webservice 1. Grails Metro插件2. Grails SpringWS插件。
但我不确定哪个最适合用于合同首次网络服务
答案 0 :(得分:1)
作者不再支持Grails SpringWS插件,没有人加紧接管支持。如果它对你有效,那么效果很好。一旦您需要自定义或存在错误,您就可以自己动手了。
我最终使用SpringWS并手动导入依赖项。这是BuildConfig.groovy中的依赖项部分:
dependencies {
runtime('org.springframework.ws:spring-ws:2.0.3.RELEASE')
runtime('org.springframework.ws:spring-ws-core:2.0.3.RELEASE')
runtime('org.springframework.ws:spring-ws-security:2.0.3.RELEASE')
runtime('org.springframework.ws:spring-ws-support:2.0.3.RELEASE')
runtime('org.springframework.ws:spring-xml:2.0.3.RELEASE')
runtime('com.sun.xml.wsit:wsit-rt:1.1')
runtime('commons-httpclient:commons-httpclient:3.0.1')
test('com.github.robfletcher:betamax:1.0')
}
然后以这种方式定义客户端:
import org.springframework.ws.transport.http.CommonsHttpMessageSender
beans = {
myMarshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) {
contextPath = "com.the.jaxb.beans.to.marshall"
}
wss4jSecurityInterceptor(org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor) {
securementActions = "UsernameToken"
securementPasswordType = "PasswordText"
}
myInterfaceTemplate(org.springframework.ws.client.core.WebServiceTemplate) {
marshaller = ref("myMarshaller")
unmarshaller = ref("myMarshaller")
messageSender = { CommonsHttpMessageSender ms -> }
interceptors = [wss4jSecurityInterceptor]
defaultUri = ""
}
}
那么你做
grails install-templates
并自定义您的web.xml:
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
我创建了一个spring-ws-servlet.xml
<context:component-scan base-package="com.bean.base.package"/>
<bean id="myTypes" class="org.springframework.xml.xsd.SimpleXsdSchema">
<property name="xsd" value="/WEB-INF/Types.xsd"/>
</bean>
<bean id="ContractFirstBeanName" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition"
p:wsdl="/WEB-INF/ContractFirstBeanName.wsdl"/>
<bean class="org.springframework.ws.transport.http.XsdSchemaHandlerAdapter"/>
<bean id="outputMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="com.output.beans"/>
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
<property name="interceptors">
<list>
<bean id="loggingInterceptor"
class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor">
<property name="logRequest" value="true"/>
<property name="logResponse" value="true"/>
</bean>
<ref local="wsSecurityInterceptor"/>
</list>
</property>
</bean>
<bean class="org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter">
<property name="transformLocations" value="true"/>
</bean>
<bean class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter">
<property name="messageFactory">
<bean class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
</property>
</bean>
<bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
<constructor-arg ref="outputMarshaller" index="0"/>
</bean>
<bean id="wsSecurityInterceptor"
class="org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor">
<property name="policyConfiguration" value="/WEB-INF/securityPolicy.xml"/>
<property name="callbackHandlers">
<list>
<ref bean="springWSSecurityHandler"/>
</list>
</property>
</bean>
<bean id="springWSSecurityHandler"
class="org.springframework.ws.soap.security.xwss.callback.SpringPlainTextPasswordValidationCallbackHandler">
<property name="authenticationManager" ref="authenticationManager"/>
</bean>
现在,这将以Grails为您提供Spring WS合约的第一个终点。
答案 1 :(得分:0)
相当老的帖子,但可能会帮助别人。
除了Rob的帖子:
除了安装模板以便能够修改web.xml之外,您还可以在scripts / _Events.groovy中动态添加MessageDispatcher servlet及其映射:
eventWebXmlEnd = { String tmpfile ->
GPathResult root = new XmlSlurper().parse(webXmlFile)
GPathResult servlets = root.servlet
servlets[servlets.size() - 1] + {
'servlet' {
'display-name'("web-services")
'servlet-name'("web-services")
'servlet-class'("org.springframework.ws.transport.http.MessageDispatcherServlet")
}
}
def servletMappings = root.'servlet-mapping'
servletMappings[servletMappings.size() - 1] + {
'servlet-mapping' {
'servlet-name'("web-services")
'url-pattern'("/services/*")
}
}
// update web.xml content
webXmlFile.text = new StreamingMarkupBuilder().bind {
mkp.declareNamespace("":"http://java.sun.com/xml/ns/javaee")
mkp.yield(root)
}
}