JBoss Fuse-나머지 웹 서비스

우선 REST는 Representational State Transfer를 의미합니다. 이는 대부분의 경우 HTTP 인 상태 비 저장, 캐시 가능, 클라이언트-서버 프로토콜을 기반으로 웹 서비스를 개발하는 방법입니다.

REST 웹 서비스는 HTTP 요청을 사용하여 네트워크에서 데이터를 게시, 가져 오기, 삭제합니다.

CXF를 사용한 REST 개발

간단한 Maven 빠른 시작 프로젝트 만들기

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

종속성 추가

<dependency>
   <groupId>org.apache.servicemix.specs</groupId>
   <artifactId>org.apache.servicemix.specs.jsr311-api-1.1.1</artifactId>
   <version>1.9.0</version>
   <scope>provided</scope>
</dependency>

<dependency>
   <groupId>org.apache.servicemix</groupId>
   <artifactId>servicemix-http</artifactId>
   <version>2013.01</version>
</dependency>

<dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.16</version>
</dependency>

빌드 지침 추가

<build>
   <defaultGoal>install</defaultGoal>
   <plugins>
      <plugin>
         <groupId>org.apache.felix</groupId>
         <artifalctId>maven-bundle-plugin</artifactId>
         <version>2.3.4</version>
         <extensions>true</extensions>
			
         <configuration>
            <instructions>
               <Bundle-SymbolicName>rest-example-database-post-method
                  </Bundle-SymbolicName>
               <Import-Package>* </Import-Package>
            </instructions>
         </configuration>
			
      </plugin>
   </plugins>
</build>

퓨즈 플러그인 저장소 추가

<pluginRepositories>
   <pluginRepository>
      <id>fusesource.m2</id>
      <name>FuseSource Community Release Repository</name>
      <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
      <snapshots>
         <enabled>false</enabled>
      </snapshots>
		
      <releases>
         <enabled>true</enabled>
      </releases>
   </pluginRepository>
<pluginRepositories>

저장소 추가

<repositories>
   <repository>
      <id>fusesource.m2</id>
      <name>FuseSource Community Release Repository</name>
      <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
      <snapshots>
         <enabled>false</enabled>
      </snapshots>
		
      <releases>
         <enabled>true</enabled>
      </releases>
		
   </repository>
	
   <repository>
      <id>fusesource.ea</id>
      <name>FuseSource Community Early Access Release Repository</name>
      <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
      <snapshots>
         <enabled>false</enabled>
      </snapshots>
      <releases>
         <enabled>true</enabled>
      </releases>
   </repository>
	
</repositories>

서비스 클래스 생성

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을 만듭니다.

<?xml version = "1.0" encoding = "UTF-8"?>
<blueprint xmlns = "http://www.osgi.org/xmlns/blueprint/v1.0.0"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:jaxrs = "http://cxf.apache.org/blueprint/jaxrs"
   xsi:schemaLocation = "http://www.osgi.org/xmlns/blueprint/v1.0.0 
   http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
   http://cxf.apache.org/blueprint/jaxrs 
   http://cxf.apache.org/schemas/blueprint/jaxrs.xsd">
	
   <jaxrs:server id = "service" address = "/users">
      <jaxrs:serviceBeans>
         <ref component-id = "userService" />
      </jaxrs:serviceBeans>
   </jaxrs:server>
	
   <bean id = "userService" class = "com.tuts.UserService" />
</blueprint>

퓨즈에 휴식 서비스 설치

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

번들에 등록 된 웹 서비스가 있는지 확인

URL 열기 http://localhost:8181/cxf

웹 서비스 테스트

URL 열기 http://localhost:8181/cxf/users12/UserService_1/get_data