- From: <mnautiyal@hss.hns.com>
- Date: Sat, 1 Dec 2001 12:10:07 +0530
- To: www-lib@w3.org
RE: Requests to a servlet
Hello Dave,
My requirement is the similar to that of yours. I've to get the XML response
back from the
servelet I post data. I started with the post.c (sample program). It works
but with user interaction.
i.e it asks file name for saving the response. However I want the response
as in memory (or as a chunk).
I tried the solution provided by Andreas. However, the problem remains the
same. The prompt comes
for saving the response in a file. The response is correct, that I need. I
went through the library and saw
a function HTSaveLocally() (in HTFSave.c) is invoked when repsonse comes.
This function is invoked
when the MIME parser understands that the content-type is application/octet
stream or unknown encoding
is seen. Please respond and provide your comments to solve this problem.
Following is the customised post.c that I'm using.
PRIVATE int terminate_handler (HTRequest * request, HTResponse * response,
void * param, int status)
{
if (status == HT_LOADED && result && HTChunk_data(result)) {
HTPrint("---Printing response---->%s", HTChunk_data(result));
HTChunk_delete(result);
}
/* We are done with this request */
HTRequest_delete(request);
/* Terminate libwww */
HTProfile_delete();
exit(0);
}
PUBLIC HTChunk * HTPostAnchorToChunk (HTParentAnchor * source,
HTAnchor * destination,
HTRequest * request)
{
if (source && destination && request) {
HTChunk * chunk = NULL;
HTStream * target = HTStreamToChunk(request, &chunk, 0);
HTRequest_setOutputStream(request, target);
if (HTPostAnchor(source, destination, request) != NULL)
return chunk;
else {
HTChunk_delete(chunk);
return NULL;
}
}
return NULL;
}
int main (int argc, char ** argv)
{
HTRequest * request = NULL;
HTParentAnchor * src = NULL;
HTAnchor * dst = NULL;
HTAnchor * anchor = NULL;
char * dst_str = NULL;
char * data = NULL;
BOOL status = NO;
/* Initiate libwww :- Create a new premptive client */
HTProfile_newNoCacheClient("libwww-POST", "1.0");
/* Need our own trace and print functions */
HTPrint_setCallback(printer);
HTTrace_setCallback(tracer);
/* Add our own filter to update the history list */
HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
/* Handle command line args */
if (argc >= 3) {
dst_str = argv[1];
xml_data = argv[2];
} else {
HTPrint("Type the URI of the destination you want to POST to and the
contents that you w
ant to post.\n");
HTPrint("\t%s <destination> <data>\n", argv[0]);
HTPrint("For example, %s http://myserver/destination.html \"This is some
testdata\"\n",
argv[0]);
return -1;
}
if (xml_data && *xml_data && dst_str && *dst_str) {
/* Make source relative to where we are */
char * cwd = HTGetCurrentDirectoryURL();
request = HTRequest_new();
HTRequest_setOutputFormat(request, HTAtom_for("text/xml"));
anchor = HTAnchor_findAddress(dst_str);
/* dst_str is the Destination Address: http://www.xxx */
/* xml_data is the XML Data you would like to send */
src = HTTmpAnchor(NULL);
HTAnchor_setDocument(src, xml_data);
HTAnchor_setFormat(src, HTAtom_for("text/xml"));
HTAnchor_setCharset(src, HTAtom_for("UTF-8"));
HTAnchor_setLength(src, strlen(xml_data));
{
HTChunk * chunk;
char *string;
chunk = HTPostAnchorToChunk(src, anchor, request);
if (!chunk)
{
printf ("NULL Response!!\n");
}
/* If chunk != NULL then we have the data */
if (chunk) {
HTEventList_loop(request);
/* After event loop the following statements are not executed...!!!*/
string = HTChunk_toCString(chunk);
HTPrint("%s", string ? string : "no text\n");
HT_FREE(string);
}
}
}
return 0;
}
Thanks,
Manoj Nautiyal
From: Mikesell, Dave (dmikesell@cas.org)
Date: Tue, Sep 25 2001
*Next message: Jun Wang: "RE: CVS on Win98"
* Previous message: SMIGIELSKI ANDREAS: "Re: Requests to a servlet"
* Maybe in reply to: Mikesell, Dave: "Requests to a servlet"
* Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
* Other mail archives: [this mailing list] [other W3C mailing lists]
* Mail actions: [ respond to this message ] [ mail a new topic ]
------------------------------------------------------------------------
Message-ID: <117BB2BA200DD311850D0004AC66D3DE0A3B9D16@pop-server.cas.org>
From: "Mikesell, Dave" <dmikesell@cas.org>
To: "'www-lib@w3.org'" <www-lib@w3.org>
Date: Tue, 25 Sep 2001 11:10:21 -0400
Subject: RE: Requests to a servlet
Thanks to all who responded. The "missing link" in my original solution was
the call to HTRequest_setOutputStream() to catch the
response from a post.
--
Dave Mikesell
Chemical Abstracts Service
614.447.3600 x2993
> -----Original Message-----
> From: Mikesell, Dave
> Sent: Monday, September 24, 2001 10:26 AM
> To: 'www-lib@w3.org'
> Subject: Requests to a servlet
>
>
> Greetings. We have a client library written in C that
> provides access to our J2EE environment. Without going into
> to much detail, each library function causes an XML message
> to be sent over a socket to the server, which in turn parses
> the message, invokes the proper J2EE service, and then sends
> an XML response back to the client. We would like to replace
> our socket/home-grown protocol with HTTP using libwww. This
> would involve sending raw XML to a servlet and waiting for
> the servlet to send back an XML response.
>
> Is this possible using libwww? From what I can tell, the
> closest thing to what we need is HTPostFormAnchorToChunk(),
> but we don't have a "form" per se...just XML. Any insight
> would be greatly appreciated. Thank you.
>
> Dave
>
------------------------------------------------------------------------
* Next message: Jun Wang: "RE: CVS on Win98"
* Previous message: SMIGIELSKI ANDREAS: "Re: Requests to a servlet"
* Maybe in reply to: Mikesell, Dave: "Requests to a servlet"
* Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
* Other mail archives: [this mailing list] [other W3C mailing lists]
* Mail actions: [ respond to this message ] [ mail a new topic ]
Received on Saturday, 1 December 2001 01:44:03 UTC