如何在Spring MVC中使用第三方WSDL服务

斯里哈里

我编写了一些服务(由Android应用程序使用),该服务接受请求并以json发送响应。现在,我有一个场景,我必须通过提供的WSDL文件使用第三方Web服务。我不知道该怎么做,有人可以帮忙吗?

这是我的dispatcher-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans ">

    <context:property-placeholder location="classpath:jdbc.properties" />   
    <context:component-scan base-package="com.srihari" />

    <tx:annotation-driven transaction-manager="hibernateTransactionManager" /> 

    <mvc:annotation-driven />

    <bean id="jspViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/view/" />
        <property name="suffix" value=".jsp" />
    </bean>

     <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${database.driver}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.user}" />
        <property name="password" value="${database.password}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>              
                <value>com.srihari.model.User</value>                       
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
               <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
    </bean>

    <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean> 
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>

//This is used to convert my requests and responses into json automatically

    <bean id="jacksonMessageChanger" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes" value="application/json"/>
    </bean>

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <util:list id="beanList">
                <ref bean="jacksonMessageChanger"/>
            </util:list>
        </property>
    </bean>

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="mediaTypes">
            <map>
                <entry key="json" value="application/json"/>
                <entry key="html" value="text/html"></entry>
                <entry key="xml" value="application/xml"></entry>
            </map>
        </property>
    </bean>

</beans>

这是我的简单控制器:这些服务运行正常

@Controller
@RequestMapping("/home")
public class UserController {

    @RequestMapping(value="/getallusers",method = RequestMethod.GET)
    public @ResponseBody List<User> getallusers() 
    {
        List<User> allUsersDetails =userServices.getAllUsers();
        return allUsersDetails;
    }
}

这是第三方提供的WSDL文件

POST /someservices/otherService.asmx HTTP/1.1
Host: sriharicorp.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/CreateCard"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <UserCredentials xmlns="http://tempuri.org/">
      <Password>string</Password>
      <Username>string</Username>
    </UserCredentials>
  </soap:Header>
  <soap:Body>

Example String Request 

    <CreateCard xmlns="http://tempuri.org/">
      <request>
        <DePpAcctCreationDate>string</DePpAcctCreationDate>
        <DePpAcctCreationTime>string</DePpAcctCreationTime>
        //Some other fields also
      </request>
    </CreateCard>
  </soap:Body>
</soap:Envelope>

字符串响应示例

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CreateCardResponse xmlns="http://tempuri.org/">
      <CreateCardResult>
        <RequestType>string</RequestType>
        <ProductType>string</ProductType>
        <ResponseCode>string</ResponseCode>
        <ReasonDescription>string</ReasonDescription>
      </CreateCardResult>
    </CreateCardResponse>
  </soap:Body>
</soap:Envelope>
斯里哈里

最后,我能够访问Third服务。

这是我访问服务的方法

   public void createSoapActionCallBack(ValidateCardRequest validateCardRequest) {

        //This is used to send header message
        SoapActionCallback actionCallBack=new SoapActionCallback(soapAction);
        try{

            actionCallBack = new SoapActionCallback(ResponseConstants.SOAPACTION_DEFAULT_URL) {
            public void doWithMessage(WebServiceMessage msg) {
                    SoapMessage smsg = (SoapMessage)msg;                
                    SoapHeader soapHeader = smsg.getSoapHeader();

                    try{
                        //To send header message
                        StringSource headerSource = new StringSource("<UserCredentials xmlns='URL'>\n" +
                                        "<userid>"+"ABCD"+"</userid>\n" +
                                        "<password>"+"ABCD"+"</password>\n" +
                                        "</UserCredentials>");
                        Transformer transformer = TransformerFactory.newInstance().newTransformer();
                        transformer.transform(headerSource, soapHeader.getResult());

                        smsg.setSoapAction(soapAction);
                    }catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                }
                }; 
               validateCardResponse = (FVValidateCardResponse) webServiceTemplate.marshalSendAndReceive(URL, validateCardRequest, actionCallBack);  

            } catch (Exception e) {
                e.printStackTrace();
            }       
}

这是我的配置xml文件:

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
        <property name="soapVersion">
            <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12"/>
        </property>
    </bean>

    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<!-- If we want to use contextPath then we mush create ObjectFactory class in the described Package-->
        <!-- <property name="contextPath" value="com.waleteros.firstviewmodel" /> -->

        <property name="classesToBeBound">
            <list>
                <value>com.waleteros.firstviewmodel.FVValidateCardRequest</value>
                <value>com.waleteros.firstviewmodel.FVValidateCardResponse</value>               
            </list>
        </property>
    </bean>

    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="messageFactory" />
        <property name="marshaller" ref="marshaller"></property>
        <property name="unmarshaller" ref="marshaller"></property>
        <property name="messageSender">
            <bean class="org.springframework.ws.transport.http.HttpComponentsMessageSender"/>            
        </property>
        <!-- <property name="defaultUri" value="https://www.firstviewcorp.com/dbbapplications/ServicesSS/Selfservice.asmx?wsdl"/> -->
    </bean>

根据您的xmls创建pojo的示例

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "CardUpdateResponse",namespace="http://www.corecard.com/Prepaid")
public class FVCardUpdateResponse {

    @XmlElement(name="CARDUPDATE_RET", namespace="http://www.corecard.com/Prepaid")
    private CARDUPDATE_RET response;
    //Getters and Setters   

    public static class CARDUPDATE_RET{

        @XmlElement(name = "ACCOUNTNUMBER", namespace="http://www.corecard.com/Prepaid")
        private String AccountNumber;

        @XmlElement(name = "ResCode", namespace="http://www.corecard.com/Prepaid")
        private String ResCode;

        @XmlElement(name = "ResErrorCode", namespace="http://www.corecard.com/Prepaid")
        private String ResErrorCode;

        @XmlElement(name = "ResErrorMsg", namespace="http://www.corecard.com/Prepaid")
        private String ResErrorMsg;
        //Getters and Setters
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在“第三方服务器”上对GKLocalPlayer进行身份验证?

来自分类Dev

如何添加第三方Java jar以便在pyspark中使用

来自分类Dev

如何使用cxf componnet使用Apache骆驼调用第三方Web服务

来自分类Dev

如何在Laravel中使用第三方软件包?

来自分类Dev

如何在C#中使用第三方https wsdl Web服务

来自分类Dev

如何使用.NET解析此第三方JSON服务?

来自分类Dev

如何在taskKey中使用第三方库?

来自分类Dev

如何在iOS8中使用iOS触摸ID映射第三方应用凭据?

来自分类Dev

如何在ember cli app中使用第三方npm软件包

来自分类Dev

如何添加第三方Java JAR文件以在PySpark中使用

来自分类Dev

如何在Gradle中的buildSrc下的自定义任务中使用第三方依赖项

来自分类Dev

如何在installa4j脚本中使用诸如apache之类的第三方库类

来自分类Dev

如何在ionic 2中使用第三方javascript库(pixijs)?

来自分类Dev

如何使用第三方@ConfigurationProperties @Bean?

来自分类Dev

如何在Stencil.js中使用外部第三方库

来自分类Dev

如何在抖动中使用来自第三方包装资产的图像?

来自分类Dev

如何在自己的应用中使用第三方TvProvider对象?

来自分类Dev

如何在IBM Cloud功能中使用第三方二进制文件

来自分类Dev

如何在第三方事件处理程序中使用最新的状态/值?

来自分类Dev

ImageJ:如何使用第三方插件API?

来自分类Dev

如何在Python中使用第三方库?

来自分类Dev

如何使用.NET解析此第三方JSON服务?

来自分类Dev

如何在AzureML Studio中使用R脚本导入第三方库“ causalImpact”?

来自分类Dev

如何查找第三方库中正在使用的第三方组件

来自分类Dev

如何在React App中使用第三方扩展?

来自分类Dev

如何允许在Safari中使用第三方Cookie或创建解决方法?

来自分类Dev

如何在聚合物 2.x 中使用第三方 javascript 插件

来自分类Dev

如何在不安装类型的情况下在 Angular 2+ 中使用第三方 js 库?

来自分类Dev

如何使用第三方组件

Related 相关文章

  1. 1

    如何在“第三方服务器”上对GKLocalPlayer进行身份验证?

  2. 2

    如何添加第三方Java jar以便在pyspark中使用

  3. 3

    如何使用cxf componnet使用Apache骆驼调用第三方Web服务

  4. 4

    如何在Laravel中使用第三方软件包?

  5. 5

    如何在C#中使用第三方https wsdl Web服务

  6. 6

    如何使用.NET解析此第三方JSON服务?

  7. 7

    如何在taskKey中使用第三方库?

  8. 8

    如何在iOS8中使用iOS触摸ID映射第三方应用凭据?

  9. 9

    如何在ember cli app中使用第三方npm软件包

  10. 10

    如何添加第三方Java JAR文件以在PySpark中使用

  11. 11

    如何在Gradle中的buildSrc下的自定义任务中使用第三方依赖项

  12. 12

    如何在installa4j脚本中使用诸如apache之类的第三方库类

  13. 13

    如何在ionic 2中使用第三方javascript库(pixijs)?

  14. 14

    如何使用第三方@ConfigurationProperties @Bean?

  15. 15

    如何在Stencil.js中使用外部第三方库

  16. 16

    如何在抖动中使用来自第三方包装资产的图像?

  17. 17

    如何在自己的应用中使用第三方TvProvider对象?

  18. 18

    如何在IBM Cloud功能中使用第三方二进制文件

  19. 19

    如何在第三方事件处理程序中使用最新的状态/值?

  20. 20

    ImageJ:如何使用第三方插件API?

  21. 21

    如何在Python中使用第三方库?

  22. 22

    如何使用.NET解析此第三方JSON服务?

  23. 23

    如何在AzureML Studio中使用R脚本导入第三方库“ causalImpact”?

  24. 24

    如何查找第三方库中正在使用的第三方组件

  25. 25

    如何在React App中使用第三方扩展?

  26. 26

    如何允许在Safari中使用第三方Cookie或创建解决方法?

  27. 27

    如何在聚合物 2.x 中使用第三方 javascript 插件

  28. 28

    如何在不安装类型的情况下在 Angular 2+ 中使用第三方 js 库?

  29. 29

    如何使用第三方组件

热门标签

归档