Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
33 replies Latest Post - ‏2013-01-25T22:49:52Z by SystemAdmin
SystemAdmin
SystemAdmin
13339 Posts
ACCEPTED ANSWER

Pinned topic 502388

‏2010-07-30T15:47:12Z |
502388
Updated on 2013-01-25T22:49:52Z at 2013-01-25T22:49:52Z by SystemAdmin
  • KeithDonald
    KeithDonald
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-07-30T15:47:13Z  in response to SystemAdmin
    Good article! I would love to see coverage of Spring MVC's HttpMessageConverter feature in a future article. This feature is the basis for the @ResponseBody/@RequestBody elements of the programming model that are designed for implementing REST-based web services. The following Spring MVC showcase covers this comprehensively: http://blog.springsource.com/2010/07/22/spring-mvc-3-showcase/.
  • Kendal
    Kendal
    8 Posts
    ACCEPTED ANSWER

    test

    ‏2010-08-03T01:48:02Z  in response to SystemAdmin
    Thanks for the interest and your requests. We will post another further on article covers that. Please stay tuned.
  • Kendal
    Kendal
    8 Posts
    ACCEPTED ANSWER

    test

    ‏2010-09-13T02:26:05Z  in response to SystemAdmin
    Another further on article about using HttpMessageConverter is published.
    http://www.ibm.com/developerworks/web/library/wa-restful/index.html
  • Vijay559
    Vijay559
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-10-08T21:44:39Z  in response to SystemAdmin
    Thanks for the article. It is what i am looking for..
  • benothman
    benothman
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-10-10T22:09:14Z  in response to SystemAdmin
    Good article! it was very helpful for me as a beginer in this domain
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2010-12-06T03:16:19Z  in response to SystemAdmin
    Hi,

    I have tried the above code with Spring 3.0.3 release.

    It worked only if i had @PathVariable("id")
    as
    @RequestMapping(method=RequestMethod.GET,value="/employee/{id}")
    public ModelAndView getEmployee(@PathVariable("id") String id){
    Employee e = empDS.get(Long.parseLong(id));
    return new ModelAndView(XML_VIEW_NAME,"object",e);

    }

    Why is it so?
  • MRaza
    MRaza
    1 Post
    ACCEPTED ANSWER

    test

    ‏2011-01-20T12:36:45Z  in response to SystemAdmin
    Nice tutorial; I tried it and and seen working perfectly. You should also include JSON support.
    Thanks,
    Raza
  • seano
    seano
    2 Posts
    ACCEPTED ANSWER

    test

    ‏2011-01-21T02:09:36Z  in response to SystemAdmin
    I'm getting an exception "Unable to locate object to be marshalled in model" with Spring 3.0.5. Any hints? Nothing I came across through Google seemed related.
  • seano
    seano
    2 Posts
    ACCEPTED ANSWER

    test

    ‏2011-01-21T02:21:17Z  in response to SystemAdmin
    Answered my own question: the "object" model name needed to be added to the class via @XmlRootElement annotation. Probably something fundamental to something that I have no experience with.
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2011-01-31T13:13:18Z  in response to SystemAdmin
    HTTP Status 404 - /Spring_web_example/service/employee/3

    I am getting this Error when i am trying the Running the Code.

    need your advice
  • BDSU_Jayamohan_Ganesan
    1 Post
    ACCEPTED ANSWER

    test

    ‏2011-02-22T19:28:10Z  in response to SystemAdmin
    I have got almost the same set up. But I'm getting the following error whenevere i send a post request. Get requests work fine. Any help will be greatly appreciated.

    Error 415: SRVE0295E: Error reported: 415
  • Kendal
    Kendal
    8 Posts
    ACCEPTED ANSWER

    test

    ‏2011-02-24T03:03:49Z  in response to SystemAdmin
    As far as I writing the article, I use the following JARs, I recommend you try the same configure and see.
    There is also a required_jars.txt in the package to tell you the version.

    If you could provide the detailed exception information, it would help more.

    com.springsource.com.sun.syndication-1.0.0.jar
    com.springsource.org.codehaus.jackson.mapper-1.4.2.jar
    com.springsource.org.codehaus.jackson-1.4.2.jar
    com.springsource.org.jdom-1.1.0.jar
    org.springframework.asm-3.0.2.RELEASE.jar
    org.springframework.beans-3.0.2.RELEASE.jar
    org.springframework.context-3.0.2.RELEASE.jar
    org.springframework.core-3.0.2.RELEASE.jar
    org.springframework.expression-3.0.2.RELEASE.jar
    org.springframework.oxm-3.0.2.RELEASE.jar
    org.springframework.web.servlet-3.0.2.RELEASE.jar
    org.springframework.web-3.0.2.RELEASE.jar
    commons-logging.jar
    jaxb-api.jar
    jaxb-impl.jar
    jstl.jar
    log4j-1.2.15.jar
    standard.jar
  • mke07
    mke07
    1 Post
    ACCEPTED ANSWER

    test

    ‏2011-05-28T21:35:27Z  in response to SystemAdmin
    Thanks for article.I am getting an error message like the following.How can I solve this problem ?

    SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
    java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
  • Kendal
    Kendal
    8 Posts
    ACCEPTED ANSWER

    test

    ‏2011-06-01T01:04:05Z  in response to SystemAdmin
    mke07,
    It looks like that you do not have a valid server runtime setup. javax/servlet/ServletContextListener should be in the standard j2ee servlet-api.jar. A correctly configured tomcat would save you.
  • jaalex
    jaalex
    2 Posts
    ACCEPTED ANSWER

    test

    ‏2011-07-18T06:53:03Z  in response to SystemAdmin
    The POST XML is missing the </email> closing tag ; apart from this, the example worked like a charm. Thanks!
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2011-07-18T13:16:30Z  in response to SystemAdmin
    Thanks for your comments. I have updated the code for both the POST and PUT code samples to include the </email> tag.
  • NMurali
    NMurali
    1 Post
    ACCEPTED ANSWER

    test

    ‏2011-09-29T15:05:27Z  in response to SystemAdmin
    Thanks.
    It worked. But I am getting only the xml output.
    In internet explorer:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    • <employees>
    <count>2</count>
    • <employee>
    <email>wudongf@cn.ibm.com</email>
    <id>2</id>
    <name>Wu Dong Fei</name>
    </employee>
    • <employee>
    <email>huangyim@cn.ibm.com</email>
    <id>1</id>
    <name>Huang Yi Ming</name>
    </employee>
    </employees>

    and using curl:
    C:\DevTools\curl>curl -H"Accept:text/html" http://localhost:8383/RestWS/service/employees

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><employees><count>2</coun
    t><employee><email>wudongf@cn.ibm.com</email><id>2</id><name>Wu Dong Fei</name><
    /employee><employee><email>huangyim@cn.ibm.com</email><id>1</id><name>Huang Yi M
    ing</name></employee></employees>

    Bothways I am getting the xml output only. Can you pls tell me as to where I am mixing. FYI, I am using the code downloaded. Its using ContentNegotiatingViewResolver.

    pls help.
  • TimP21337
    TimP21337
    3 Posts
    ACCEPTED ANSWER

    test

    ‏2011-10-21T13:58:09Z  in response to SystemAdmin
    Sharing a Mavenised version at https://github.com/timp21337/spring3rest
  • TimP21337
    TimP21337
    3 Posts
    ACCEPTED ANSWER

    test

    ‏2011-10-21T18:39:48Z  in response to SystemAdmin
    curl -HAccept:application/xml http://localhost:8080/rest/service/employee/1 works as expected
    curl -HAccept:applicatext/html http://localhost:8080/rest/service/employee/1 gives empty collection (html table with headers)

    There was a small error in rest-context.xml, the line http://www.springframework.org/schema/util needed to be added.
  • WadeYellow
    WadeYellow
    1 Post
    ACCEPTED ANSWER

    test

    ‏2011-11-04T18:42:00Z  in response to SystemAdmin
    To make this work...
    >>curl -HAccept:text/html http://localhost:8080/spring3rest/service/employee/1

    replace your getEmployee by...
    @RequestMapping(method=RequestMethod.GET, value="/employee/{id}")
    public ModelAndView getEmployee(@PathVariable String id) {
    Employee e = employeeDS.get(Long.parseLong(id));
    List<Employee> employees = new ArrayList<Employee>();
    employees.add(e);
    EmployeeList list = new EmployeeList(employees);

    return new ModelAndView(XML_VIEW_NAME, "employees", list);
    }
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2012-01-09T11:09:20Z  in response to SystemAdmin
    Thanks for this useful article. Can we generate WADL file with this ?. if yes then how ?
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2012-01-09T11:10:26Z  in response to SystemAdmin
    This post apart from other one which describes JSON data interchange with Spring REST is wonderful.
  • Kendal
    Kendal
    8 Posts
    ACCEPTED ANSWER

    test

    ‏2012-01-10T01:52:53Z  in response to SystemAdmin
    @Anup Awasthi
    I'm not sure for this.. You may find the answer yourself :)
  • sriramkasthuri
    sriramkasthuri
    2 Posts
    ACCEPTED ANSWER

    test

    ‏2012-02-01T13:16:43Z  in response to SystemAdmin
    Hi,
    I get the below error when I try to run the application.

    javax.servlet.ServletException: Unable to locate object to be marshalled in model: {org.springframework.validation.BindingResult.employees=org.springframework.validation.BeanPropertyBindingResult: 0 errors, employees=dw.spring3.rest.bean.EmployeeList@7878529d}
    org.springframework.web.servlet.view.xml.MarshallingView.renderMergedOutputModel(MarshallingView.java:100)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(Ht
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2012-03-29T04:29:17Z  in response to SystemAdmin
    I downloaded the source code and deployed in tomcat 6. but in curl and browser, for url, http://localhost:8080/rest/service/employees, i am getting HTTP Status 404 - /rest/service/employees

    Deployment looks ok, no error in console,

    INFO: Initializing Spring FrameworkServlet 'rest'
    Mar 29, 2012 12:14:06 PM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-8080
    Mar 29, 2012 12:14:06 PM org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /0.0.0.0:8009
    Mar 29, 2012 12:14:06 PM org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/27 config=null
    Mar 29, 2012 12:14:06 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 17335 ms

    Please Help.
  • G52P_Neel_Sukhadia
    G52P_Neel_Sukhadia
    1 Post
    ACCEPTED ANSWER

    test

    ‏2012-04-03T17:27:18Z  in response to SystemAdmin
    Excellent!! Still relevant and one of the best tutorials out there on the topic!
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2012-04-12T20:57:59Z  in response to SystemAdmin
    Thanks for the tutorial. I was able to test it successfully. However, I think title for this tutorial is a misnomer. It should have been "Build RESTful web apps using Spring 3" or something like that since the main class in this tutorial is adorned with "@Controller" annotation instead of "@WebService" annotation. While a web app typically returns html back to the client, a web service returns data in xml or json notation. I was not able to figure out how to change this tutorial to act as web service though.

    Thanks.
  • Scorpion_Keyur
    Scorpion_Keyur
    1 Post
    ACCEPTED ANSWER

    test

    ‏2012-05-07T07:56:34Z  in response to SystemAdmin
    Hello Sir,

    Its a very nice Tutorials for beginners. I have learn a lot from this. But i have one question in my mind that I would like to ask you. Here We are getting data in the form of HTML in Browser. And by using curl we are getting data in XML on the Console. And I want to use my service in Mobile Application so what I need as a result is either XML/JSON. So how can I get that? I also want to show data in the form of xml in browser also. So can you please guide me for that.

    Once again thanks for such a nice tutorial.
  • Kendal
    Kendal
    8 Posts
    ACCEPTED ANSWER

    test

    ‏2012-05-07T08:04:04Z  in response to SystemAdmin
    @Scorpion
    This need you to implement the server side to support multiple representation: HTML/XML/JSON, etc.
    Then you can take two approach
    1. use a URL param to indicate what is the desired representation. eg. &output=html, &output=json, etc
    2. use request header 'Accept' to indicate what your client need (eg. Accept=application/json), then in the server side parse this out and send output accordingly
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2012-06-07T11:41:37Z  in response to SystemAdmin
    Nice tutorial. Which is the efficient way to create rest client APIs for Spring restful application? I have a requirement to create APIs for my spring restful application.
  • RMorschel
    RMorschel
    5 Posts
    ACCEPTED ANSWER

    test

    ‏2012-07-31T10:26:59Z  in response to SystemAdmin
    IG Group have recently open-sourced their RESTdoclet solution, which is specifically aimed at documenting services built using Spring’s REST framework. We use this internally to automatically generate documentation for all our RESTful services and publish these via an internal web portal.

    More info here: http://ig-group.github.com/RESTdoclet/

    Robert @ IG Group
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2013-01-25T17:35:12Z  in response to SystemAdmin
    Nice tutorial,
    but as it is, retrieving employee by id is not working,
    rest-context.xml is wrong. will get " org.xml.sax.SAXParseException: SchemaLocation: schemaLocation ...must have even number of URI's" error msg.

    But easy fix tho.
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2013-01-25T22:49:52Z  in response to SystemAdmin
    also the use of POST vs PUT seems against the common practice , see http://vantsuyoshi.wordpress.com/2012/08/10/when-to-use-http-post-vs-put/
    tho its not a big deal.