2016-03-09 13 views
0

我有一個用Jolie編寫的服務,我希望根據請求提取http頭文件。以同樣的方式可以打印出request.id,我想打印標題。試着在代碼中使用粗體字。這裏代碼:如何在Jolie編程語言服務上獲取http頭文件

execution { concurrent } 



    inputPort UserDB_Service { 
    Location: "socket://localhost:8002/" 
    Protocol: http { .format = "json"} 
    Interfaces: Users, ShutdownInterface, ConnectionPool 
    } 


    outputPort DB_Connector { 
    Location: "socket://localhost:1000/" 
    Protocol: sodep 
    Interfaces: ConnectionPool 
    } 



init 
{ 
[email protected]_Connector()(connectionInfo); 
[email protected](connectionInfo)() 

} 

main 
{ 
//Example: http://localhost:8002/retrieve?id=1 
[ retrieve(request)(response) { 
    [email protected](
     "select * from users where user_id=:id" { 
      .id = request.id 
     } 
    )(sqlResponse); 

    [email protected]("You have requested the user_id: " + request.id)(); 
    **[email protected]("Request Headers: " + response.format)();** 

    if (#sqlResponse.row == 1) { 
     response -> sqlResponse.row[0]   
    } 

} ] 



} 

感謝您的幫助。

+0

它沒有把大膽,但在接下來的格式:**調用println @控制檯( 「請求頭:」 + request.format)(); ** 而且它的請求,沒有迴應。對於混淆的爭論抱歉。這是我想要的請求標題。 –

+0

這個問題措辭不好,沒有太大意義,但我投了贊成票,因爲它似乎是關於jolie的第一個問題,這似乎是一種有趣的語言。 – exebook

回答

0

我不明白你是否知道你想在入站請求中包含哪些頭文件,或者你只是想打印整個http消息來進行調試。這兩種情況都很快,我報告了兩種解決方案:)

在第一種情況下,您可以設置http協議的headers參數,以使inputPort在請求消息中包含特定報頭的內容,例如,

http { 
    .headers.format = "format"; 
} 

,然後你可以檢查通常的方式

[email protected](request.format)() 

在第二種情況下的值,可以使用

http { 
    .debug = true; 
    .debug.showContent = true 
} 

查看所有http請求和響應及其主體的日誌。

這些和關於協議的進一步信息,特別是http協議在Jolie站點的文檔中。

+0

它實際上工作! 標題是: mar。 10,2016 1:16:55 PM jolie.Interpreter logInfo 信息:[UserDB_crud.ol] [HTTP調試]接收: HTTP代碼:0 資源:/ retrieve?id = 1 - >標頭屬性 ** iv-user:g47257 ** accept-language:en-US,en; q = 0.8,da; q = 0.6,es; q = 0.4 host:localhost:8002 upgrade-insecure-requests:1 connection:保持活着 緩存控制:max-age = 0 accept-encoding:gzip,deflate,sdch –

+0

我不知道我是否可以提取請求頭「iv-user」(我使用fiddler注入),因爲它會被使用爲了認證。 我現在有這樣的配置: inputPort UserDB_Service { \t地點: 「套接字://本地主機:8002 /」 \t協議:HTTP {.format = 「JSON」; \t .headers.format =「format」; \t .debug = true; .debug。showContent =真 } \t接口:用戶,ShutdownInterface,連接池 } –

+0

是的,試試這個MWE '包括 「console.iol」 inputPort我{ 位置: 「套接字://本地主機:8000」 協議:HTTP {.headers.iv_user = 「ivUser」} requestResponse則:myRequest } 主 { myRequest(請求)(){ \t的println @控制檯(request.ivUser)() } 請記住,正如[documentation](http://docs.jolie-lang.org/#!documentation/protocols/http.html)中所報告的,Jolie http.headers參數在標題名稱中映射'-'與'_',例如,在你的情況下,我們使用'iv_user'來定位頭文件'iv-user'。 – thesave

0

我把這裏的輸出再次。我想知道是否可以提取使用Fiddler注入的「iv-user:g47257」頭文件。再次感謝您的幫助。 標題是這樣的(更好的格式)。

INFO: [UserDB_crud.ol] [HTTP debug] Receiving: 
HTTP Code: 0 
Resource: /retrieve?id=1 
--> Header properties 
    iv-user: g47257 
    accept-language: en-US,en;q=0.8,da;q=0.6,es;q=0.4 
    host: localhost:8002 
    upgrade-insecure-requests: 1 
    connection: keep-alive 
    cache-control: max-age=0 
    accept-encoding: gzip, deflate, sdch 
    accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp 
,*/*;q=0.8 
     user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTM 
L, like Gecko) Chrome/48.0.2564.116 Safari/537.36 

You have requested the user_id: 1 
mar. 10, 2016 2:30:44 PM jolie.Interpreter logInfo 
INFO: [UserDB_crud.ol] [HTTP debug] Sending: 
HTTP/1.1 200 OK 
Server: Jolie 
X-Jolie-MessageID: 0 
Content-Type: application/json; charset=utf-8 
Content-Encoding: gzip 
Content-Length: 72 

?V*H,..?/JQ?R*I-.Q?Q*-N-??♦ 
↑?(?%?"dRs‼3s?\►?????T♂ %??WE 
mar. 10, 2016 2:30:44 PM jolie.Interpreter logInfo 
INFO: [UserDB_crud.ol] [HTTP debug] Receiving: 
HTTP Code: 0 
Resource: /favicon.ico 
--> Header properties 
    iv-user: g47257 
    referer: http://localhost:8002/retrieve?id=1 
    accept-language: en-US,en;q=0.8,da;q=0.6,es;q=0.4 
    host: localhost:8002 
    connection: keep-alive 
    cache-control: no-cache 
    pragma: no-cache 
    accept-encoding: gzip, deflate, sdch 
    user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTM 
L, like Gecko) Chrome/48.0.2564.116 Safari/537.36 
    accept: */* 

mar. 10, 2016 2:30:44 PM jolie.Interpreter logWarning 
WARNING: [UserDB_crud.ol] Received a message for operation favicon.ico, not specified in the input port at the receiving service. Sending IOException to the caller. 
mar. 10, 2016 2:30:44 PM jolie.Interpreter logInfo 
INFO: [UserDB_crud.ol] [HTTP debug] Sending: 
HTTP/1.1 200 OK 
Server: Jolie 
X-Jolie-MessageID: 0 
Content-Type: application/json; charset=utf-8 
Content-Encoding: gzip 
Content-Length: 102 

?VJ-*?/R??V?M-.NLOU?R??w?HN-(???S?QJ?O☺?→←↓↑↑?(?$?$???%?d?(?↨?▬%?¶Z)?%?e&???☺ ??Z ?yd?Y 
相關問題