New post

Encontrar

Article
· Dec 18, 2024 2m read

HTTPアウトバウンドアダプタを使用して、クエリパラメータとボディを両方送付する方法

開発者の皆さん、こんにちは。

試していたWebAPIでは、POST要求時クエリパラメータとボディの両方を送る必要がありましたので、HTTPアウトバウンドアダプタが提供するメソッド:Post()/PostFormDataArray()/PostURL() 辺りをドキュメントで確認していたのですが、残念ながら両方を渡せるように作成された丁度良いメソッドがありませんでした。

ドキュメント:HTTPアウトバウンドアダプタが提供するメソッド

では、どのように送ったかというと、SendFormDataArray()の第3引数を利用して両方の情報を送付してみました。

具体的には、SendFormDataArray()の第2引数にはHTTPメソッド(GET、POST、PUT、DELETEなど)第3引数に%Net.HttpRequestのインスタンスが渡せる仕様になっていましたので、クエリパラメータとボディを%Net.HttpRequestのインスタンスに設定し、第3引数に指定して実行する方法をとりました。

  set status=..Adapter.SendFormDataArray(.pHttpResponse,"POST",httprequest)
  if $$$ISERR(status) {
    return status
  }

変数httprequestの中身は以下のように作成しています

  set httprequest=##class(%Net.HttpRequest).%New()
  set httprequest.ContentType="application/json"
  set httprequest.ContentCharset="utf-8"
  //ボディの設定
  //..JTemplateプロパティにJSONダイナミックオブジェクトが設定されていると仮定
  do ..JTemplate.%ToJSON(httprequest.EntityBody)
  
  // QueryParameterの設定(..QueryParamプロパティにクエリパラメータが設定されていると仮定)
  for cn=1:1:$length(..QueryParam,"&") {
    set name=$piece($piece(..QueryParam,"&",cn),"=",1)
    set val=$piece($piece(..QueryParam,"&",cn),"=",2)
    do httprequest.SetParam(name,val)
  }

例では、クエリパラメータとボディを設定してますが、HTTP要求のヘッダに情報を追加したいときにも同様の方法が利用できます。
(HTTPヘッダを追加するには、SetHeader(キー,値)が利用できます。)

ヘッダ追加の参考情報:HTTP要求時の認証の指定

 

HTTPアウトバウンドアダプタを使用せず、シンプルにObjectScriptでHTTP要求を行う方法については以下ObjectScriptクックブックの例をご参照ください。

Discussion (0)1
Log in or sign up to continue
Announcement
· Dec 18, 2024

[Video] AI Governance in IT solutions

Hey Community!

Check out the new video dedicated to Gen AI on our InterSystems Developers YouTube:

⏯ AI Governance in IT solutions

Learn the approaches to the AI governance in healthcare IT projects:

  • Integrate AI into Existing Processes
  • Establish an AI Committee
  • Emphasize Pilots for Trust Building
  • Monitor Ongoing Use

These points provide a practical framework for responsibly adopting AI in healthcare.

🗣  Presenter@Don Woodlock, Vice President, Healthcare Solutions Development, InterSystems

Enjoy watching, and look forward to more videos! 👍

Discussion (0)1
Log in or sign up to continue
Announcement
· Dec 18, 2024

HealthShare Unified Care Record Overview-Virtual January 22-23, 2025 - Registration space available

  • HealthShare Unified Care Record Overview – Virtual January 22-23, 2025
    • The HealthShare Unified Care Record Overview course is a great way for anyone to become familiar with Unified Care Record, but especially those who need to understand its capabilities but not how to configure HealthShare Unified Care Record.
    • This is a non-technical, instructor-led in person training course providing a comprehensive introduction to HealthShare Unified Care Record.
    • This course is for anyone who needs to know about the functionality and architecture of HealthShare Unified Care Record.  (If you need information on configuring and troubleshooting Unified Care Record, consider the HealthShare Unified Care Record Fundamentals class.)
    • No prior knowledge or experience is required for the Overview class and any InterSystems employee may enroll.

 

Discussion (0)1
Log in or sign up to continue
Question
· Dec 18, 2024

The right side of a logical double AND (&&) riddle

References:

ObjectScript always follows strict left-to-right execution of arithmetic operators. 

The && operator evaluates the left operand and returns a value of FALSE (0) if it evaluates to a value of zero. Only if the left operand is nonzero does the && operator then evaluates the right operand. It returns a value of FALSE (0) if the right operand evaluates to a value of zero. Otherwise it returns a value of TRUE (1).

So here is a riddle then. Given the expression

write (1=0) && (1=0)

 we get the result "0", which is expected. But if we remove the parenthesis we should in theory (to my understanding) should get the same result, but we do not! We instead get "1" for the following

write 1=0 && 1=0

if this is truly left to right only operational procedence, then shouldn't it still be "0"?

1=0 && 1=0
0 && 1=0
0 (since the left side is 0, the right side shouldn't be evaluated according to docs)

But what appears to be happening is:
1=0 && 1=0
0 && 1=0
0=0

It was not clear that the right side of the `&&` operator does not extend past the "1" but literally checks only "0 && 1" and then continues to check "0=0"

I assumed that anything past a "&&" would be considered the "right side" and would exit early.
 

5 Comments
Discussion (5)2
Log in or sign up to continue
Question
· Dec 18, 2024

EnsLib.HL7.Service.* through BPL to EnsLib.HL7.MsgRouter.RoutingEngine

Very similar question posed here: https://community.intersystems.com/node/467496, but I am missing a piece of this:

How do I correctly call a EnsLib.HL7.MsgRouter.RoutingEngine class from the BPL?I can successfully call the BPL from the EnsLib.HL7.Service.TCPService, and I have the BPL created to delay then call the rule. And I set the context and the result location.

This rule is really basic just sending the HL7 content to a EnsLib.HL7.Operation.TCPOperation

The Visual Trace shows that the BPL is getting called, and the rule gets called after the delay, but the rule actions don't get called, at least not correctly?

How would I send the HL7 original message through the BPL to this rule as if the BPL was not there?

If there is another way to add a delay without the BPL, that would work as well. I have not found a way to add the delay within the rule itself.

Discussion (0)1
Log in or sign up to continue