0

I'm new in struts2, I tried to use Restful but I can't config.

I have 2 Controllers:

UsersController

@Namespace("/api")
public class UsersController extends ActionSupport implements ModelDriven<Object> {
}

ListController

@Namespace("/api/users/{user_id}")
public class ListController extends ActionSupport implements ModelDriven<Object> {
}

I would like to create API like this:

/api/users/ -> method UsersController.index

/api/users/{user_id} -> method UsersController.show

/api/users/{users_id}/list -> method ListController.index

/api/users/{users_id}/list/{list_id} -> method ListController.show

I tried config struts.properties

struts.devMode = true
struts.convention.action.suffix = Controller
struts.convention.action.mapAllMatches = true
struts.convention.default.parent.package = rest-default
struts.convention.package.locators = controller
struts.rest.defaultExtension = json
struts.action.extension = 
struts.mapper.alwaysSelectFullNamespace = false
struts.mapper.idParameterName = id
struts.patternMatcher = namedVariable
struts.mapper.class = org.apache.struts2.dispatcher.mapper.Restful2ActionMapper
struts.enable.SlashesInActionNames = true

It doesn't work like what I want.

Do you have any suggestion?

Luc
  • 2,800
  • 2
  • 25
  • 46
  • Do you use Struts2 REST plugin? or do you have a jar struts2-rest-plugin.jar on classpath? – Lukasz Lenart Jul 08 '13 at 09:17
  • Sure, that's the first I add to lib. And I used struts2-rest-plugin.2.3.15.jar – Luc Jul 09 '13 at 04:09
  • If so you cannot mix Restful2ActionMapper (from Struts2 Core) with the Struts2 REST Plugin (which has its own ActionMapper). You must decide to use only one. – Lukasz Lenart Jul 09 '13 at 09:04
  • That's mean I have to chagne *.parent.package = rest-default to *.parent.package = rest2-default ??? I don't know where? :D – Luc Jul 09 '13 at 09:45
  • No, if you don't want to use the REST plugin, remove struts2-rest-plugin.jar and just follow description from here http://struts.apache.org/development/2.x/docs/restfulactionmapper.html#RestfulActionMapper-Restful2ActionMapper – Lukasz Lenart Jul 09 '13 at 12:51
  • But I'm not sure if what you want is possible with Struts2 :\ – Lukasz Lenart Jul 09 '13 at 12:51

0 Answers0