http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1345

*** shadow/1345 Mon Apr 16 12:13:42 2001
--- shadow/1345.tmp.5842        Mon Apr 16 12:13:42 2001
***************
*** 0 ****
--- 1,233 ----
+ +============================================================================+
+ | BinHTTPURLInputStream ignoring query params                                |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1345                        Product: Xerces-C                |
+ |       Status: NEW                         Version: 1.4                     |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Normal                   OS/Version: Windows NT/2K           |
+ |     Priority: Medium                    Component: Utilities               |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: [EMAIL PROTECTED]                                  |
+ |  Reported By: [EMAIL PROTECTED]                                         |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ I was having difficulty submitting input data to servlets(CGI) through Xerces 
+ BinHTTPURLInputStream's readBytes method.  Fetching the output
+ worked fine but none of the parameters were being passed to
+ the servlet(CGI).
+ 
+ I have made a modification to the code - as far as I can tell it
+ simply ignores the query elements that are stored within the XMLURL object
+ it is passed during the call to the BinHTTPURLInputStream constructor.
+ 
+ Here is code I added to make it work.
+ 
+     //start of constructor.
+     const XMLCh*        query = urlSource.getQuery();
+     char*               queryAsCharStar = XMLString::transcode(query);
+     ArrayJanitor<char>  janBuf4(queryAsCharStar);
+ 
+     //after adding path to fBuffer string.
+ 
+     if(queryAsCharStar && strlen(queryAsCharStar) >0) {
+               
+       strcat(fBuffer,"?");
+       strcat(fBuffer,queryAsCharStar);
+ 
+     }
+ 
+ 
+ Here is entire Function code for clarity :
+ 
+ BinHTTPURLInputStream::BinHTTPURLInputStream(const XMLURL& urlSource)
+       : fSocketHandle(0)
+       , fBytesProcessed(0)
+ {
+       if(!fInitialized) 
+       {
+               Initialize();
+       }
+ 
+     //
+     // Pull all of the parts of the URL out of th urlSource object, and 
+ transcode them
+     //   and transcode them back to ASCII.
+     //
+     const XMLCh*        hostName = urlSource.getHost();
+     char*               hostNameAsCharStar = XMLString::transcode(hostName);
+     ArrayJanitor<char>  janBuf1(hostNameAsCharStar);
+ 
+     const XMLCh*        path = urlSource.getPath();
+     char*               pathAsCharStar = XMLString::transcode(path);
+     ArrayJanitor<char>  janBuf2(pathAsCharStar);
+ 
+     const XMLCh*        fragment = urlSource.getFragment();
+     char*               fragmentAsCharStar = 0;
+     if (fragment)
+         fragmentAsCharStar = XMLString::transcode(fragment);
+     ArrayJanitor<char>  janBuf3(fragmentAsCharStar);
+ 
+ // new code to fix query params problem :begin
+     const XMLCh*        query = urlSource.getQuery();
+     char*               queryAsCharStar = XMLString::transcode(query);
+     ArrayJanitor<char>  janBuf4(queryAsCharStar);
+ // new code to fix query params problem :end
+ 
+     unsigned short      portNumber = (unsigned short) urlSource.getPortNum();
+ 
+     //
+     // Set up a socket.
+     //
+     struct hostent*     hostEntPtr = 0;
+     struct sockaddr_in  sa;
+ 
+ 
+     if ((hostEntPtr = gethostbyname(hostNameAsCharStar)) == NULL)
+     {
+         unsigned long  numAddress = inet_addr(hostNameAsCharStar);
+         if (numAddress == INADDR_NONE)
+         {
+             // Call WSAGetLastError() to get the error number.
+             ThrowXML(NetAccessorException,
+                      XMLExcepts::NetAcc_TargetResolution);
+         }
+         if ((hostEntPtr = 
+                 gethostbyaddr((const char *) &numAddress, 
+                               sizeof(unsigned long), AF_INET)) == NULL)
+         {
+             // Call WSAGetLastError() to get the error number.
+             ThrowXML(NetAccessorException,
+                      XMLExcepts::NetAcc_TargetResolution);
+         }
+     }
+ 
+     memcpy((void *) &sa.sin_addr,
+            (const void *) hostEntPtr->h_addr, hostEntPtr->h_length);
+     sa.sin_family = hostEntPtr->h_addrtype;
+     sa.sin_port = htons(portNumber);
+ 
+     SOCKET s = socket(hostEntPtr->h_addrtype, SOCK_STREAM, 0);
+     if (s == INVALID_SOCKET)
+     {
+         // Call WSAGetLastError() to get the error number.
+         ThrowXML(NetAccessorException,
+                  XMLExcepts::NetAcc_CreateSocket);
+     }
+ 
+     if (connect(s, (struct sockaddr *) &sa, sizeof(sa)) == SOCKET_ERROR)
+     {
+         // Call WSAGetLastError() to get the error number.
+         ThrowXML(NetAccessorException,
+                  XMLExcepts::NetAcc_ConnSocket);
+     }
+ 
+ 
+     // The port is open and ready to go.
+     // Build up the http GET command to send to the server.
+     // To do:  We should really support http 1.1.  This implementation
+     //         is weak.
+       memset(fBuffer,'\0',sizeof(fBuffer));
+ 
+     strcpy(fBuffer, "GET ");
+     strcat(fBuffer, pathAsCharStar);
+ // new code to fix query params problem :begin
+       if(queryAsCharStar && strlen(queryAsCharStar) >0) {
+               
+               strcat(fBuffer,"?");
+               strcat(fBuffer,queryAsCharStar);
+ 
+       }
+ // new code to fix query params problem :end
+ 
+     if (fragmentAsCharStar != 0)
+     {
+         strcat(fBuffer, fragmentAsCharStar);
+     }
+     strcat(fBuffer, " HTTP/1.0\r\n");
+ 
+ 
+     strcat(fBuffer, "Host: ");
+     strcat(fBuffer, hostNameAsCharStar);
+     if (portNumber != 80)
+     {
+         int i = strlen(fBuffer);
+         _itoa(portNumber, fBuffer+i, 10);
+     }
+     strcat(fBuffer, "\r\n\r\n");
+ 
+     // Send the http request
+     int lent = strlen(fBuffer);
+     int  aLent = 0;
+       
+     if ((aLent = send(s, fBuffer, lent, 0)) != lent)
+     {
+         // Call WSAGetLastError() to get the error number.
+         ThrowXML(NetAccessorException,
+                  XMLExcepts::NetAcc_WriteSocket);
+     }
+ 
+ 
+     //
+     // get the response, check the http header for errors from the server.
+     //
+       memset(fBuffer,'\0',sizeof(fBuffer));
+     aLent = recv(s, fBuffer, sizeof(fBuffer)-1, 0);
+     if (aLent == SOCKET_ERROR || aLent == 0)
+     {
+         // Call WSAGetLastError() to get the error number.
+         ThrowXML(NetAccessorException, XMLExcepts::NetAcc_ReadSocket);
+     }
+ 
+     fBufferEnd = fBuffer+aLent;
+     *fBufferEnd = 0;
+ 
+     // Find the break between the returned http header and any data.
+     //  (Delimited by a blank line)
+     // Hang on to any data for use by the first read from this 
+ BinHTTPURLInputStream.
+     //
+     fBufferPos = strstr(fBuffer, "\r\n\r\n");
+     if (fBufferPos != 0)
+     {
+         fBufferPos += 4;
+         *(fBufferPos-2) = 0;
+     }
+     else
+     {
+         fBufferPos = strstr(fBuffer, "\n\n");
+         if (fBufferPos != 0)
+         {
+             fBufferPos += 2;
+             *(fBufferPos-1) = 0;
+         }
+         else
+             fBufferPos = fBufferEnd;
+     }
+ 
+     // Make sure the header includes an HTTP 200 OK response.
+     //
+     char *p = strstr(fBuffer, "HTTP");
+     if (p == 0) 
+     {
+         ThrowXML(NetAccessorException, XMLExcepts::NetAcc_ReadSocket);
+     }
+ 
+     p = strchr(p, ' ');
+     if (p == 0) 
+     {
+         ThrowXML(NetAccessorException, XMLExcepts::NetAcc_ReadSocket);
+     }
+     
+     int httpResponse = atoi(p);
+     if (httpResponse != 200)
+     {
+         // Most likely a 404 Not Found error.
+         //   Should recognize and handle the forwarding responses.
+         //
+         ThrowXML(NetAccessorException, XMLExcepts::File_CouldNotOpenFile);
+     }
+ 
+     fSocketHandle = (unsigned int) s;
+ }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to