当前位置: 首页 > news >正文

石景山老山网站建设媒体网站怎么做

石景山老山网站建设,媒体网站怎么做,外链火,wordpress整合uc在RESTful Web服务时代#xff0c;我有机会使用SOAP Web Service。 为此#xff0c;我选择了Spring #xff0c;这是因为我们已经在项目中使用Spring作为后端框架#xff0c;其次它提供了一种直观的方式来与具有明确定义的边界的服务进行交互#xff0c;以通过WebServiceT… 在RESTful Web服务时代我有机会使用SOAP Web Service。 为此我选择了Spring 这是因为我们已经在项目中使用Spring作为后端框架其次它提供了一种直观的方式来与具有明确定义的边界的服务进行交互以通过WebServiceTemplate促进可重用性和可移植性。 假设您已经了解SOAP Web服务让我们开始创建在端口9999上运行的hello-world soap服务并使用下面的步骤来使用相同的客户端 步骤1 根据以下图像转到start.spring.io并创建一个添加Web启动器的新项目soap-server 步骤2编辑SoapServerApplication.java以在端点发布hello-world服务-http// localhost9999 / service / hello-world 如下所示 package com.arpit.soap.server.main;import javax.xml.ws.Endpoint;import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;import com.arpit.soap.server.service.impl.HelloWorldServiceImpl;SpringBootApplication public class SoapServerApplication implements CommandLineRunner {Value(${service.port})private String servicePort;Overridepublic void run(String... args) throws Exception {Endpoint.publish(http://localhost: servicePort /service/hello-world, new HelloWorldServiceImpl());}public static void main(String[] args) {SpringApplication.run(SoapServerApplication.class, args);} } 步骤3编辑application.properties以指定hello-world服务的应用程序名称端口和端口号如下所示 server.port9000 spring.application.namesoap-server## Soap Service Port service.port9999 步骤4创建其他包com.arpit.soap.server.service和com.arpit.soap.server.service.impl来定义Web Service及其实现如下所示 HelloWorldService.java package com.arpit.soap.server.service;import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService;import com.arpit.soap.server.model.ApplicationCredentials;WebService public interface HelloWorldService {WebMethod(operationName helloWorld, action https://aggarwalarpit.wordpress.com/hello-world/helloWorld)String helloWorld(final String name,WebParam(header true) final ApplicationCredentials credential);} 上面指定的WebService将Java类标记为实现Web服务或者将Java接口标记为定义Web Service接口。 上面指定的WebMethod将Java方法标记为Web Service操作。 上面指定的WebParam自定义单个参数到Web服务消息部分和XML元素的映射。 HelloWorldServiceImpl.java package com.arpit.soap.server.service.impl;import javax.jws.WebService;import com.arpit.soap.server.model.ApplicationCredentials; import com.arpit.soap.server.service.HelloWorldService;WebService(endpointInterface com.arpit.soap.server.service.HelloWorldService) public class HelloWorldServiceImpl implements HelloWorldService {Overridepublic String helloWorld(final String name,final ApplicationCredentials credential) {return Hello World from name;} } 步骤5移至soap-server目录并运行命令 mvn spring-bootrun 。 运行后打开http// localhost9999 / service / hello-worldwsdl以查看hello-world服务的WSDL。 接下来我们将创建soap-client 它将使用我们新创建的hello-world服务。 步骤6转到start.spring.io并基于下图创建一个新的项目soap-client添加WebWeb Services启动程序 步骤7编辑SoapClientApplication.java以创建一个向hello-world Web服务的请求将该请求连同标头一起发送到soap-server并从中获取响应如下所示 package com.arpit.soap.client.main;import java.io.IOException; import java.io.StringWriter;import javax.xml.bind.JAXBElement; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.ws.WebServiceMessage; import org.springframework.ws.client.core.WebServiceMessageCallback; import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.ws.soap.SoapMessage; import org.springframework.xml.transform.StringSource;import com.arpit.soap.server.service.ApplicationCredentials; import com.arpit.soap.server.service.HelloWorld; import com.arpit.soap.server.service.HelloWorldResponse; import com.arpit.soap.server.service.ObjectFactory;SpringBootApplication ComponentScan(com.arpit.soap.client.config) public class SoapClientApplication implements CommandLineRunner {AutowiredQualifier(webServiceTemplate)private WebServiceTemplate webServiceTemplate;Value(#{${service.soap.action}})private String serviceSoapAction;Value(#{${service.user.id}})private String serviceUserId;Value(#{${service.user.password}})private String serviceUserPassword;public static void main(String[] args) {SpringApplication.run(SoapClientApplication.class, args);System.exit(0);}public void run(String... args) throws Exception {final HelloWorld helloWorld createHelloWorldRequest();SuppressWarnings(unchecked)final JAXBElementHelloWorldResponse jaxbElement (JAXBElementHelloWorldResponse) sendAndRecieve(helloWorld);final HelloWorldResponse helloWorldResponse jaxbElement.getValue();System.out.println(helloWorldResponse.getReturn());}private Object sendAndRecieve(HelloWorld seatMapRequestType) {return webServiceTemplate.marshalSendAndReceive(seatMapRequestType,new WebServiceMessageCallback() {public void doWithMessage(WebServiceMessage message)throws IOException, TransformerException {SoapMessage soapMessage (SoapMessage) message;soapMessage.setSoapAction(serviceSoapAction);org.springframework.ws.soap.SoapHeader soapheader soapMessage.getSoapHeader();final StringWriter out new StringWriter();webServiceTemplate.getMarshaller().marshal(getHeader(serviceUserId, serviceUserPassword),new StreamResult(out));Transformer transformer TransformerFactory.newInstance().newTransformer();transformer.transform(new StringSource(out.toString()),soapheader.getResult());}});}private Object getHeader(final String userId, final String password) {final https.aggarwalarpit_wordpress.ObjectFactory headerObjectFactory new https.aggarwalarpit_wordpress.ObjectFactory();final ApplicationCredentials applicationCredentials new ApplicationCredentials();applicationCredentials.setUserId(userId);applicationCredentials.setPassword(password);final JAXBElementApplicationCredentials header headerObjectFactory.createApplicationCredentials(applicationCredentials);return header;}private HelloWorld createHelloWorldRequest() {final ObjectFactory objectFactory new ObjectFactory();final HelloWorld helloWorld objectFactory.createHelloWorld();helloWorld.setArg0(Arpit);return helloWorld;}} 步骤8接下来创建其他包com.arpit.soap.client.config来配置WebServiceTemplate 如下所示 ApplicationConfig.java package com.arpit.soap.client.config;import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.oxm.jaxb.Jaxb2Marshaller; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.ws.soap.saaj.SaajSoapMessageFactory; import org.springframework.ws.transport.http.HttpComponentsMessageSender;Configuration EnableWebMvc public class ApplicationConfig extends WebMvcConfigurerAdapter {Value(#{${service.endpoint}})private String serviceEndpoint;Value(#{${marshaller.packages.to.scan}})private String marshallerPackagesToScan;Value(#{${unmarshaller.packages.to.scan}})private String unmarshallerPackagesToScan;Beanpublic static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {return new PropertySourcesPlaceholderConfigurer();}Beanpublic SaajSoapMessageFactory messageFactory() {SaajSoapMessageFactory messageFactory new SaajSoapMessageFactory();messageFactory.afterPropertiesSet();return messageFactory;}Beanpublic Jaxb2Marshaller marshaller() {Jaxb2Marshaller marshaller new Jaxb2Marshaller();marshaller.setPackagesToScan(marshallerPackagesToScan.split(,));return marshaller;}Beanpublic Jaxb2Marshaller unmarshaller() {Jaxb2Marshaller unmarshaller new Jaxb2Marshaller();unmarshaller.setPackagesToScan(unmarshallerPackagesToScan.split(,));return unmarshaller;}Beanpublic WebServiceTemplate webServiceTemplate() {WebServiceTemplate webServiceTemplate new WebServiceTemplate(messageFactory());webServiceTemplate.setMarshaller(marshaller());webServiceTemplate.setUnmarshaller(unmarshaller());webServiceTemplate.setMessageSender(messageSender());webServiceTemplate.setDefaultUri(serviceEndpoint);return webServiceTemplate;}Beanpublic HttpComponentsMessageSender messageSender() {HttpComponentsMessageSender httpComponentsMessageSender new HttpComponentsMessageSender();return httpComponentsMessageSender;} } 步骤9编辑application.properties以指定应用程序名称端口和hello-world soap Web服务配置如下所示 server.port9000 spring.application.namesoap-client## Soap Service Configurationservice.endpointhttp://localhost:9999/service/hello-world service.soap.actionhttps://aggarwalarpit.wordpress.com/hello-world/helloWorld service.user.idarpit service.user.passwordarpit marshaller.packages.to.scancom.arpit.soap.server.service unmarshaller.packages.to.scancom.arpit.soap.server.service 上面指定的service.endpoint是提供给服务用户以调用服务提供者公开的服务的URL。 service.soap.action指定服务请求者发送请求时需要调用哪个进程或程序还定义了进程/程序的相对路径。 marshaller.packages.to.scan指定在将请求发送到服务器之前在编组时要扫描的软件包。 unmarshaller.packages.to.scan指定从服务器收到请求后在解组时要扫描的软件包。 现在我们将使用wsimport从WSDL生成Java对象并将其复制到在终端上执行以下命令的soap-client项目 wsimport -keep -verbose http://localhost:9999/service/hello-world?wsdl 步骤10移至soap-client目录并运行命令 mvn spring-bootrun 。 命令完成后我们将在控制台上看到“来自Arpit的Hello World”作为hello-world soap服务的响应。 在运行时如果遇到以下错误则– 由于缺少XmlRootElement批注因此无法封送键入“ com.arpit.soap.server.service.HelloWorld”作为元素然后添加XmlRootElementname “ helloWorld”命名空间 “ http://service.server.soap.arpit.com/ ”到com.arpit.soap.server.service.HelloWorld 其中名称空间应与在肥皂信封中定义的xmlnsser相匹配如下所示 soapenv:Envelope xmlns:soapenvhttp://schemas.xmlsoap.org/soap/envelope/ xmlns:serhttp://service.server.soap.arpit.com/soapenv:Headerser:arg1userIdarpit/userIdpasswordarpit/password/ser:arg1/soapenv:Headersoapenv:Bodyser:helloWorld!--Optional:--arg0Arpit/arg0/ser:helloWorld/soapenv:Body /soapenv:Envelope 完整的源代码托管在github上 。 翻译自: https://www.javacodegeeks.com/2016/07/writing-consuming-soap-webservice-spring.html
http://www.sadfv.cn/news/64881/

相关文章:

  • 千博企业网站管理系统营销旗舰版消费金融网站建设
  • wordpress公众号抓取网站优化软件排名技术
  • 如何把图片做网站背景专业购物网站建设哪家好
  • 关于做无机化学实验的网站爱链接外链购买
  • 中铝长城建设有限公司网站小程序登录代码
  • 仪器网站模板广东省外贸网站建设
  • 郑州上街区网站建设公司中小型网站建设案例
  • 福州微信营销网站建设网站开发汇报ppt模板
  • 美容行业培训网站建设营销推广的作用
  • 网做 网站有哪些功能南京网站网站建设学校
  • 洛阳恒凯做的网站有哪些信阳网站建设招聘
  • 网站建设商标属于哪个类别wordpress 只显示文章标题
  • 网站建设价格很 好乐云seo哈尔滨专业官网建站企业
  • 嘉兴专业做网站wordpress 七牛缩略图
  • 谁会在掏宝网上做网站做一个电子商务网站在哪里做
  • 婚庆网站源码哪个dns访问国外网站
  • 在线crm视频在线crm免wordpress改造seo
  • 购物网站做兼职建筑设计网站国外
  • 济南 手机网站制作外国的贸易网站
  • 帝国cms做搜索网站产品网页设计公司
  • 网站建设站点无法发布使用wordpress的用户有哪些
  • 行业网站大全青岛哪家做网站的公司好
  • 北京市建网站王者荣耀网页设计报告
  • 成都网站制作需要多少钱软件开发入门教程
  • 做外贸网站报价单网站开发与spark
  • 百度商桥怎样绑定网站群英云服务器
  • 上海哪家做公司网站网站建设背景是什么
  • 广州越秀建网站的公司怎么使用dw做一个网站
  • 如何做网站优化并快速提高权重做网站的图片要求大小
  • 装修网站模板下载网站目录结构图