Examples of MimeParser


Examples of org.w3c.www.mime.MimeParser

    {
  if ( debug )
      System.out.println(conn+": runs[11] "+request.getURL());
  RequestObserver o  = request.getObserver();
  OutputStream os    = conn.getOutputStream();
  MimeParser   p     = conn.getParser();
  Reply        reply = null;
  boolean      needsChunk = false;

  if (request.hasOutputStream()) {
      if (request.getContentLength() < 0 ) {
    needsChunk = true;
    String tes[] = request.getTransferEncoding();
    if (tes == null) {
        // FIXME intern this
        request.addTransferEncoding("chunked");
    } else {
        boolean addIt = true;
        for (int i=0; !addIt && (i < tes.length); i++) {
      addIt = addIt && !tes[i].equals("chunked");
        }
        if (addIt) {
      // FIXME intern this
                        request.addTransferEncoding("chunked");
        } else {
      if (os instanceof ChunkedOutputStream) {
          needsChunk = false;
      }
        }
    }
      }  
  }

  try {
      request.emit(os, Request.EMIT_HEADERS);
      os.flush();
      if (o != null) {
    notifyObserver(o, new ConnectedEvent(this, request, os));
      }
      // We don't expect a "100-continue" so let's dump the body
      // If any...
      if ( request.hasOutputStream() ) {
    String       exp   = request.getExpect();
    if ((exp != null) && (exp.equalsIgnoreCase("100-continue"))) {
        if ( o != null) {
      // client is expecting a 100 continue let's fake one
      notifyObserver(o, new ContinueEvent(this, request));
        }
    }
    if (needsChunk) {
        DataOutputStream dos = new DataOutputStream(os);
        ChunkedOutputStream cos = new ChunkedOutputStream(dos);
        request.emit(cos, Request.EMIT_BODY);
        cos.flush();
        cos.close(false);
        request.emit(os,Request.EMIT_FOOTERS);
    } else {
        request.emit(os,Request.EMIT_BODY|Request.EMIT_FOOTERS);
    }
    os.flush();
      }
      reply = (Reply) p.parse(manager.isLenient());
      // "eat" the 100 replies FIXME it indicates an error in
      // the upstream server
      while ((reply.getStatus() / 100) == 1 ) {
    if (o != null) {
        notifyObserver(o, new ContinueEvent(this, request, reply));
    }
    reply = (Reply) p.parse(manager.isLenient());
      }
  } catch (MimeParserException ex) {
      return null;
  } catch (IOException ioex) {
      return null;
View Full Code Here

Examples of org.w3c.www.mime.MimeParser

    {
  if ( debug )
      System.out.println(conn+": runs[11ts] "+request.getURL());
  RequestObserver o  = request.getObserver();
  OutputStream os    = conn.getOutputStream();
  MimeParser   p     = conn.getParser();
  Reply        reply = null;
  boolean needsChunk = false;
 
  if (request.getContentLength() < 0 ) {
      needsChunk = true;
      String tes[] = request.getTransferEncoding();
      if (tes == null) {
    request.addTransferEncoding("chunked"); // FIXME intern this
      } else {
    boolean addIt = true;
    for (int i=0; !addIt && (i < tes.length); i++) {
        addIt = addIt && !tes[i].equals("chunked");
    }
    if (addIt) {
        // FIXME intern thi
        request.addTransferEncoding("chunked");
    } else {
        if (os instanceof ChunkedOutputStream) {
      needsChunk = false;
        }
    }
      }
  }
 
  try {
      request.emit(os, Request.EMIT_HEADERS);
      os.flush();
      if ( o != null )
    notifyObserver(o, new ConnectedEvent(this, request, os));
      reply = (Reply) p.parse(manager.isLenient());
     
      boolean bodySent = false;
      while ((reply.getStatus() / 100) == 1 ||
       reply.getStatus() == HTTP.EXPECTATION_FAILED) {
    if (reply.getStatus() == HTTP.EXPECTATION_FAILED)
        return reply; // FIXME observer?
    reply = null;
    // Notify the observer if any:
    if ( o != null ) {
        notifyObserver(o, new ContinueEvent(this, request, reply));
    }
    // Finish the request normally:
    if (!bodySent) {
        bodySent = true;
        if (needsChunk) {
      DataOutputStream dos = new DataOutputStream(os);
      ChunkedOutputStream cos = new ChunkedOutputStream(dos);
      request.emit(cos, Request.EMIT_BODY);
      cos.flush();
      cos.close(false);
      request.emit(os,Request.EMIT_FOOTERS);
        } else {
      request.emit(os,
             Request.EMIT_BODY|Request.EMIT_FOOTERS);
        }
        os.flush();
    }
    reply = (Reply) p.parse(manager.isLenient());
    // if we don't have any observer, eat the 100 continue!
    while ((reply.getStatus() / 100) == 1 ) {
        if (o != null) {
      notifyObserver(o,
                    new ContinueEvent(this, request, reply));
        }
        reply = (Reply) p.parse(manager.isLenient());
    }
      }
  } catch (MimeParserException ex) {
      return null;
  } catch (IOException ieox) {
View Full Code Here

Examples of org.w3c.www.mime.MimeParser

    {
  if ( debug )
      System.out.println(conn+": runs[10_ka] "+request.getURL());
  RequestObserver o  = request.getObserver();
  OutputStream os    = conn.getOutputStream();
  MimeParser   p     = conn.getParser();
  Reply        reply = null;
  String       exp   = request.getExpect();

  if ((exp != null) && (exp.equalsIgnoreCase("100-continue"))) {
      reply = request.makeReply(HTTP.EXPECTATION_FAILED);
      reply.setContent("100-continue is not supported by upstream "
           + "HTTP/1.0 Server");
      return reply;
  }
  if (request.getConnection() == null) {
      if ( request.hasProxy() ) {
    request.addProxyConnection("Keep-Alive");
      } else {
    request.addConnection("Keep-Alive");
      }
  }
  try {
      request.emit(os, Request.EMIT_HEADERS);
      os.flush();
  } catch (IOException ioex) {
      return null;
  }
  if ( o != null )
      notifyObserver(o, new ConnectedEvent(this, request, os));
  // If this is a two stage method, emit a fake continue event:
  if ( isTwoStage_10(request) ) {
      if ( o != null )
    notifyObserver(o, new ContinueEvent(this, request));
      request.emit(os, Request.EMIT_BODY|Request.EMIT_FOOTERS);
      os.flush();
  }
  try {
      reply = (Reply) p.parse(manager.isLenient());
      // if ever we switch to 1.1 in the meantime...
      while ((reply.getStatus() / 100) == 1 ) {
    if (o != null) {
        notifyObserver(o, new ContinueEvent(this, request, reply));
    }
    reply = null;
    reply = (Reply) p.parse(manager.isLenient());
      }
  } catch (IOException ex) {
      // at this point, we try to parse the reply if we have a body
      if (isTwoStage_10(request)) {
    try {
        reply = (Reply) p.parse(manager.isLenient());
    } catch (MimeParserException mex) {
        // a stale connection?
        return null;
    }
    try {
View Full Code Here

Examples of org.w3c.www.mime.MimeParser

    {
  if ( debug )
      System.out.println(conn+": runs[10] "+request.getURL());
  RequestObserver o  = request.getObserver();
  OutputStream os    = conn.getOutputStream();
  MimeParser   p     = conn.getParser();
  Reply        reply = null;
  String       exp   = request.getExpect();

  if ((exp != null) && (exp.equalsIgnoreCase("100-continue"))) {
      reply = request.makeReply(HTTP.EXPECTATION_FAILED);
      reply.setContent("100-continue is not supported by upstream "
           + "HTTP/1.0 Server");
      return reply;
  }
  // Emit the request headers:
  request.emit(os, Request.EMIT_HEADERS);
  os.flush();
  if ( o != null ) {
      notifyObserver(o, new ConnectedEvent(this, request, os));
      // If this is a two stage method, emit a fake continue event:
      if ( isTwoStage_10(request) )
    notifyObserver(o, new ContinueEvent(this, request));
  }
  // Then emit the body:
  try {
      request.emit(os, Request.EMIT_BODY|Request.EMIT_FOOTERS);
      os.flush();
  } catch (IOException ex) {
      // at this point, we try to parse the reply if we have a body
      if (isTwoStage_10(request)) {
    try {
        reply = (Reply) p.parse(manager.isLenient());
    } catch (MimeParserException mex) {
        // perhaps nothing so...
        throw ex;
    }
    if (reply != null) {
                    // close the request stream
        try {
      request.getOutputStream().close();
        } catch (Exception cex) {};
        return reply;
    }
      }
      // no reply throw the exception again
      throw ex;
  }
  // HTTP 100 status codes *are* forbidden here, unless the server
  // switches...
  try {
      reply = (Reply) p.parse(manager.isLenient());
      while ((reply.getStatus() / 100) == 1 ) {
    if (o != null) {
        notifyObserver(o, new ContinueEvent(this, request, reply));
    }
    reply = null;
    reply = (Reply) p.parse(manager.isLenient());
      }
  } catch (MimeParserException ex) {
      // be nice to lamers
  }
  conn.setCloseOnEOF(true);
View Full Code Here

Examples of org.w3c.www.mime.MimeParser

  // then issue the request if it's ok. (expect 100 continue with
  // a timeout?
  // Emit the request:
  RequestObserver o  = request.getObserver();
  OutputStream os    = conn.getOutputStream();
  MimeParser   p     = conn.getParser();
  Reply        reply = null;
  // Emit the request headers:
  request.emit(os, Request.EMIT_HEADERS);
  if ( o != null ) {
      notifyObserver(o, new ConnectedEvent(this, request, os));
      // If this is a two stage method, try to be nice:
      if ( isTwoStage_10(request) ) {
    // Always emit a fake continue event:
    eventfaked = true;
    notifyObserver(o, new ContinueEvent(this, request));
      }
  }
  // Then emit the body:
  try {
      request.emit(os, Request.EMIT_BODY|Request.EMIT_FOOTERS);
      os.flush();
  } catch (IOException ex) {
      // at this point, we try to parse the reply if we have a body
      if (isTwoStage_10(request)) {
    try {
        reply = (Reply) p.parse(manager.isLenient());
    } catch (MimeParserException mex) {
        // perhaps nothing so...
        throw ex;
    }
    if (reply != null) {
                    // close the request stream
        try {
      request.getOutputStream().close();
        } catch (Exception cex) {};
        return reply;
    }
      }
      // no reply throw the exception again
      throw ex;
  }
  try {
      reply = (Reply) p.parse(manager.isLenient());
      while ((reply.getStatus() / 100) == 1) {
    // If we already faked an event, skip that one:
    if ( eventfaked ) {
        eventfaked = false;
        continue;
    }
    // Notify the observer, if any:
    if ( o != null )
        notifyObserver(o, new ContinueEvent(this, request, reply));
    // Get next reply:
    reply = (Reply) p.parse(manager.isLenient());
      }
      // Now, we know about that server, update infos:
      if ( reply != null ) {
    updateServerInfo(reply);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.