2017-05-12 57 views
0

我正在嘗試學習如何使用cxf和JBoss Fuse製作REST服務。在服務器上成功安裝服務之後,我嘗試在http://localhost:8181/cxf上看到已安裝的cxf服務列表,得到「沒有找到服務」的表達式。有人知道爲什麼沒有服務沒有出現,我該如何顯示它? ,我現在把它用作測試的代碼是一個在本教程中https://www.tutorialspoint.com/jboss_fuse/jboss_fuse_rest_web_services.htm,從Maven項目org.apache.cxf CXF-HTTP-基本出發在JBoss Fuse上安裝了項目cxf,但仍然沒有找到服務

編輯1:以下我安裝Abolfazl的有益重寫指南後並重新開始服務。 這一次做的OSGi:名單我得到

[ 320] [Active  ] [Failure  ] [  ] [ 80] mvn:com.tuts.abhinav/rest-service/1.0-SNAPSHOT 

一邊做記錄:顯示我得到

2017-05-23 09:44:36,969 | ERROR | l Console Thread | BlueprintContainerImpl   | 23 - org.apache.aries.blueprint.core - 1.4.5 | Unable to start blueprint container for bundle null/0.0.0 
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
    at java.util.ArrayList.rangeCheck(ArrayList.java:653)[:1.8.0_121] 
    at java.util.ArrayList.get(ArrayList.java:429)[:1.8.0_121] 
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.readDirectives(BlueprintContainerImpl.java:214) 
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:296) 
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:270) 
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294) 
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263) 
    at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:253) 
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500) 
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433) 
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725) 
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463) 
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422) 
    at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127) 
    at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696) 
    at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484) 
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429) 
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2100) 
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976) 
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:963) 
    at org.apache.karaf.shell.osgi.StartBundle.doExecute(StartBundle.java:37) 
    at org.apache.karaf.shell.osgi.BundlesCommand.doExecute(BundlesCommand.java:37) 
    at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:38) 
    at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_121] 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_121] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_121] 
    at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_121] 
    at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54)[19:org.apache.aries.proxy.impl:1.0.5] 
    at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)[19:org.apache.aries.proxy.impl:1.0.5] 
    at org.apache.karaf.shell.console.commands.$BlueprintCommand417451938.execute(Unknown Source)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:92)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.karaf.shell.console.jline.Console.run(Console.java:197)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
    at org.apache.karaf.shell.console.jline.DelayedStarted.run(DelayedStarted.java:79)[38:org.apache.karaf.shell.console:2.4.0.redhat-630187] 
+0

你有沒有安裝和啓動捆綁之後檢查控制檯日誌?請在jboss保險絲控制檯中輸入「list」命令並檢查捆綁狀態是否「有效」。 –

+0

安裝並運行軟件包後,日誌中沒有錯誤,例如服務正常工作。當我檢查osgi:list時,捆綁軟件的狀態是活動的 –

回答

0

上面的示例需要一些更正如下:

1,在「添加保險絲插件庫」中的代碼的最後一行節,「< pluginRepositories>」絕替換爲</pluginRepositories>。

2-In代碼第6行的「添加構建指令」部分,「artifalctId」必須替換爲「artifactId」。爲創建和部署上面的示例

正確的步驟如下:

用下面的命令1 - 創建一個簡單的Maven快速啓動項目:

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

,直到你有以下2 - 更改項目結構結構: Project Structure

3- 「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; 
    } 
} 

4- 「blueprint.xml」 文件應具有下列內容:

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

5- 「的pom.xml」 文件應具有下列內容:

<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/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.tuts.abhinav</groupId> 
<artifactId>rest-service</artifactId> 
<packaging>bundle</packaging> 
<version>1.0-SNAPSHOT</version> 
<name>rest-service</name> 
<url>http://maven.apache.org</url> 
<dependencies> 
    <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>org.apache.cxf</groupId> 
     <artifactId>cxf-rt-frontend-jaxrs</artifactId> 
     <version>3.0.2</version> 
    </dependency> 

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

<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> 

<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> 
<build> 
    <defaultGoal>install</defaultGoal> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>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> 

6-您可以使用以下命令安裝項目:

mvn install 

7 - 最後,你可以在karaf用下面的命令部署項目包:

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

之後,你的服務必須可在http://localhost:8181/cxf網址:

+0

感謝您的幫助,但我仍然有一些問題在保險絲上安裝服務。安裝並做osgi之後:list我得到: [320] [Active] [Failure] [] [80] mvn:com.tuts.abhinav/rest-service/1.0-SNAPSHOT。 控制日誌說: 2017-05-22 17:19:09,545 |錯誤| l控制檯線程| BlueprintContainerImpl | 23 - org.apache.aries.blueprint.core - 1.4.5 |無法啓動套件的藍圖容器null/0.0.0 –

+0

請執行「log:display」命令並在此輸出您的異常。 –

+0

在評論中沒有足夠的空間,我要編輯帖子並在那裏寫下 –

0

也許嘗試從保險絲來代替這個REST的例子嗎?它使用JBoss的保險絲6.3:

https://github.com/jboss-fuse/quickstarts/tree/master/cxf/rest

+0

安裝並啓動你的例子後,我可以在http:// localhost:8181/cxf上看到你的服務,但我仍然不明白爲什麼我不能看到我正在使用的另一個例子。 –

相關問題