legacy-knowledge-base
公開されました Sep. 10, 2025

バックエンド OSGI モジュールから Liferay Objects REST API を呼び出すにはどうすればよいですか?

written-by

Jorge Diaz

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

Liferay オブジェクト API を呼び出す必要があるバックエンド OSGI モジュールを実装しています。

この機能の唯一の利用可能な API は REST API / GraphQL API ここで説明されていることに気付きました: https://learn.liferay.com/w/dxp/building-applications/objects/understanding-object-統合/ヘッドレス フレームワーク統合

私の質問:

  • バックエンド OSGI モジュールからこの API を呼び出すにはどうすればよいですか?
  • これらの REST API を呼び出すときに認証するにはどうすればよいですか?

Environment

  • ライフレイDXP 7.4

解決策

この API をバックエンドの OSGI モジュールからどのように使用できますか?

バックエンドの OSGI モジュールからこの REST API を呼び出すには、HTTP リクエストを作成できる Java クラスまたはライブラリを使用する必要があります。次に例を示します。

これらの REST API を呼び出すときに認証するにはどうすればよいですか?

バックエンドから の REST API を呼び出すときに認証するには、 から add から HTTP リクエスト ヘッダー with 18 ユーザー セッション 情報 および クロス-サイト リクエスト 偽造 CSRF) トークン.

の例 は、 CURL 使用して ます0/object-definitions は次のように行われます。

curl -X 'GET' 'http://localhost:8080/o/object-admin/v1.0/object-definitions' -H 'accept: application/json' -H 'Cookie: JSESSIONID=FCCBB92E9A927DBDF9A7FB7E41002889' -H 'x-csrf-token: bgs4QRYa'

ここで FCCBB92E9A927DBDF9A7FB7E41002889 ユーザー's 現在の セッションであり、bgs4QRYa は CSRF トークンです。

From the backend code, this data can be 簡単に 得られた from the HttpServletRequest object contains the 着信 HTTP 要求:

  1. JSESSIONID: httpServletRequest.getSession().getId();
  2. CSRF トークン: AuthTokenUtil.getToken(request)

As an example, groovy script example call_rest_api_get_method_from_backendを添付しました。groovy that you can execute from Control Panel => System => Server Administration => スクリプト

これ グルーヴィー スクリプト:

  1. Gets the JSESSIONID and CSRF Token from the request

  2. Liferay が portal-kernel で提供する HttpUtil HTTP クライアントを使用して、http://localhost:8080/o/object-admin/v1.0/object-definitions サービスへの GET 呼び出しを行います。

追加情報

did-this-article-resolve-your-issue

legacy-knowledge-base