Expand my Community achievements bar.

SOLVED

AEM Custom Form Action

Avatar

Level 3

I am working on custom form action.

So far I am able to achieve the following points.

1. Added Custom Form Action.

2. Overlap Forward.jsp page.

3. From Forward.jsp able to successfully route to Custom SlingServlet.

4. In Custom Sling Servlet I have the following requirement.

     a. Get all request parameters

     b. Send the request to third part application by using HttpClient

     c. On response equals to 200 rout the servlet to Thank you page.

Right now I have 2 issues.

1. In HttpClient I am able to pass the request data if I hard code the value , but if I try to submit it by dynamically populated to NameValuePare Array even though values are there it is not getting processed.

2. Once I have response as 200 I am not able to route the servlet to "Thank you page" , but getting the following exception.

-----------------------------------------------

SlingServlet Code.

-----------------------------------------------

@Override
protected void doPost(SlingHttpServletRequest request,
   SlingHttpServletResponse response) throws ServletException,
   IOException {
  LOG.debug("Enter into doPost method");

  NameValuePair[] requestFormdata = null;
  ProcessHttpClientUtil processHttpClientUtil = null;
  int responseCode = -1;

  processHttpClientUtil = new ProcessHttpClientUtil();
  requestFormdata = postToApp(request);

  responseCode = processHttpClientUtil.processHttpClient(response, requestFormdata,
    formsConfigService, formsConfigService.getAppURL() );

 
  if (responseCode == HttpStatus.SC_OK){
 
   response.getWriter().print(" Request Successuflly Processed");
  
   request.getRequestDispatcher(request.getParameter(":redirect")).forward(request,response);

// :redirect is path of Thank you page "/content/aruba/na/us/n/thankyou.html".

}else
  {
   response.getWriter().print(" Request Failed to Processed");
  }
 
  LOG.debug("Exit from doPost method");
}

@SuppressWarnings("unchecked")
private NameValuePair[] postToApp(
   final SlingHttpServletRequest request) {

 

  Map<String, String> requestMap = null;
  Iterator<String> iterator = null;
  String parameterKey = null;
  NameValuePair[] data = null;
  int count = 0;
  int totalParam = 0;

  requestMap = request.getParameterMap();

  LOG.debug("Result from Iterator Map" + requestMap.size() + " "
    + requestMap);

  if (requestMap.keySet() != null) {
   iterator = requestMap.keySet().iterator();
   totalParam = requestMap.size();
  }

  data = new NameValuePair[totalParam + 1];

  if (iterator != null) {
   while (iterator.hasNext()) {
    parameterKey = (String) iterator.next();

    data[count] = new NameValuePair(parameterKey,
      request.getParameter(parameterKey));
    count++;


   }

   data[count] = new NameValuePair("encoding", "UTF-8");

   // Need to remove
   LOG.debug("Result from Iterator final length " + data.length);

   LOG.debug("Exit from postToSalesforce method");
  }


  return data;
}

NOTE : IN Exception Oid = 00D90000000b33A is highlighted it is nothing but the hidden parameters added in Start.jsp page.

Since I am calling RequestDispatcher and passing the request parameters these values are also getting passed to Thanks you page.

----------------------------------------------------------------------------------

EXCEPTION DETAILS ON ROUTING REQUEST TO THANK YOU PAGE

----------------------------------------------------------------------------------

Error while processing /content/aruba/na/us/n/thankyou

Status
500

Message
javax.jcr.nodetype.ConstraintViolationException: No matching property definition: Oid = 00D90000000b33A

Location /content/aruba/na/us/n/thankyou
Parent Location /content/aruba/na/us/n
Path
/content/aruba/na/us/n/thankyou

Referer http://localhost:4504/content/aruba/na/us/n/salesforce.html
ChangeLog
<pre></pre>

-------------------------------------

From ERRO LOG File.

01.10.2014 12:22:10.288 *ERROR* [0:0:0:0:0:0:0:1 [1412146328863] POST /content/aruba/na/us/n/salesforce.html HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing.

javax.jcr.nodetype.ConstraintViolationException: No matching property definition: Oid = 00D90000000b33A

at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:522)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1305)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1294)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:308)

at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1294)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:422)

at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.store(SlingPropertyValueHandler.java:592)

at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setPropertyAsIs(SlingPropertyValueHandler.java:305)

at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setProperty(SlingPropertyValueHandler.java:159)

at org.apache.sling.servlets.post.impl.operations.ModifyOperation.writeContent(ModifyOperation.java:411)

at org.apache.sling.servlets.post.impl.operations.ModifyOperation.doRun(ModifyOperation.java:101)

at org.apache.sling.servlets.post.AbstractPostOperation.run(AbstractPostOperation.java:92)

at org.apache.sling.servlets.post.impl.SlingPostServlet.doPost(SlingPostServlet.java:200)

at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:148)

at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344)

at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375)

at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:511)

at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)

at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:146)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)

at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:357)

at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:166)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)

at com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:96)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)

at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:284)

at org.apache.sling.engine.impl.SlingRequestProcessorImpl.dispatchRequest(SlingRequestProcessorImpl.java:324)

at org.apache.sling.engine.impl.request.SlingRequestDispatcher.dispatch(SlingRequestDispatcher.java:216)

at org.apache.sling.engine.impl.request.SlingRequestDispatcher.forward(SlingRequestDispatcher.java:144)

at com.day.cq.wcm.core.impl.WCMComponentFilter$ForwardRequestDispatcher.forward(WCMComponentFilter.java:418)

at com.aig.dmfc.forms.SalesforcePostServlet.doPost(SalesforcePostServlet.java:97)

at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:148)

at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344)

at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375)

at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:511)


Advice and Guidence on this will help.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here is an artilce that shows you how to create a cusotm form action. WHen you click the submit button - it goes to a post.Post.JSP that you can then pass the submitted data to an OSGi service:

Scott's Digital Community: Creating a custom action for an Adobe Experience Manager Form component

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Here is an artilce that shows you how to create a cusotm form action. WHen you click the submit button - it goes to a post.Post.JSP that you can then pass the submitted data to an OSGi service:

Scott's Digital Community: Creating a custom action for an Adobe Experience Manager Form component

Avatar

Level 10

This answer is a test, please disregard.

Test