📜  JBoss Fuse-Rest Web Services

📅  最后修改于: 2020-10-13 08:11:59             🧑  作者: Mango


 

首先,REST代表代表性状态转移。它是一种基于无状态,可缓存的客户端-服务器协议(大多数情况下为HTTP)开发Web服务的方法。

REST Web服务使用HTTP请求从网络发布,获取和删除数据。

使用CXF进行REST开发

创建一个简单的Maven快速入门项目

mvn archetype:generate 
-DgroupId = com.tuts.abhinav 
-DartifactId = rest-service
-DarchetypeArtifactId = maven-archetype-quickstart 
-DinteractiveMode = false

添加依赖项


   org.apache.servicemix.specs
   org.apache.servicemix.specs.jsr311-api-1.1.1
   1.9.0
   provided



   org.apache.servicemix
   servicemix-http
   2013.01



   log4j
   log4j
   1.2.16

添加构建指令


   install
   
      
         org.apache.felix
         maven-bundle-plugin
         2.3.4
         true
            
         
            
               rest-example-database-post-method
                  
               * 
            
         
            
      
   

添加保险丝插件存储库


   
      fusesource.m2
      FuseSource Community Release Repository
      http://repo.fusesource.com/nexus/content/repositories/releases
      
         false
      
        
      
         true
      
   

添加存储库


   
      fusesource.m2
      FuseSource Community Release Repository
      http://repo.fusesource.com/nexus/content/repositories/releases
      
         false
      
        
      
         true
      
        
   
    
   
      fusesource.ea
      FuseSource Community Early Access Release Repository
      http://repo.fusesource.com/nexus/content/groups/ea
      
         false
      
      
         true
      
   
    

创建服务类别

在com / tuts /下创建类UserService.java

package com.tuts;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/UserService_1")
public class UserService {
   @GET
   @Path("/get_data")
   @Produces(MediaType.APPLICATION_JSON)
    
   public String getUser() {
      String reponse = "This is standard response from REST";
      return reponse;
   }
}

创建Blueprint.xml

在/ src / main / resources / OSGI-INF / blueprint blueprint.xml下创建blueprint.xml



    
   
      
         
      
   
    
   

在保险丝中安装Rest服务

install -s mvn:com.tuts.abhinav/rest-service/1.0-SNAPSHOT

检查捆绑软件是否具有注册的Web服务

开启网址http:// localhost:8181 / cxf

注册的网络服务

测试Web服务

打开URL http:// localhost:8181 / cxf / users12 / UserService_1 / get_data

本地主机CXF