JavaEE
2、Http协议
·4476 字·9 分钟·
loading
·
loading
Java
JavaEE
JavaWeb
HTTP协议 # 超文本传输协议(hypertext transport protocol),服务端和客户端发送数据,需要遵守的协议,传递的数据又称为报文
2、CXF
·922 字·2 分钟·
loading
·
loading
Java
JavaEE
WebService
整合SpringBoot+CXF # 1、添加依赖 # <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>top.ygang</groupId> <artifactId>cxfdemo</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-parent</artifactId> <version>2.2.0.RELEASE</version> </parent> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <cxf.version>3.2.1</cxf.version> </properties> <dependencies> <!-- webService--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> <!-- CXF webservice --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>${cxf.version}</version> </dependency> </dependencies> </project> 2、编写服务接口和服务实现类 # @WebService( name = "testService", targetNamespace = "http://top.ygang.test/service", serviceName = "testService" ) public interface TestService { @WebMethod(operationName = "testMethod") @WebResult(name = "message") String testMethod(@WebParam(name = "name") String name); } @Component @WebService( name = "testService", targetNamespace = "http://top.ygang.test/service", serviceName = "testService" ) public class TestServiceImpl implements TestService{ @Override @WebMethod(operationName = "testMethod") @WebResult(name = "message") public String testMethod(@WebParam(name = "name")String name) { return "accept success : " + name; } } 3、编写配置类 # @Configuration public class WSConfig { @Autowired private TestService testService; /** * Apache CXF 核心架构是以BUS为核心,整合其他组件。 * Bus是CXF的主干, 为共享资源提供一个可配置的场所,作用类似于Spring的ApplicationContext,这些共享资源包括 * WSDl管理器、绑定工厂等。通过对BUS进行扩展,可以方便地容纳自己的资源,或者替换现有的资源。默认Bus实现基于Spring架构, * 通过依赖注入,在运行时将组件串联起来。BusFactory负责Bus的创建。默认的BusFactory是SpringBusFactory,对应于默认 * 的Bus实现。在构造过程中,SpringBusFactory会搜索META-INF/cxf(包含在 CXF 的jar中)下的所有bean配置文件。 * 根据这些配置文件构建一个ApplicationContext。开发者也可以提供自己的配置文件来定制Bus。 */ @Bean(name = Bus.DEFAULT_BUS_ID) public SpringBus springBus() { return new SpringBus(); } /** * 此方法作用是改变项目中服务名的前缀名,此处127.0.0.1或者localhost不能访问时,请使用ipconfig查看本机ip来访问 * 此方法被注释后, 即不改变前缀名(默认是services) * * 如果启动时出现错误:not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServlet * 可能是springboot与cfx版本不兼容。 * 同时在spring boot2.0.6之后的版本与xcf集成,不需要在定义以下方法,直接在application.properties配置文件中添加: * cxf.path=/service(默认是services) */ // @Bean // public ServletRegistrationBean dispatcherServlet() { // return new ServletRegistrationBean(new CXFServlet(), "/services/*"); // } /** * 此方法的作用是发布服务 */ @Bean public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(springBus(), testService); endpoint.publish("/"); return endpoint; } } 4、启动类 # @SpringBootApplication public class Start { public static void main(String[] args) { SpringApplication.run(Start.class,args); } } 5、访问浏览器查看wsdl # 访问地址:http://127.0.0.1:8080/services/testService?wsdl
1、WebService
·3082 字·7 分钟·
loading
·
loading
Java
JavaEE
WebService
WebService简介 # Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的、专门的第三方软件或硬件, 就可相互交换数据或集成。依据Web Service规范实施的应用之间, 无论它们所使用的语言、平台或内部协议是什么,都可以相互交换数据。
1、Shiro
·2322 字·5 分钟·
loading
·
loading
Java
JavaEE
Shiro
Shiro简介 # 公司项目中,常见的权限框架:shiro,spring security Apache Shiro是一个功能强大且灵活的开源安全框架,可以清晰地处理身份验证,授权,企业会话管理和加密 Apache Shiro的首要目标是易于使用和理解。安全有时可能非常复杂,甚至是痛苦的,但并非必须如此。框架应尽可能掩盖复杂性,并提供简洁直观的API,以简化开发人员确保其应用程序安全的工作 Shiro能帮系统做什么 # 做用户的身份认证,判断用户是否系统用户(重点) 给系统用户授权,用来帮助系统实现不同的用户展示不同的功能(重点) 针对密码等敏感信息,进行加密处理(明文变成密文)(重点) 提供了Session管理,但是它的Session不是HttpSession,是它自己自带的 做授权信息的缓存管理,降低对数据库的授权访问 提供测试支持,因为它也是一个轻量级框架,它也可以直接针对代码进行使用Junit单元测试 提供Remeber me的功能,可以做用户无需再次登录即可访问某些页面 Shiro提供的10大功能 #