Пример #1
0
 public String getStatusText() {
   try {
     final LocalResponse lr = this.localResponse;
     return lr == null ? null : lr.getStatusText();
   } catch (final java.io.IOException ioe) {
     return null;
   }
 }
Пример #2
0
 public int getStatus() {
   try {
     final LocalResponse lr = this.localResponse;
     return lr == null ? NetworkRequest.STATE_UNINITIALIZED : lr.getStatus();
   } catch (final java.io.IOException ioe) {
     return 0;
   }
 }
Пример #3
0
 /*
  * (non-Javadoc)
  * @see org.lobobrowser.ua.NetworkRequest#getStatusText()
  */
 @Override
 public String getStatusText() {
   try {
     LocalResponse lr = this.localResponse;
     return lr == null ? null : lr.getStatusText();
   } catch (IOException ioe) {
     return null;
   }
 }
Пример #4
0
 public Image getResponseImage() {
   final LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseImage();
 }
Пример #5
0
 public Document getResponseXML() {
   final LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseXML();
 }
Пример #6
0
 public String getResponseText() {
   final LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseText();
 }
Пример #7
0
 private void setResponse(final ClientletResponse response) {
   final Runnable runnable =
       () -> {
         if (response.isFromCache()) {
           final Object cachedResponse = response.getTransientCachedObject();
           if (cachedResponse instanceof CacheableResponse) {
             // It can be of a different type.
             final CacheableResponse cr = (CacheableResponse) cachedResponse;
             this.changeReadyState(NetworkRequest.STATE_LOADING);
             this.localResponse = cr.newLocalResponse(response);
             this.changeReadyState(NetworkRequest.STATE_LOADED);
             this.changeReadyState(NetworkRequest.STATE_INTERACTIVE);
             this.changeReadyState(NetworkRequest.STATE_COMPLETE);
             return;
           }
         }
         try {
           this.changeReadyState(NetworkRequest.STATE_LOADING);
           final LocalResponse newResponse = new LocalResponse(response);
           this.localResponse = newResponse;
           this.changeReadyState(NetworkRequest.STATE_LOADED);
           final int cl = response.getContentLength();
           final InputStream in = response.getInputStream();
           final int bufferSize = cl == -1 ? 8192 : Math.min(cl, 8192);
           final byte[] buffer = new byte[bufferSize];
           int numRead;
           int readSoFar = 0;
           boolean firstTime = true;
           final ClientletContext threadContext = ClientletAccess.getCurrentClientletContext();
           NavigatorProgressEvent prevProgress = null;
           if (threadContext != null) {
             prevProgress = threadContext.getProgressEvent();
           }
           try {
             long lastProgress = 0;
             while ((numRead = in.read(buffer)) != -1) {
               if (numRead == 0) {
                 if (logger.isLoggable(Level.INFO)) {
                   logger.info("setResponse(): Read zero bytes from " + response.getResponseURL());
                 }
                 break;
               }
               readSoFar += numRead;
               if (threadContext != null) {
                 final long currentTime = System.currentTimeMillis();
                 if ((currentTime - lastProgress) > 500) {
                   lastProgress = currentTime;
                   threadContext.setProgressEvent(
                       ProgressType.CONTENT_LOADING, readSoFar, cl, response.getResponseURL());
                 }
               }
               newResponse.writeBytes(buffer, 0, numRead);
               if (firstTime) {
                 firstTime = false;
                 this.changeReadyState(NetworkRequest.STATE_INTERACTIVE);
               }
             }
           } finally {
             if (threadContext != null) {
               threadContext.setProgressEvent(prevProgress);
             }
           }
           newResponse.setComplete(true);
           // The following should return non-null if the response is complete.
           final CacheableResponse cacheable = newResponse.getCacheableResponse();
           if (cacheable != null) {
             response.setNewTransientCachedObject(cacheable, cacheable.getEstimatedSize());
           }
           this.changeReadyState(NetworkRequest.STATE_COMPLETE);
         } catch (final IOException ioe) {
           logger.log(Level.WARNING, "setResponse()", ioe);
           this.localResponse = null;
           this.changeReadyState(NetworkRequest.STATE_COMPLETE);
         }
       };
   if (isAsynchronous) {
     // TODO: Use the JS queue to schedule this
     runnable.run();
   } else {
     runnable.run();
   }
 }
Пример #8
0
 public String getResponseHeader(final String headerName) {
   final LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseHeader(headerName);
 }
Пример #9
0
 public String getAllResponseHeaders(final List<String> excludedHeadersLowerCase) {
   final LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getAllResponseHeaders(excludedHeadersLowerCase);
 }
Пример #10
0
 public byte[] getResponseBytes() {
   final LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseBytes();
 }
Пример #11
0
 /*
  * (non-Javadoc)
  * @see org.lobobrowser.ua.NetworkRequest#getResponseText()
  */
 @Override
 public String getResponseText() {
   LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseText();
 }
Пример #12
0
 /*
  * (non-Javadoc)
  * @see org.lobobrowser.ua.NetworkRequest#getResponseHeader(java.lang.String)
  */
 @Override
 public String getResponseHeader(String headerName) {
   LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseHeader(headerName);
 }
Пример #13
0
 /*
  * (non-Javadoc)
  * @see org.lobobrowser.ua.NetworkRequest#getAllResponseHeaders()
  */
 @Override
 public String getAllResponseHeaders() {
   LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getAllResponseHeaders();
 }
Пример #14
0
 /*
  * (non-Javadoc)
  * @see org.lobobrowser.ua.NetworkRequest#getResponseBytes()
  */
 @Override
 public byte[] getResponseBytes() {
   LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseBytes();
 }
Пример #15
0
 /*
  * (non-Javadoc)
  * @see org.lobobrowser.ua.NetworkRequest#getResponseImage()
  */
 @Override
 public Image getResponseImage() {
   LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseImage();
 }
Пример #16
0
 /*
  * (non-Javadoc)
  * @see org.lobobrowser.ua.NetworkRequest#getResponseXML()
  */
 @Override
 public Document getResponseXML() {
   LocalResponse lr = this.localResponse;
   return lr == null ? null : lr.getResponseXML();
 }