Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danielgek/3bca6b43402dc82ac926 to your computer and use it in GitHub Desktop.
Save danielgek/3bca6b43402dc82ac926 to your computer and use it in GitHub Desktop.
StrutsRestPlugin
package com.danielgek.webclient.controllers;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import org.apache.struts2.rest.RestActionSupport;
/**
* Created by danielgek on 26/11/15.
*/
public class UsersController extends RestActionSupport implements ModelDriven<Object> {
private Object object;
// GET /data/order/1
public HttpHeaders show() {
object = "asdfasdfasdf";
return new DefaultHttpHeaders("show");
}
// GET /data/order
public HttpHeaders index() {
return new DefaultHttpHeaders("index")
.disableCaching();
}
@Override
public Object getModel() {
return object;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.package.locators" value="controllers"/>
</struts>
<%--
Created by IntelliJ IDEA.
User: danielgek
Date: 27/11/15
Time: 00:10
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" metadata-complete="true">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment