• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Struts2 + Rest web service example please

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is struts2 supports rest webservice?? If 'Yes' Please provide me the link. I tired but i am not getting any link.

My application was built on struts2 with rest webservice. When they tried to access those service from outside (other application). They are passing client certificate and other keystore file, then they consuming those service.
Our requirement is -- those services need to consume by LDAP based authentication. So i removed all the filters on web.xml which was mapped with the service. Then i tried to hit the url from rest client. Then it says no action is mapped with service.

My doubt is whether struts2 framework will supports rest service?

Please help me to resolve my issue

 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saravanan sambandam wrote:Is struts2 supports rest webservice?
...
My application was built on struts2 with rest webservice.



These two sentences contradict each other. Either your application is a REST webservice (and therefore REST works with Struts 2) or it isn't.

saravanan sambandam wrote:
I removed all the filters on web.xml which was mapped with the service. Then i tried to hit the url from rest client. Then it says no action is mapped with service.



So you removed all the mappings and the application correctly said there were no mappings. Sounds like it worked as designed.

saravanan sambandam wrote:Our requirement is -- those services need to consume by LDAP based authentication.



This sounds like your actual question: Does Struts 2 REST work with LDAP authentication.
That I don't know. Usually, a Struts application would use the standard declarative security mechanism specified in JEE. I assume the same mechanism would work with REST. The actual source for credentials (i.e. LDAP) is configured in your application container. Your client would need some way to communicate its credentials according to the authentication method specified by the application.
Did you write this application or are you taking over an existing project?
 
saravanan sambandam
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I am taking an existing project.

my struts.xml

web.xml


Java class

 
saravanan sambandam
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://localhost:8080/Lottus/languageResource/ - when i hit this URL from browser, i am getting error message no action is mapped with this action. Could you please help me out to resolve this issue. Where i made the mistakes on above.

I am new to strust2 framework and rest service is also new.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saravanan sambandam wrote:http://localhost:8080/Lottus/languageResource/ - when i hit this URL from browser, i am getting error message no action is mapped with this action. Could you please help me out to resolve this issue. Where i made the mistakes on above.



Is the URL correct? The display name of the application according to web.xml is "LOTTUES". Can you open your server console and see where the application was deployed?
If it is the correct URL or if you get the correct URL and you still get an error, do you see any errors in the server log?

saravanan sambandam wrote:
I am new to strust2 framework and rest service is also new.



It will be very difficult for you to pick up a working application and make changes to it without understanding the framework it uses. I recommend running through the tutorials and introduce the desired functionality (authentication, REST) one at a time rather than trying to tackle everything at once.
I see you are using the javax.ws.rs classes. I don't have any experience with them and I don't know if Struts plays nice with them. That would be something you would want to sort out by going through the tutorials and documentation. I would probably rely on the Struts REST plugin to add REST functionality to a Struts app.
 
saravanan sambandam
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Thanks for your reply. My url is correct, bu the changes in web.xml (LOTTUES --> LOTUS).

Implemented with Struts ActionMapper.java class

also on struts.xml


After login my application. struts other action are working fine, i just hit the REST URL from browser (http://localhost:8080/lotus/MascomWS/languageResource/Language), now my rest service is calling. But, it shows error message. What & where i done the mistake? Please help me.

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
com.lotus.Mascom.action.CustomActionMapper.getMapping(CustomActionMapper.java:18)
org.apache.struts2.dispatcher.ng.PrepareOperations.findActionMapping(PrepareOperations.java:159)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:84)
com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:270)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.61 logs.

Apache Tomcat/7.0.61

 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Looks like you have an exception in line 18. Unfortunately, the code you posted is not complete, so the line numbers don't match up.
Why are you using a custom action mapper?
 
saravanan sambandam
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My application having struts actions and rest service. Based on the action this customActionMapper will find and call accordingly. Hence, i decided to go with customActionMapper. Is this wrong? Please advise me. Or else any approach is there? Link also provided - Mapping REST URLs to Struts 2 Actions http://struts.apache.org/docs/rest-plugin.html.

You mentioned that the line no.18 was an issue, and was removed the package name & import statement. The full code is below


Can you please help to resolve this issue.

Thanks in advance
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saravanan sambandam wrote: Link also provided - Mapping REST URLs to Struts 2 Actions http://struts.apache.org/docs/rest-plugin.html.



I don't see anything at that link indicating that one should use a custom action mapper. There's a mention of RestActionMapper, but that is part of the REST Plugin, which you do not appear to be using.
Again, my recommendation would be for you to start with the basics and build up. You appear to be spinning your wheels trying to wedge functionality you don't understand into an application you didn't write.
 
saravanan sambandam
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. I gone through this link and implemented

http://stackoverflow.com/questions/17697432/struts2-rest-plugin-making-both-struts-actions-rest-actions-work-together-but


As you said, i will do the basic simple application which have both struts2 action and rest url.


Thanks
 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic