2013-01-23 99 views
1

使用cURL訪問Guvnor服務器的任何示例?使用cURL訪問Guvnor REST API

嘗試1:

curl -i --user username:pwd -H"Content-Type: application/json" -X GET localhost:8080/guvnor-server/rest/packages 

返回:

HTTP/1.1 401 Unauthorized 

嘗試2:

curl -X GET -u"username:pwd" localhost:8080/guvnor-server/rest/packages.json 

返回:

HTTP/1.1 404 Not Found 

參考:docs.jboss.org/drools/release/5.5.0.CR1/drools-guvnor-docs/html/ch09點HTML

THX!

回答

1

這Tomcat的7

下工作,我在的Guvnor 5.5.0.Final使用:

curl -v -u {user}:{password} -H "Accept: application/json" curl-X GET localhost:8080/drools-guvnor/rest/packages 

返回:

* About to connect() to localhost port 8080 (#0) 
* Trying ::1... connected 
* Server auth using Basic with user '{user}' 
> GET /drools-guvnor/rest/packages HTTP/1.1 
> Authorization: Basic ZGF2aWQ6ZGF2aWQ= 
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 
> Host: localhost:8080 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
< Server: Apache-Coyote/1.1 
< Set-Cookie: JSESSIONID=68225AF4B272E5CCA962FFE83BCB008A; Path=/drools-guvnor/; HttpOnly 
< Content-Type: application/json 
< Transfer-Encoding: chunked 
< Date: Sat, 18 May 2013 17:10:51 GMT 
< 
* Connection #0 to host localhost left intact 
* Closing connection #0 
[{"package":{"assets":"http:\/\/localhost:8080\/drools-guvnor\/rest\/packages\/defaultPackage\/assets\/drools","author":"{user}","binar         yLink":"http:\/\/localhost:8080\/drools-guvnor\/rest\/packages\/defaultPackage\/binary","description":"The default rule package","meta         data":{"archived":false,"checkinComment":"Initial","created":"2013-05-18T12:34:53.825-04:00","state":"","uuid":"ab4ae1a2-10d7-43e7-9d8         e-411c93a8e669","versionNumber":1},"published":"2013-05-18T12:34:53.833-04:00","sourceLink":"http:\/\/localhost:8080\/drools-guvnor\/r 

故障排除:

HTTP Status 500 - Unable to find JAXBContext for media type: application/json 

這發生錯誤因爲@sstarcher根據this post「resteasy不再在罐子裏包含json支持」。從這個答案中不清楚的是,如何解決drools-guvnor中的問題。

在這種情況下,使用drools-guvnor.5.5.0.Final,你需要下載兩個jar文件:在您的{} TOMCAT_HOME

- [jettison-1.3.3.jar][2] 
- [resteasy-jettison-provider-2.2.3.GA.jar][3] 

您應該將 jar文件/ webapps /目錄drools-guvnor/WEB-INF/lib文件夾。在一些系統上看起來像這樣:

/usr/local/tomcat/apache-tomcat-7.0.35/webapps/drools-guvnor/WEB-INF/lib 

接下來停止並重新啓動Web服務器。在{TOMCAT_HOME}/bin目錄 的Tomcat上,您可以使用./shutdown.sh和./startup.sh命令。

401 - 未經授權。如果您不使用-u user:pass可選參數,則會發生這種情況。開箱即用,guvnor使用假基本認證器,這需要頭文件才能工作。

404未找到。如果您沒有在請求中指定目錄或資源的正確名稱,則會發生此錯誤。

405 - 方法不允許。當你糾纏捲曲選項,忘記報價等時會發生。

406 - 不可接受。如果您使用-H選項指定了不受支持的「Accept:」標題,則會發生此錯誤。

HTH