Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!

Mimi Tam

Ranch Hand
+ Follow
since Mar 05, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mimi Tam


My RestTemplate client needs to "bring up" a HTTP Request Form (for input) created by the Web Service, enters data and hit the SEND button via the browser. The Web Service will process Form data, create an HTTP Response message in XML and send back to the RestTemplate client.

Two questions:

1. How can the RestTemplate client "bring up" this Form (*.jspx in the WS) created by the Web Service to the browser?
2. From the Web Service's HttpRequest controller at POST (after input data), how can I trigger the GET, POST handlers from the Web Service's HttpResponse controller?


My Client App:

My demo client POJO:

HTTP Request Controller in the Web Service:




Any help will be greatly appreciated.








10 years ago
How exactly can I trigger display of a model and view from another model and view’s controller?

HTTP Request View --> HttpRequestController POST -> new HttpResponse POJO and a string of the POJO in XML for the Http Response msg to be sent back to the Requestor --> <what should I return from the POST handler?>

I have HttpRequestController() to handle a POST message with data from an input Form and populated an HttpRequest POJO with it. An HttpResponse POJO is composed and persisted along with the HttpRequest to a Db.

The HttResponse is made into an XML string as the @Responsebody to be sent back (as an actual HTTP Response message with header and body) and I want to present this HttpResponse POJO in a View.

I tried different things, none worked and I could not find a similar example anywhere.

HttpRequestController, HttpRequest and HttpResponse POJOs:
I have an HttpResponse View (jspx) for ‘show’ and an unused HttpResponseController():

What should I return from the HttpRequestController().POST to trigger an HTTP Response message to be sent back and the data-sent-back to be shown on in an HTTP Response View?

I desperately need help. I’d be quite grateful for any pointers, any info or any suggestions. Please kindly help.
10 years ago

I am looking for a simple but complete Spring project that uses Logback's Teefilter in the MVC framework.

Your help will be greatly appreciated.
10 years ago

I am looking for a simple but complete Spring project that uses Logback's Teefilter in the MVC framework.

Your help will be greatly appreciated.
10 years ago
In my RESTFUL Web Service, when HttpRequestController() got a POST, a new HTTP Response will be created in XML format and sent back to the Requestor as a HTTP Response message.

I (Web Service) also need to display this already sent HTTP Response in a predefined View.

Everything is done in the Server, Client is just a browser.

Please see my Controller code below:


Questions:

1. What should I return from the HttpRequestController() in order to get the HttpResponse View show up in Client's browser?

2. I know I can only do one or the other; either returning a HTTP Response View or the HTTP Response message in XML format straight to the Requestor's URL (i.e. Browser). How can I do the latter? By returning an HTTP Response object(POJO) like below?

public @ResponseBody HttpResponse createResponse(@RequestBody HttpRequest httpRequest) {...}

Any info/help will be greatly appreciated.
10 years ago
It finally worked. I did not make any changes.

By "it worked", I meant that it passed the persist() action and moving on.....to another question.

Thanks!
10 years ago

I really need an example on this as I have no idea how this is done and finally gave up after fiddling with it long enough.


A list of Class TestSubClass is part of Class ABC.

I need Class ABC to be mapped and populated with a list of TestSubClass (i.e. testSubClassList) objects inside an instance of Object ABC. Various exceptions when persisting to MySQL.

How shall I do this? Please help.

Any help will be greatly appreciated.
10 years ago
Dear Bill,

I wrote: "...I think I will have to return NULL to get MVC to send back just a HTTP Response message to the sender URL (the wireless device)...."

Your response: "...Why not use HTTP response codes to communicate or just send an empty response body? MVC is pretty intuitive, don't worry too much about it. The main thing is not to get your M tangled up with V and C. ...."



Sorry, I was not clear here or I am just really confused. What I meant was that to have the Controller returning a View, a View will be displayed with the data model. In order for the Controller to not do anything (e.g. looking for a View to retutrn) but just send the HTTP Response message out, I thought the way to do it is to return NULL from the Controller and the Controller will know what to do.

For Web Client (wired):
For Wireless Client:

Am I making any sense?

I always have doubt on the wireless client bit (2nd block above). Is that indeed the way to indicate in the Controller to Spring that this POST request has been handled (so no View to return) but will still send the @ResponseBody (after it automatically added an HTTP Header for me) to the HTTP Requestor URL for me?

Many THANKS for your help!
10 years ago
Dear Bill,

Thank you so much for all the useful advice and explanation. They are most helpful. I really appreciate it.

"...IF you want the response to be treated and displayed as a string, you are already there.

IF you want the response to be parsed (XML, CSV, some other format) THEN will have to write some response handling code, which I suppose will be called a web client. There is no useful framework for REST clients as far as I know but it should be simple....



I am indeed already there as the Server App is displaying the HTTP Response returned by it to the sender URL on the screen as formatted text. I am going to create a Response View (Show) so that the Server App can return this View instead of a String for the browser user to see it more easily.

Nevertheless, I have 2 scenarios:

1.) For a Web Client (vs Wireless Client), I can return this Response View just like any other Views. No Problem

2.) For a Wireless Client, I am calling XStream to serialize the HTTP Response to XML before sending it out to the URL of the wireless endpoint.

I am doing both in my Web Server App. It sounds like that if the Browse User is not expected to do anything but simply to receive the HTTP Response either via a View constructed and sent back by the Server App (in which case, user simply sees a returned formatted web page) or for a wireless device, to receive the HTTP Response in XML format as is, then I don't need a Web Client.

The RESTFUL Web Client web site that talks about using the "RestTemplate" (http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/) is the scenario that I don't think mine resembles but just want to make sure.

From your clear and precise explanation, I am convinced that I don't need a separate Web client.

My very sincere THANKS!







10 years ago

Thank you very much for your reply.

I have wired clients and wireless clients. For wireless clients, the only communication between Server and client is via HTTP messaging, message body is in XML format.

The wireless client (iPhone, Blackberry, Android...) can do whatever they want with the returned data.

My wired clients (also for testing purposes) are Web Browser users. They URL into the Server and see the Home Page. they clicked something and a customized HTTP Request Form shows up for them to enter data. This HTTP Request Form is the View ('V' of the MVC) that the Server presents.

User done entering data and click a SEND button. The Server than use the Form data to compose a HTTP Response in XML format to be sent back to the sender URL. For testing in wired connections via the Internet, the Server side returns a View of a customized HTTP Response message Form to display what data has been sent.

My Web Service is acting both as a Server and a Client because it is capable of receiving HTTP Request and sending HTTP Response back. Only for testing, the HTTP Response will be displayed on a web page to show the user what has been sent. This is also a View (i.e. the HTTP Response View) that the Server puts out under the MVC model.

For wireless endpoints, they send HTTP Request to Server and get back HTTP Response, that's it. The Server currently do the following:


Now, the Server returns a long string to be displayed on the screen. I will change it to return a HttpResponse View with data. That way, any browser accessing my Server will see Forms to enter data and Forms to see what they had sent.

Ultimately, the Service will have to distinguish between wired and wireless HTTP requests. For wireless request, under the MVC model, instead of returning a View (*.jspx) to the DefaultHandler() and display this View on the client browser, I think I will have to return NULL to get MVC to send back just a HTTP Response message to the sender URL (the wireless device).

There are a few things that I simply don't know how to go about doing it yet (using the MVC model). For now, I want to get the wired web client working (i.e. to consume my Web services, put the composed Response message onto a Form to be shown on the Requestor's browser.

In this scenario, do I need a separate Web Client?

Thank you so much for reading thru my problem.

Any help will be tremendously appreciate.























10 years ago
Thank you so much for your reply, Bill.

"demo" is a Web Service running in a Server (Tomcat, JBOSS) so anyone with a browser can access it via the Internet and to fiddle with a back-end MySQL database (i.e to retrieve, store, update, merge data) .

My clients are actually wireless devices (phone, pad, laptop, whatever) and they send HTTP Requests to "demo", "demo" sends forms/web pages back to the browser client for input, process it and return a HTTP Response to the URL of the sender. Both HTTP Request and Response are in XML format.

I am using XStream for my XML conversion and it seems to work fine so far on the server side. Of course currently, I am running Server-side logic and Client-side logic together when running from the same machine, like a loopback.

The idea is for the Web Service to receive any HTTP Requests coming in and sends a HTTP Response back to the URL of the sender.

In this scenario, do I need a separate web client (web application) in order to consume the "demo" Web Service running on my Tomcat?

Am I using the right approach?

Your help is and will be greatly appreciated.
10 years ago
Dear all,

(I got no response from Forums where I also posted this question)

My "demo" RESTFUL Web Service is running fine on my local Tomcat. As far as I am concerned, I can use any Browser as a client to access and consume its Services simply by specify a URL to it e.g. http://localhost/demo brings up the Home page.

Now, "demo" is running on a Tomcat in the network. I expect any browser opened up within this network to act as a Web Client simply by specifying a URL to it e.g. "http://192.168.xx.xx/demo"; or "http://192.168.xx.xx:8080/demo"; to bring up the Home page. Am I wrong?

Do I need to write a RESTFUL Web client using RestTemplate or any good old web client in order to access and consume "demo"'s Web Services? Under what circumstance do I need a separate RESTFUL web client written up as a consumer? In a Remote access situation?

As far as I am concerned, "demo" being a RESTFUL Web Service already has a Web client built in. If I send an HTTPRequest from a client machine to "demo" running in a network Tomcat, the HTTPResponse will be received by the client machine. The business logic to process this HTTPResponse message can be written inside this Web Service "demo" module as well. Am I totally confused?

Please straighten me out. I need your advice.

Many Thanks.
10 years ago
Hope this is the right forum for this question. I am new to AJAX. I dug in quite a bit trying to find a simple but complete AJAX web client project to use as a project template but to no avail.

I am using Java/Jsp in Eclipse. All I wanted to do is to be able to type an URL on a browser and see my AJAX client App's HOME page. On the HOME page, I would have a Text Box for user to put in an HTTPRequest in XML (for now) and if the SEND button is pressed, the request will be sent to a Server. When the Server sends a response in XML, the AJAX App should decode this response and put the values on a web page for display.

Very basic and simple. Code fragments did not help me in this case. Can someone please direct me as to where to get such a sample project?

Any help will be greatly appreciated.

Yes, I thought so as well. Thank you very much for the link, David. It is very helpful.
Thank you, David.

Thank you for the suggestion as well. By "serializing to XML", did you mean to read from an XML file? Probably not.

I have a whole bunch of *jspx files written up via Spring Roo as the initial program structure and I thought to stick with the *.jspx files for Views would be an easier way out. Can you please elaborate a bit on how I can do this by "serializing to XML'?

Many Thanks...Mimi