掲示板

How to build theseDisplay JSON object

thumbnail
7年前 に Raihaan Cassim によって更新されました。

How to build theseDisplay JSON object

New Member 投稿: 14 参加年月日: 16/08/31 最新の投稿
Hi All,

We are currently using DXP 7 deployed on Tomcat 8.

We're trying to use the
/journal.journalarticle/get-article-content
JSON service but thus far have been unable to figure out just what exactly the themeDisplay object is and what/how to populate it.

We'd greatly appreciate any help in understanding what this object is and how to go about populating it.

Thanks
thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: How to build theseDisplay JSON object

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hi Raihaan,

Are you trying to make the JSON WS call from a Javascript block? If you are then you might be able to use the Liferay.ThemeDisplay object that is provided by default?
thumbnail
7年前 に Raihaan Cassim によって更新されました。

RE: How to build theseDisplay JSON object

New Member 投稿: 14 参加年月日: 16/08/31 最新の投稿
Hi Andrew,

We're using the UI to test out the API call. There is no default value specified so we're looking to understand what exactly needs to be put into that field.

Thanks
thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: How to build theseDisplay JSON object

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Ok -- so here is what I did. To be clear, I dont have DXP -- I am trying this on 7CE GA3, but I doubt for this particular feature it matters. You have to specify the item as a JSON object of course -- meaning something like

{ companyId: 20155, scopeGroupId:20144 ...


I tried to use the web browser console window to JSON.stringify the Liferay.ThemeDisplay JS oject, but that didn't work. So next, what I did was I filled in the form, with a value o f"null" for the ThemeDisplay. This of course didn't work, but it allowed me to grab the JS example and put it into the console where I was able to replace the "null" with the Liferay.ThemeDisplay js var --

var x = Liferay.Service(
  '/journal.journalarticle/get-article-content',
  {
    groupId: 20147,
    articleId: '30245',
    languageId: 'en_US',
    themeDisplay: Liferay.ThemeDisplay
  }
);


But this returned a 500 HTTP error -- with nothing in the log. I had this issue with the LAR stuff in 6.2 when I was trying to automate something and found that when you are working with this feature of the product the first thing you should do is bump the logging -- Control Panel > Server Administrator > Logging and then add a category


com.liferay.portal.jsonwebservice
ALL


I re-ran the code and then got a useful stacktrace --


16:06:45,457 WARN  [http-nio-7070-exec-2][JSONWebServiceActionImpl:401] Invoking deprecated method getArticleContent
16:06:45,460 DEBUG [http-nio-7070-exec-2][JSONWebServiceServiceAction:94] java.lang.NullPointerException
java.lang.NullPointerException
	at com.liferay.journal.util.impl.JournalUtil._populateTokens(JournalUtil.java:1436)
	at com.liferay.journal.util.impl.JournalUtil.getTokens(JournalUtil.java:761)


I went to look up those lines of code in the source and found --

	private static void _populateTokens(
			Map<string, string> tokens, long articleGroupId,
			ThemeDisplay themeDisplay)
		throws PortalException {

		Layout layout = themeDisplay.getLayout();
		Group group = layout.getGroup();</string,>


.. so the Layout was null, hence the NPE. The Javascript objects are not the full Java object versions so I guess this is why the NPE occurs. I think the only thing you could try on your end is to get a regular ThemeDisplay (in java) and then JSON it and output the string to your log. Then you can copy and paste that value into the forms to test. Once you get to your actual JS code though, I suspect you will need to write a utility class that constructs the parts of the ThemeDisplay that you need. I had to so that for the LAR services (not ThemeDisplay, but something else... can't recall off hand, it was a while ago now).
thumbnail
7年前 に Raihaan Cassim によって更新されました。

RE: How to build theseDisplay JSON object

New Member 投稿: 14 参加年月日: 16/08/31 最新の投稿
Hi Adrian,

Thank you for the detailed response. It's given me a good idea of what to try. I've enabled the logging and the stacktrace I get points me to a different section of the code. I'm reading through it now to see what I can make from it.

I'll update this as I go along.

Thanks
thumbnail
7年前 に Raihaan Cassim によって更新されました。

RE: How to build theseDisplay JSON object

New Member 投稿: 14 参加年月日: 16/08/31 最新の投稿
So it turns out that this was rather simple to fix.

"themeDisplay" is not a required parameter but the UI does not correctly deal with an empty string when calling the service. This is turn causes the service to attempt to construct a themeDisplay object and it correctly throws a null pointer exception.

What we needed to do was figure out how to send through a null value to the service. We did some wading through the documentation and found that to pass through a null value we had to prepend a "-" to the start of the parameter name in the request.

Our request looks like this. Pay attention to the dash in front of themeDisplay.

Curl:
curl https://mysecure.url.com/api/jsonws/journal.journalarticle/get-article-content \
  -u user@liferay.com:pass \
  -d groupId=1234 \
  -d articleId='5678' \
  -d languageId='en-US' \
  -d -themeDisplay=

URL:
https://mysecure.url.com/api/jsonws/journal.journalarticle/get-article-content/group-id/1234/article-id/5678/language-id/en-US/-theme-display/

And voila, everything works as intended.
thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: How to build theseDisplay JSON object

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hah! That's awesome -- definitely going to make a note of that for future reference. Question though, you said that you were testing using the api/jsonws page; were you able to figure out how to pass a null from the form field? I tried several combinations (empty field, "", {}, etc) and all of them generated the exception.
thumbnail
7年前 に Raihaan Cassim によって更新されました。

RE: How to build theseDisplay JSON object

New Member 投稿: 14 参加年月日: 16/08/31 最新の投稿
Nope. No luck at all with the API test page.

I'm glad we've discovered that though because it's answered a lot of questions for us on how to make better use of the API without needing to extend it.

Hope it helps others as well.