gpt4 book ai didi

web-services - 与grails签订第一份 SOAP 网络服务

转载 作者:行者123 更新时间:2023-12-02 15:38:02 25 4
gpt4 key购买 nike

在grails应用程序中编写契约(Contract)优先SOAP Web服务的最佳方法是什么?我发现有两个插件可用于编写契约(Contract)第一个Web服务1. Grails Metro插件2. Grails SpringWS插件。

但我不确定哪个最适合用于契约(Contract)优先的Web服务

最佳答案

作者不再支持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契约(Contract)的第一个终点。

关于web-services - 与grails签订第一份 SOAP 网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7022364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com