Package org.browsermob.core.har

Examples of org.browsermob.core.har.HarNameValuePair


  public List<HarCookie> getCookies(HttpRequest request) {
    List<HarCookie> cookies = newLinkedList();
    for(Header hdr : request.getHeaders("Cookie")) {
      String[] pairs = hdr.getValue().split("; ")
      for (String p : pairs) {
        HarNameValuePair pair = nameValuePair(p);
        HarCookie cookie = new HarCookie();
        cookie.setName(pair.getName());
        cookie.setValue(pair.getValue());
        cookies.add(cookie);
      }
    }
    return cookies;
  }
View Full Code Here


    return cookies;
  }
 
  private Map<String, String> parseSetCookieHeader(Header setCookieHdr) {
    String[] pairs= setCookieHdr.getValue().split("; ");
      HarNameValuePair pair = nameValuePair(pairs[0]);
     
      Map<String, String> cookieData = newHashMap();
      cookieData.put("name", pair.getName());
      cookieData.put("value", pair.getValue());
     
      for (int i = 1; i < pairs.length; i++) {
        pair = nameValuePair(pairs[i]);
          cookieData.put(pair.getName(), pair.getValue());
      }     
      return cookieData;
  }
View Full Code Here

  private HarNameValuePair nameValuePair(String data) {
    int eqIdx = data.indexOf("=");
    if (eqIdx > 0) {
      String name = data.substring(0, eqIdx);
      String val = data.substring(eqIdx + 1);
      return new HarNameValuePair(name, val);
    }
    else return new HarNameValuePair(data, "");
  }
View Full Code Here

    public List<HarCookie> getCookies(HttpRequest request) {
        List<HarCookie> cookies = newLinkedList();
        for(Header hdr : request.getHeaders("Cookie")) {
            String[] pairs = hdr.getValue().split("; ");
            for (String p : pairs) {
                HarNameValuePair pair = nameValuePair(p);
                HarCookie cookie = new HarCookie();
                cookie.setName(pair.getName());
                cookie.setValue(pair.getValue());
                cookies.add(cookie);
            }
        }
        return cookies;
    }
View Full Code Here

    private HarNameValuePair nameValuePair(String data) {
        int eqIdx = data.indexOf("=");
        if (eqIdx > 0) {
            String name = data.substring(0, eqIdx);
            String val = data.substring(eqIdx + 1);
            return new HarNameValuePair(name, val);
        }
        else return new HarNameValuePair(data, "");
    }
View Full Code Here

      if (query != null) {
          MultiMap<String> params = new MultiMap<String>();
          UrlEncoded.decodeTo(query, params, "UTF-8");
          for (String k : params.keySet()) {
            for (Object v : params.getValues(k)) {
              entry.getRequest().getQueryString().add(new HarNameValuePair(k, (String) v));
            }
          }
        }

        String errorMessage = null;
        HttpResponse response = null;

        BasicHttpContext ctx = new BasicHttpContext();

        ActiveRequest activeRequest = new ActiveRequest(method, ctx, entry.getStartedDateTime());
        synchronized (activeRequests) {
            activeRequests.add(activeRequest);
        }

        // for dealing with automatic authentication
        if (authType == AuthType.NTLM) {
            // todo: not supported yet
            //ctx.setAttribute("preemptive-auth", new NTLMScheme(new JCIFSEngine()));
        } else if (authType == AuthType.BASIC) {
            ctx.setAttribute("preemptive-auth", new BasicScheme());
        }

        StatusLine statusLine = null;
        try {
            // set the User-Agent if it's not already set
            if (method.getHeaders("User-Agent").length == 0) {
                method.addHeader("User-Agent", "BrowserMob VU/1.0");
            }

            // was the request mocked out?
            if (mockResponseCode != -1) {
                statusCode = mockResponseCode;

                // TODO: HACKY!!
                callback.handleHeaders(new Header[]{
                        new Header(){
                            @Override
                            public String getName() {
                                return "Content-Type";
                            }

                            @Override
                            public String getValue() {
                                return "text/plain";
                            }

                            @Override
                            public HeaderElement[] getElements() throws ParseException {
                                return new HeaderElement[0];
                            }
                        }
                });
            } else {
                response = httpClient.execute(method, ctx);
                statusLine = response.getStatusLine();
                statusCode = statusLine.getStatusCode();

                if (callback != null) {
                    callback.handleStatusLine(statusLine);
                    callback.handleHeaders(response.getAllHeaders());
                }

                if (response.getEntity() != null) {
                    is = response.getEntity().getContent();
                }

                // check for null (resp 204 can cause HttpClient to return null, which is what Google does with http://clients1.google.com/generate_204)
                if (is != null) {
                    // deal with GZIP content!
                    if (decompress) {
                        Header contentEncodingHeader = response.getFirstHeader("Content-Encoding");
                        if (contentEncodingHeader != null && "gzip".equalsIgnoreCase(contentEncodingHeader.getValue())) {
                            is = new GZIPInputStream(is);
                        }
                    }

                    bytes = copyWithStats(is, os);
                }
            }
        } catch (Exception e) {
            errorMessage = e.toString();

            if (callback != null) {
                callback.reportError(e);
            }

            // only log it if we're not shutdown (otherwise, errors that happen during a shutdown can likely be ignored)
            if (!shutdown) {
                LOG.info(String.format("%s when requesting %s", errorMessage, url));
            }
        } finally {
            // the request is done, get it out of here
            synchronized (activeRequests) {
                activeRequests.remove(activeRequest);
            }

            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // this is OK to ignore
                }
            }
        }

        // record the response as ended
        RequestInfo.get().finish();

        // set the start time and other timings
        entry.setStartedDateTime(RequestInfo.get().getStart());
        entry.setTimings(RequestInfo.get().getTimings());
        entry.setServerIPAddress(RequestInfo.get().getResolvedAddress());
        entry.setTime(RequestInfo.get().getTotalTime());

        // todo: where you store this in HAR?
        // obj.setErrorMessage(errorMessage);
        entry.getResponse().setBodySize(bytes);
        entry.getResponse().getContent().setSize(bytes);
        entry.getResponse().setStatus(statusCode);
        if (statusLine != null) {
            entry.getResponse().setStatusText(statusLine.getReasonPhrase());
        }

        boolean urlEncoded = false;
        if (captureHeaders || captureContent) {
            for (Header header : method.getAllHeaders()) {
                if (header.getValue() != null && header.getValue().startsWith(URLEncodedUtils.CONTENT_TYPE)) {
                    urlEncoded = true;
                }

                entry.getRequest().getHeaders().add(new HarNameValuePair(header.getName(), header.getValue()));
            }

            if (response != null) {
                for (Header header : response.getAllHeaders()) {
                    entry.getResponse().getHeaders().add(new HarNameValuePair(header.getName(), header.getValue()));
                }
            }
        }

        /* TODO
 
View Full Code Here

TOP

Related Classes of org.browsermob.core.har.HarNameValuePair

Copyright © 2018 www.massapicom. 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.