掲示板

URL can only be invoked using POST

9年前 に Venkatesh Manam によって更新されました。

URL can only be invoked using POST

New Member 投稿: 14 参加年月日: 13/11/12 最新の投稿
Hi,

"This URL can only be invoked using POST"
I am getting this error when I save configuration for my custom portlet. Everything works fine but I see this error in the logs.
In my custom portlet configuration I am using select_document_library_folder portlet to enable users to select a folder from DL while configuring the custom portlet.

My portlet class extends an MVCPortlet class and my CustomConfigurationActionClass extends DefaultConfigurationAction class.

https://www.liferay.com/community/forums/-/message_boards/message/3691379
https://www.liferay.com/community/wiki/-/wiki/Main/Check+Method+on+Process+Action.

From the forums & Wiki found that I need to override 'isCheckMethodOnProcessAction ' to be able to use GET method.

Now I don't understand where I need to override isCheckMethodOnProcessAction method?
Both the above classes don't allow me to override the isCheckMethodOnProcessAction.

Using Liferay 6.1.30 GA3. Earlier versions seems to have a PortletAction class where we can override this method.

Any help would be greatly appreciated.

-Venkat
thumbnail
9年前 に Olaf Kock によって更新されました。

RE: URL can only be invoked using POST

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
Venkatesh Manam:
Hi,

"This URL can only be invoked using POST"
I am getting this error when I save configuration for my custom portlet. Everything works fine but I see this error in the logs.


You probably are saving the configuration through a form. In that case, just add

method="post"


to the form tag and post it. In fact, for forms this is required by the HTTP spec, because of the way portlet action URLs are built. Here's the reason: Inspect the actual HTML resulting from this code:

<form action="<portlet:actionURL/>" method="get">
   <input name="test" type="text">
</form>


You'll find that <portlet:actionURL/> resolves to a URL containing parameters. To simplify it down: Assume you're submitting the above form with GET to http://example.com/doSomething?some=parameter&in=the&url, you'd expect the actual URL to be http://example.com/doSomething?some=parameter&in=the&url&test=whatever. However, the HTTP spec specifically states that the resulting URL will be http://example.com/doSomething?test=whatever. Only with POST you get all parameters transmitted to the server side and there's nothing Liferay could do about it. The only solution would be to use javascript to parse your parameters into hidden fields of that form. But then, it's bad style to submit forms that change state by GET.

So, advice: Just use

<form action="<portlet:actionURL/>" method="POST">
   <input name="test" type="text">
</form>
9年前 に Venkatesh Manam によって更新されました。

RE: URL can only be invoked using POST

New Member 投稿: 14 参加年月日: 13/11/12 最新の投稿
Thanks for the reply Olaf Kock,

Yes, I am using a form to store the configuration and I am using POST to submit the form. Still this error appears.
To give you more insight of what I am doing in the custom config tab

// Document library URL
LiferayPortletURL documentLibURL = PortletURLFactoryUtil.create(
request, PortletKeys.JOURNAL, themeDisplay.getPlid(),
PortletRequest.RENDER_PHASE);
documentLibURL.setWindowState(LiferayWindowState.POP_UP);
documentLibURL.setPortletMode(PortletMode.VIEW);
documentLibURL.setParameter("struts_action",
"/journal/select_document_library");
documentLibURL.setParameter("groupId",
String.valueOf(dlScopeGroupId));

<aui:form action="<%=configurationURL%>" method="post" name="configForm"
onSubmit='<%="event.preventDefault(); "
+ renderResponse.getNamespace()
+ "saveConfiguration();"%>'>
// select a file from Document Library(DL)
<aui:input name="preferences--lookupFileUrl--" type="text"
label=" " value="<%=lookupFileSrcURL%>" size="120"
id="selectedLookupFileUrl" readonly="true">
</aui:input>
<aui:button name="openFolderSelectorButton"
onClick="showFiles();" value="Browse" />

// Then some code to pre-fill the remaining configuration values with data from selected DL file
.....................
.....................
.....................
function showFiles()
{
var dl_url = '<%=documentLibURL%>';
fileSelectWindow = window.open(dl_url, 'fileSelect', 'directories=no,height=640,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=830');
fileSelectWindow.focus();
}

// This is triggered when the user selects a file from the DL. So when user selects a new file from DL. I am doing this to refresh the config page.
function _15_selectDocumentLibrary(url) {
// Append the selected file info to the url
..........
.........
window.location.href = modifiedurl;
}


I am thinking the issue is with the DL url I am using. Here is the error that I am getting

This URL can only be invoked using POST: /group/test1/venkat?p_auth=jmKxfN1P&p_p_id=86&p_p_lifecycle=1&p_p_state=pop_up&p_p_mode=view&controlPanelCategory=portlet_86&_86_struts_action=%2Fportlet_configuration%2Fedit_configuration&_86_returnToFullPageURL=%2Fgroup%2Ftest1%2Fvenkat%3Fp_p_id%3Dlookup_WAR_lookupportlet_INSTANCE_6Dhho4UJxYbf%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_mode%3Dview%26p_p_col_id%3Dcolumn-1%26p_p_col_count%3D1%26_lookup_WAR_lookupportlet_INSTANCE_6Dhho4UJxYbf_jspPage%3D%252Fhtml%252Flookup%252Fview.jsp%26&_86_portletResource=lookup_WAR_lookupportlet_INSTANCE_I5m99jEubPkS&_86_previewWidth=
INFO | jvm 1 | 2014/07/07 11:08:55 | 16:08:55,219 ERROR [http-bio-8180-exec-245][render_portlet_jsp:154] com.liferay.portal.security.auth.PrincipalException: /group/test1/venkat?p_auth=jmKxfN1P&p_p_id=86&p_p_lifecycle=1&p_p_state=pop_up&p_p_mode=view&controlPanelCategory=portlet_86&_86_struts_action=%2Fportlet_configuration%2Fedit_configuration&_86_returnToFullPageURL=%2Fgroup%2Ftest1%2Fvenkat%3Fp_p_id%3Dlookup_WAR_lookupportlet_INSTANCE_6Dhho4UJxYbf%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_mode%3Dview%26p_p_col_id%3Dcolumn-1%26p_p_col_count%3D1%26_lookup_WAR_lookupportlet_INSTANCE_6Dhho4UJxYbf_jspPage%3D%252Fhtml%252Flookup%252Fview.jsp%26&_86_portletResource=lookup_WAR_lookupportlet_INSTANCE_I5m99jEubPkS&_86_previewWidth=


Thanks,
Venkat
9年前 に Venkatesh Manam によって更新されました。

RE: URL can only be invoked using POST

New Member 投稿: 14 参加年月日: 13/11/12 最新の投稿
I missed this earlier, this is how I am creating the actionURL
<liferay-portlet:actionURL portletConfiguration="true" var="configurationURL" />

-Venkat
thumbnail
9年前 に Olaf Kock によって更新されました。

RE: URL can only be invoked using POST

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
well, and you're submitting the form from javascript and don't give away what you're doing in that method:

<aui:form action="<%=configurationURL%>" method="post" name="configForm"
onSubmit='<%="event.preventDefault(); " + renderResponse.getNamespace() + "saveConfiguration();"%>'>

Plus I still don't understand if you get that error message when you select a file, or what you do at all with that javascript fragment that you posted.
9年前 に Venkatesh Manam によって更新されました。

RE: URL can only be invoked using POST

New Member 投稿: 14 参加年月日: 13/11/12 最新の投稿
I am just submitting the form after setting some field values, See the code at bottom.

"Plus I still don't understand if you get that error message when you select a file, or what you do at all with that javascript fragment that you posted. "
Sorry I might have misdirected you, I am getting the error when I save the configuration.
OK regarding the JavaScript fragments.
showFiles()
From the IntialPortletConfiguration page (See screenshot3 attached) When I click on Browse button the DL file select window opens [screenshot2]
_15_selectDocumentLibrary(url)
When we choose a file from DL file select window the control returns to this function. Here I am appending the selected file info to the url and refreshing the page
/ Append the selected file info to the url
..........
.........
window.location.href = modifiedurl; // for refreshing the config page this allows me to pull data from selected file to pre-fill remaining fields [screenshot 1]

saveConfiguration Javascript fragment
Liferay.provide(
window,
'<portlet:namespace />saveConfiguration',
function() {
if(document.<portlet:namespace />configForm.<portlet:namespace />currentDisplayResultsColumns.length == 0 ||
document.<portlet:namespace />configForm.<portlet:namespace />currentDisplayKeysColumns.length == 0 ){
alert("Current List should atleast have a field");
return false;
}
else{
document.<portlet:namespace />configForm.<portlet:namespace />resultsCurrentDisplayList.value = Liferay.Util.listSelect(document.<portlet:namespace />configForm.<portlet:namespace />currentDisplayResultsColumns);
document.<portlet:namespace />configForm.<portlet:namespace />resultsAvailableDisplayList.value = Liferay.Util.listSelect(document.<portlet:namespace />configForm.<portlet:namespace />availableDisplayResultsColumns);
document.<portlet:namespace />configForm.<portlet:namespace />keysCurrentDisplayList.value = Liferay.Util.listSelect(document.<portlet:namespace />configForm.<portlet:namespace />currentDisplayKeysColumns);
document.<portlet:namespace />configForm.<portlet:namespace />keysAvailableDisplayList.value = Liferay.Util.listSelect(document.<portlet:namespace />configForm.<portlet:namespace />availableDisplayKeysColumns);

submitForm(document.<portlet:namespace />configForm);
}
},
['liferay-util-list-fields']
);