aspose file tools*
The moose likes Spring and the fly likes Within the infrastruture - How to and Where - to intercept HTTP request and to send HTTP response? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Within the infrastruture - How to and Where - to intercept HTTP request and to send HTTP response?" Watch "Within the infrastruture - How to and Where - to intercept HTTP request and to send HTTP response?" New topic
Author

Within the infrastruture - How to and Where - to intercept HTTP request and to send HTTP response?

Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
Hi,

I need help in finding out how to and where (in the infrastructure) to intercept an HTTP request (PUT, GET...), capture its associated data, process it and then create an XML file to send out with an HTTP response, either manually or if there is a way to set up the plumbing to allow this to happen.

Spring 3.x and Hibernate 3.x with annotations are used. It is a Web application. Where should all these happen within the project infrastructure (in Eclipse).

Is there any sample code out there that I can use? This seems to be a very common thing that is done all the time; - (in the confines of Spring+Hibernate, that is)

Can someone please help me?

Many Thanks in advance.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not sure what you're asking--are you saying you want to do something other than the normal request flow? If so, why?
Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
Hi David,

This project is for a web service and the purpose of it is to run in a Server as a web application, take in HTTP requests from mobile phones and send out HTTP responses with results from MySQL databases via Hibernate; in XML format back to the mobile device.

I am using @RequestMapping in the controller and different views like Create, Show, List...etc.


For views e.g.


If the normal request flow allows me to receive a HTTP request, examines data that comes with this request, access MySQL via Hibernate to process and retrieve results and finally allows me to compose a XML file and send it back to the requester via a HTTP response, should I put this business logic within the Controller and using the model and view paradigm like below, e.g. the HTTP request is a GET for all the businesses that are established after year 2001. The web service will first need to know about this criteria (i.e. businesses opened after 2001), look up database and instead of displaying the result on a View, it needs to compose an XML file to send out with the HTTP response.

I don't know how and where I can plug this business logic within the normal request flow and let the plumbing does the packet flow stuff. E.g.


Should I create the HTTP Requests as POJOs and use to them as data models to map to the different HTTP Requests (i.e. GET, PUT, POST....) coming in and create Views for the different XML files that need to be composed/filled-in for returning with the HTTP Response? If that is the case, I only need to create Request POJOs and Response Views and let the current request flow plumbing infrastructure do the rest?

I hope my question is made a bit clearer.

Looking forward to your help.

Many Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I still don't see how this is different than what Spring already does: are you asking how to change the response type (HTML vs. XML) based on the client?
Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121

I am quite new in Spring and REST and really needing some sample code.

I knew I need to use HttpMessageConverter to read and write XML using Spring's marshaller and unmarshaller and the MarshallingView uses XML Marshaller to render the response content as XML.

If I have a Response Bean that represents my HTTP Response XML schema, the JAXB2 marshaller will turn this bean into XML.

Although I am expecting XML requests and response, I am not sure if I still need the ContentNegotiatingViewResolver.

And for REST mappings (HTTP to CRUD), do I create POJOs for each HTTP Request and Response (GET,PUT,POST,DELETE...) and Views for each XML relevant contents that I need to receive and sent out?

How do I put all these together in a RESTFUL way? I tried Roo to examine what's generated for me but I think I need more info and SAMPLE CODE to start.

Can you point me to a Sample project that does closest to what I am looking for to use as a project+code template ?

Many Thanks and I really need some help to do this a.s.a.p.

Sincerely....

Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121

....I should add that I am looking for the server-side code.
Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
If I may be more specific in what I hope to get, someone will/may help me...hopefully.

I have general understanding of the RESTful support from Spring 3.0. I have pieces of the components but I need sample code to put this all together.

I am looking for a sample RESTful project that includes the following key words:

Marshaller
UnMarshaller
MarshallingHttpMessageConverter
Marshalling View
@RequestBody
@ResponseBody
XSLTView
CRUD REST mappings
<other regular ones....>

Looking forward to your help.

Many Thanks in advance.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Within the infrastruture - How to and Where - to intercept HTTP request and to send HTTP response?