Hi Taco,

I missed the first post of this thread - how far is it actually getting, where 
is it failing?

Cheers.

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Taco Fleur
> Sent: Monday, 20 June 2005 9:39 AM
> To: CFAussie Mailing List
> Subject: [cfaussie] Re: CFX response and [OT]
>
> Morning!
> I wish I could say it worked, but it did not, I tried another
> way, which again seems to work with the header (first 36
> chars) but as soon as I want to read the rest of the message
> it errors, I tried outputting the error but there's nothing..
>
> I'm getting desperate, something so simple (at least thats
> what I told my boss :-(
>
> import com.allaire.cfx.*;
> import java.io.*;
> import java.net.*;
>
> public class JSocketNew3 implements CustomTag {
>
>     public void processRequest( Request request, Response response )
>     throws Exception
>     {
>          // Check if all required parameters are passed to theCFX tag
>          if ( !request.attributeExists( "host" ) )
>             throw new Exception( "Missing host parameter !!!
> You must passa valid server name, containing a valid host IP
> address." );
>         if( !request.attributeExists( "port" ) )
>             throw new Exception( "Missing port parameter !!!
> You must pass a port parameter, containing a numeric port on
> the remote server" );
>         if( !request.attributeExists( "message" ) )
>             throw new Exception( "Missing message parameter
> !!! You must pass a message parameter, containing the message
> to be sent" );
>         if( !request.attributeExists( "response" ) )
>             throw new Exception( "Missing response parameter
> !!! You must pass a response parameter. This will be the cf
> variable used to write the returned message to" );
>
>         Socket Socket = null;
>         PrintWriter out = null;
>         BufferedReader in = null;
>         String returnContent = "";
>
>         //Create socket connection
>         try
>          {
>             Socket = new Socket( request.getAttribute( "host"
> ), request.getIntAttribute( "port" ) );
>             if ( request.debug() )
>             {
>                  response.writeDebug( "Socket connection
> established ..." );
>             }
>             out = new PrintWriter( Socket.getOutputStream(), true );
>             if ( request.debug() )
>             {
>                  response.writeDebug( "Writer to remote
> socket created ..." );
>             }
>             in = new BufferedReader( new InputStreamReader
> (Socket.getInputStream() ) );
>             //BufferedReader inHeader = new BufferedReader(
> new InputStreamReader( Socket.getInputStream() ), 36 );
>             if ( request.debug() )
>             {
>                  response.writeDebug( "Reader from remote
> socket created ...");
>             }
>
>             //Send data over socket
>             // Valid test message "ASPSS90 ASPSS90
> dsascot00000065YHDASCDRON     0400     9
> SHELLCO\nYRQAnythingElse     1     AL    N\nYTRENDDRON     3\n"
>             out.println( request.getAttribute( "message" ) );
>             if ( request.debug() )
>             {
>                  response.writeDebug( "Message sent to remote
> server  ..." );
>             }
>             out.flush();
>             //Receive text from server
>             if ( request.debug() )
>             {
>                  response.writeDebug( "Text from remote
> server about to be read ..." );
>             }
>             try
>               {
>                 char[] myHeader = new char[ 36 ];
>                 in.read( myHeader, 0, 36 );
>                 response.writeDebug( "Converting the header
> to a string ... " );
>                 String header = new String(myHeader);
>                 response.writeDebug( "Outputting the header:
> " + header + " ... " );
>
>                  String byteToReadString = header.substring( 28, 36 );
>                  response.writeDebug( "Getting the message
> length: " + byteToReadString + " ... " );
>                  response.writeDebug( "Parsing the string ... " );
>                  int byteToRead = Integer.parseInt(
> byteToReadString );
>
>                  char[] myMessage = new char[ byteToRead ];
>                  response.writeDebug( "Reading the rest of
> the message ... " );
>                  try
>                                {
>                       in.read( myMessage, 36, byteToRead - 10 );
>                                }
>                  catch ( Exception e )
>                                {
>                       response.writeDebug( "Error reading the
> rest of the message,
> byteToRead: " + byteToRead + " ... message: " +
> e.getMessage() + " ... " );
>                                }
>
>                  String message = new String(myMessage);
>                  response.writeDebug( "Outputting the message
> " + message + " ... " );
>
>                  response.writeDebug( message );
>
>                  in.close();
>               }
>             catch ( IOException e )
>               {
>                  response.writeDebug( "The read from the
> socket " + Socket.getPort()
> + " terminated unexpectedly ... " + e.getMessage() );
>               }
>
>             // write content to cf variable
>             try
>               {
>                  response.setVariable( "response", returnContent );
>               }
>             catch ( Exception e )
>               {
>                  response.writeDebug( "There was an error
> trying to set the return variable ..." + e.getMessage() );
>               }
>
>             if ( request.debug() )
>             {
>                  response.writeDebug( "Finished reading text
> from remote server ..." );
>                  response.writeDebug( "Content returned: " +
> returnContent );
>             }
>             // close socket
>             Socket.close();
>             if ( request.debug() )
>             {
>                  response.writeDebug( "Socket closed ..." );
>             }
>         }
>         catch ( UnknownHostException e )
>          {
>              response.writeDebug( "Unknown host ..." );
>         }
>         catch  ( IOException e )
>          {
>              response.writeDebug( "I/O Exception ..." );
>         }
>         catch ( Exception e )
>          {
>              response.writeDebug( "An exception has occurred
> ..." + e.getMessage
> () );
>         }
>     }
> }________________________________
> Taco Fleur - E-commerce Development Manager Shelco Searches &
> Services An Authorised ASIC Information Broker www.shelco.com.au
> Ph: + 61 7 3236 2605
>
>
>
> ---
> You are currently subscribed to cfaussie as:
> [EMAIL PROTECTED] To unsubscribe send a blank email to
> [EMAIL PROTECTED]
> Aussie Macromedia Developers: http://lists.daemon.com.au/
>



---
You are currently subscribed to cfaussie as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/

Reply via email to