Re: URL problem in firmware 1.12

Technoid <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.tini
Message-ID <[email protected]>
Technoid wrote:

>  Jac Kersing wrote:
>
> > Hi,
> >
> > After questions on the JXME list I decided to run some simple tests
> > to find why JXME doesn't run on TINI. It seems to boil down to a
> > rather fatal flaw (for JXME at least) in the URL parsing for HTTP
> > connections.
> >
> > When TINI is parsing URLs the parameters for GET are being included
> > in the parsing. The parse results are unusable when the parameters
> > for the get include ':' as TINI expects to find a port number after
> > it.
> >
> > See the output and test code below.
> >
> > DalSemi, could I get a bugfix release for this issue???
> >
> > Regards,
> >
> > Jac
> >
> > Output from TINI: janeway /> java T.tini protocol: http host :
> > 
172.16.1.2:9700/unknown-unknown?2000,-1,http://172.16.1.2:9700/EndpointService
> > port : -1 file :
> > /uuid-DEADBEEFDEAFBABAFEEDBABE0000000F05/pid ref : null
> >
> > Output from PC (java 1.3.1): protocol: http host : 172.16.1.2
> > port : 9700 file :
> > 
/unknown-unknown?2000,-1,http://172.16.1.2:9700/EndpointService:jxta-NetGroup/uuid-DEADBEEFDEAFBABAFEEDBABE0000000F05/pid
> > ref : null
> >
> > The code: import java.net.URL; import
> > java.net.MalformedURLException;
> >
> > public class T {
> >
> > public static void test(String url) { try { URL u = new URL(url);
> >
> > System.out.println("protocol: "+u.getProtocol());
> > System.out.println("host : "+u.getHost());
> > System.out.println("port : "+u.getPort());
> > System.out.println("file : "+u.getFile());
> > System.out.println("ref : "+u.getRef()); } catch
> > (MalformedURLException e) { System.out.println("Exception:
> > "+e.getMessage()); e.printStackTrace(); } }
> >
> > public static void main(String[] a) {
> > 
test("http://172.16.1.2:9700/unknown-unknown?2000,-1,http://172.16.1.2:9700/EndpointService:jxta-NetGroup/uuid-DEADBEEFDEAFBABAFEEDBABE0000000F05/pid");
> > } }
> >
> >
> >
> >
>  Hi Jac,
>
>  I'm testing jxme on Tini too.The problems seem to be the
>  HttpMessenger class in the jxta-cdc.jar Like you ,i 've created a
>  work around for the parsing Url issue.I modifiied the
>  HttpMessenger.poll(int timeout, Message outgoing) method to avoid the
>  IllegalArgument Exception like this :
>
>  --------------------------- synchronized Message poll(int timeout,
>  Message outgoing) throws IOException {
>
>  //blabla 1
>
>  try {
>
>  //the HttpUrlConnection
>
>  dos = new DataOutputStream(new
>  BufferedOutputStream(conn.getOutputStream(),outgoing.getSize()));
>  //added new BufferedOutputStream // to avoid IllegalArgumentException
>  outgoing.write(dos); //begin blabla 2
>
>  if (conn.getResponseCode() != HttpURLConnection.HTTP_OK &&
>  conn.getResponseCode() != 100) { throw new IOException("HTTP Error: "
>  + conn.getResponseCode() + " " + conn.getResponseMessage()); } String
>  contentLenStr = conn.getHeaderField("Content-Length");
>  System.out.println ("Con Length: " + contentLenStr); if
>  (contentLenStr == null) { return null; } if
>  ("0".equals(contentLenStr.trim())) { return null; } //end blabla 2
>
>  dis = new DataInputStream(new
>  BufferedInputStream(conn.getInputStream())); //added new
>  BufferedInputStream // to avoid IllegalArgumentException msg =
>  Message.read(dis);
>
>  } finally { if (conn != null) { conn.disconnect(); } if (dos != null)
>  { System.out.println ("DOS Flush "); dos.flush();
>  //added dos.flush() //dos.close();
>  //added comment dos.close() : Tini issue } if (dis != null) {
>  dis.close(); } }
>
>  return msg; } ------------------------------------------------
>
>  Now , i've got another (and hopefully the last :pray: ) problem :
>
>  On the "server side" i became a HttpException like this :
>
>  POST
> 
/uuid-59616261646162614A78746150325033EABCC44012DA430AA608B27DE68F7F0F03?1,-1,http://80.x.x.x:9700/EndpointService:jxta-
>  NetGroup/uuid-DEADBEEFDEAFBABAFEEDBABE0000000F05/ HTTP/1.0
>  HttpException(400,Bad Request,Missing Content)
>
>  and on the Tini side an IOException like this :
>
>  TINI01 /JXTA> java mySend.tini -relay http://80.x.x.x:9700 relay url:
>  http://80.x.x.x:9700 Peer ID=
>  uuid-59616261646162614A787461503250337F431EE1A03E4763ACADBE79F2FB9FF603
>  create request id: 0 start polling for pipeId... Message size : 406
>  Dos size : 406 java.io.IOException: HTTP Error: 400
>  Message+was+not+a+valid+JXTA+message
>
>  or like this if i comment //blabla2
>
>  TINI01 /JXTA> java mySend.tini -relay http://80.x.x.x:9700 relay url:
>  http://80.x.x.x:9700 Peer ID=
>  uuid-59616261646162614A787461503250337F431EE1A03E4763ACADBE79F2FB9FF603
>  create request id: 0 start polling for pipeId... Message size : 406
>  Dos size : 406 java.io.IOException: Message header not found
>
>  It seems (for me) that the Message was not sent properly during the
>  POST method (note :the Tini HTTPClient only supports HTTP/1.0,could
>  it be a problem for the JxtaProxy ??) I'am running Tini1.11 (i can't
>  change to tini1.12 for the moment,remote lab location) and the
>  JxtaProxy is running on a Mandrake linux 9.1 box (JxtaApps : myJxta
>  InstantP2P JXTA version 2.1.1_00 09/15/03)
>
>  Any idea to avoid the IOException ?? Maybe, Tini1.12 solves this
>  IOException problem (tell me if it does)?? Is there another solution
>  to change the whole Messenger.poll() method , because
>  BufferedOutputStream/BufferedInputStream changes increase the
>  execution time (around 40-70s before having the java.io.IOException
>  on the Tini) ??
>
>  At least,is it possible to have a Tini HTTPClient supporting HTTP/1.1
>  ??
>
>  Best regards.
>
>  Hans
>
>  P.S ; I read on the jxta-discuss mailing list that someone wants to
>  make a Tini native jxme Proxyless version (cf :
>  http://jacknet.jxta.org/ )
>
>  _______________________________________________ TINI mailing list
>  TINI-6tN4nzCoH/[email protected] To UNSUBSCRIBE, edit your profile, or see list
>  archives: http://lists.dalsemi.com/mailman/listinfo/tini
>
Hi again,

Forget my last message (i made some mistakes), it works now :) below  
the code i'm using for the HttpMessenger.poll() method :

synchronized Message poll(int timeout, Message outgoing)
        throws IOException {

        Message msg = null;
        HttpURLConnection conn = null;
        DataInputStream dis = null;
        DataOutputStream dos = null;   
       URL relay = null;

 try {
            relay = constructURL (relayUrl, "", timeout, peerId);

            conn = (HttpURLConnection) relay.openConnection();
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setRequestMethod("POST");
            conn.setAllowUserInteraction(false);
            conn.setRequestProperty("Connection", "keep-alive");       
            conn.setUseCaches(false);
            
conn.setRequestProperty("Content-Length",Integer.toString(outgoing.getSize()));
            //System.out.println ("Message size : " +outgoing.getSize());
       
           //added new BufferedOutputStream to avoid 
IllegalArgumentException for TINI

            dos = new DataOutputStream(new 
BufferedOutputStream(conn.getOutputStream()));       
            outgoing.write(dos);
            //System.out.println ("Dos size : " +dos.size());
            
            // System.out.println ("DOS Flush ");
            
            dos.flush();                                           
//added for TINI

            if (conn.getResponseCode() != HttpURLConnection.HTTP_OK &&
                conn.getResponseCode() != 100) {
                throw new IOException("HTTP Error: " +
                                       conn.getResponseCode() + " " +
                                       conn.getResponseMessage());
            }

           if (conn.getResponseCode() != HttpURLConnection.HTTP_OK &&
                conn.getResponseCode() != 100) {
                throw new IOException("HTTP Error: " +
                                       conn.getResponseCode() + " " +
                                       conn.getResponseMessage());
            }
            String contentLenStr = conn.getHeaderField("Content-Length");
            //System.out.println ("Con Length: " + contentLenStr);
       
            if (contentLenStr == null) {
                return null;
            }
            if ("0".equals(contentLenStr.trim())) {
                return null;
            }

             //added new  BufferedInputStream to avoid 
IllegalArgumentException for TINI  
          
           dis = new DataInputStream(new 
BufferedInputStream(conn.getInputStream()));

           msg = Message.read(dis);

           } finally {
             if (conn != null) {
                conn.disconnect();
            }
            if (dos != null) {
           
                dos.close();                                          
//not an Issue for tini1.11
            }
            if (dis != null) {
                dis.close();
            }
        }

        return msg;
    }
}

_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.