Solved : No configuration found for the specified action

Solved : No configuration found for the specified action

Solved : No configuration found for the specified action 


Issue: Warning : No configuration found for the specified action on struts 2 action call..


Fix : Check your struts.xml and action mapping and map it with your jsp form submission
for example,

Action mapping 
<action name="login" method="login"
class="com.tcs.ecmui.action.CredentialWatcher">
<result name="success" type="redirect">getAllPages</result>
<result name="error">/resources/jsp/login.jsp</result>
</action>
..
.. 
<package name="readNode" extends="struts-default,json-default" namespace="/">
</package>


Jsp

<s:form action="login" method="POST">
<s:textfield name="user" label="User" />
<br>
<s:password name="password


Problematic Code :

<s:form action="/login" method="POST">
<s:textfield name="user" label="User" />
<br>
<s:password

or

<s:form action="/login.action" method="POST">
<s:textfield name="user" label="User" />
<br>
<s:password
Struts 2 Rest Convention Plugin Configuration Example

Struts 2 Rest Convention Plugin Configuration Example

Struts 2 Rest Convention Plugin Configuration Example


I was playing around with Struts 2.3.8 and I really liked it the way apache has bundled it with lots of plugins that can help developers shrink their coding efforts hugely.

I was trying with conventions plugin and a simple struts action. The action was not loading saying there is no mapping found.. After couple of tries I could make it work.. Posting the same if some one might find it helpful in saving time..

Action


package com.mycomp.recruit.actions;

import java.util.Collection;

import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Validateable;
import com.opensymphony.xwork2.ValidationAwareSupport;

@Results({
    @Result(name="success", type="redirectAction", params = {"actionName" , "authentication"})
})
public class AuthenticationController extends ValidationAwareSupport implements ModelDriven<Object>, Validateable{
    
    /**

*/
private static final long serialVersionUID = 1L; 
    private String id; 

    // GET /orders/1
    public HttpHeaders show() {
        return new DefaultHttpHeaders("show");
    }
    
    public HttpHeaders index(){
    System.out.println("Going thru authentication..");    
    return  new DefaultHttpHeaders("index").disableCaching();
    }


    public void validate() { 
    }

    public void setId(String id) {
        if (id != null) { 
        //do nothin!??
        }
        this.id = id;
    }
    
   public Object getModel() { 
  return null;
    }

}


struts.xml


<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <!--  Overwrite Convention -->
    <constant name="struts.convention.action.suffix" value="Controller"/>
    <constant name="struts.convention.action.mapAllMatches" value="true"/>
    <constant name="struts.convention.default.parent.package" value="rest-default"/>

    <constant name="struts.convention.package.locators" value="example,actions"/>
    
</struts>


JSP


/web-inf/content/authentication-index.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Authenticate..
</body>
</html>




Alfresco Authenticate -get the valid ticket & invalidate the login.

Alfresco Authenticate -get the valid ticket & invalidate the login.

Alfresco Authenticate -get the valid ticket & invalidate the login.



import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class AuthenticationService {

PropertyService propS = PropertyService.getInstance();

public String validateTicket(String ticket){
URL url = null;
HttpURLConnection connection = null;
try {
String adminTicket = readTicket();
String query = String.format("alf_ticket=%s",
URLEncoder.encode(adminTicket, "UTF-8"));
url = new URL(propS.getKeyValue("systemURL")+ "alfresco/service/api/login/ticket/"+ ticket+ "?"+query);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.connect();
InputStream is = connection.getInputStream();
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document xmlDoc = docBuilder.parse(is);
System.out.println("Validated Ticket =>" + xmlDoc.getElementsByTagName("ticket").item(0).getTextContent());
return xmlDoc.getElementsByTagName("ticket").item(0).getTextContent();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
}
return null;
}

public String readTicket() {
System.out.println("Trying to readTicket()");
URL url = null;
HttpURLConnection connection = null;
try {
String query = String.format("u=%s&pw=%s",
URLEncoder.encode(propS.getKeyValue("adminuser"), "UTF-8"),
URLEncoder.encode(propS.getKeyValue("adminpassword"), "UTF-8"));
url = new URL(propS.getKeyValue("systemURL")+"alfresco/service/api/login?"
+ query);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.connect();
InputStream is = connection.getInputStream();
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document xmlDoc = docBuilder.parse(is);
System.out.println("Ticket =>"
+ xmlDoc.getElementsByTagName("ticket").item(0)
.getTextContent());
return xmlDoc.getElementsByTagName("ticket").item(0)
.getTextContent();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
}
return null;
}

public boolean invalidatelogin(String ticket){
URL url = null;
HttpURLConnection connection = null;
try{
String adminTicket = readTicket();
String query = String.format("alf_ticket=%s",
URLEncoder.encode(adminTicket, "UTF-8"));
url = new URL(propS.getKeyValue("systemURL")+ "alfresco/service/api/login/ticket/"+ ticket+ "?"+query);

connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded" );
connection.setRequestMethod("DELETE");
int responseCode = connection.getResponseCode();

connection.connect();
System.out.println("<<<<>>>>" +responseCode);
}catch(Exception e){
e.printStackTrace();
}
finally {
if (connection != null) {
connection.disconnect();
}
}
return true;
}

//Test method
public static void main(String args[]){
String newP = "TICKET_368733fe59db7b634b5767c807538f27db9f403a";
AuthenticationService au = new AuthenticationService();
//newP = au.readTicket();
System.out.println(" Validate Ticket ::> "+newP);
au.validateTicket(newP);
// System.out.println("Deletion : "+au.invalidatelogin(newP));
}
}