struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john lee <sh_thorn_b...@yahoo.com.INVALID>
Subject struts2 +rest service problem
Date Wed, 19 Jul 2017 21:13:14 GMT

Please help for the struts2 + rest service 

http://beta-dev/ecommerce/employee.xml




return the following error report

Struts Problem Report
Struts has detected an unhandled exception:
| Messages: |    
   - com.thoughtworks.xstream.XStream
   - com/thoughtworks/xstream/XStream
   - java.lang.reflect.InvocationTargetException
   - java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
   - java.lang.RuntimeException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
   - java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
 |
| File: | org/apache/catalina/loader/WebappClassLoader.java |
| Line number: | 1,714 |


Stacktraces
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException    com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:301)
    com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:492)
    com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:530)


source code:
cat Employee*.java
package xyz;
import xyz.*;
import java.util.Map;
import org.apache.struts2.rest.DefaultHttpHeaders;import org.apache.struts2.rest.HttpHeaders;import
com.opensymphony.xwork2.ModelDriven;public class EmployeeController implements ModelDriven<Object>{ 
      private static final long serialVersionUID = 1L;        private String id; 
      private Object model;        private EmployeeRepository employeeRepository =
new EmployeeRepository();        private static Map<String,Employee> map;     
  {                map = employeeRepository.findAllEmployee();        }   
    public HttpHeaders index() {                model = map;             
  return new DefaultHttpHeaders("index").disableCaching();        }        public
String add(){                Integer empId = Integer.parseInt(id);           
    Employee emp = new Employee(empId,"Ramesh", "PQR");                model = emp; 
              return "SUCCESS";        }        public String getId() {  
             return id;        }        public void setId(String id) {   
            model = employeeRepository.getEmployeeById(id);                this.id
= id;        }        @Override        public Object getModel() {        
       return model;        }} 
package xyz;
import java.util.*;import xyz.*;

public class Employee {        private Integer id;        private String name;   
    private String company;        public Employee(Integer id, String name, String company){ 
              this.id =id;                this.name = name;           
    this.company = company;        }        public Integer getId() {        
       return id;        }        public void setId(Integer id) {        
       this.id = id;        }        public String getName() {          
     return name;        }        public void setName(String name) {        
       this.name = name;        }        public String getCompany() {      
         return company;        }        public void setCompany(String company)
{                this.company = company;        }} package xyz;

import java.util.*;import java.sql.Timestamp;import xyz.*;
import java.util.HashMap;import java.util.Map;
public class EmployeeRepository {        private static Map<String,Employee> map
= new HashMap<String,Employee>();         public EmployeeRepository(){     
          map.put("111", new Employee(111, "Ram", "ABC"));                map.put("222",
new Employee(222, "Shyam", "EFG"));                map.put("333", new Employee(333,
"Mohan", "XYZ"));        }        public  Employee getEmployeeById(String id){  
             return map.get(id);        }        public  Map<String,Employee>
findAllEmployee(){                return map;        }} 

my configuration for struts.xml 


<include file="struts-default.xml"/>

    <!-- rest and regular coexist-->

  <constant name="struts.action.extension" value="xhtml,,xml,json,action"/>




  <constant name="struts.mapper.class" value="rest" />




  <constant name="struts.mapper.class" value="org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper"
/>

  <constant name="struts.mapper.prefixMapping" value="/rest:rest,:struts"/>

  <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"/>





Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message