@Test public void buildContentType() throws Exception { this.response.addHeader("Content-Type", "text/html; charset-UTF-8"); WebResponse webResponse = this.responseBuilder.build(); assertThat(webResponse.getContentType(), equalTo("text/html")); }
WebClient client = new WebClient(); Page page = client.getPage("http://stackoverflow.com/users/flair/97901.json"); WebResponse response = page.getWebResponse(); if (response.getContentType().equals("application/json")) { String json = response.getContentAsString(); Map<String, String> map = new Gson().fromJson(json, new TypeToken<Map<String, String>>() {}.getType()); System.out.println(map.get("displayName")); // Benju }
/** * {@inheritDoc} * The default behavior of this method is to return getContentType() on the wrapped webResponse object. */ @Override public String getContentType() { return wrappedWebResponse_.getContentType(); }
/** * {@inheritDoc} * The default behavior of this method is to return getContentType() on the wrapped connection object. */ public String getContentType() { return wrappedWebResponse_.getContentType(); }
/** * {@inheritDoc} * The default behavior of this method is to return getContentType() on the wrapped connection object. */ public String getContentType() { return wrappedWebResponse_.getContentType(); }
/** * {@inheritDoc} * The default behavior of this method is to return getContentType() on the wrapped connection object. */ public String getContentType() { return wrappedWebResponse_.getContentType(); }
/** * {@inheritDoc} * The default behavior of this method is to return getContentType() on the wrapped webResponse object. */ @Override public String getContentType() { return wrappedWebResponse_.getContentType(); }
/** * {@inheritDoc} */ @Override public String getContentType() { return getWebResponse().getContentType(); }
/** * {@inheritDoc} */ @Override public String getContentType() { return getWebResponse().getContentType(); }
/** * Returns <tt>true</tt> if the provided response is JavaScript content. This method * checks file extensions in addition to content types, because many web applications * are badly configured and have incorrect headers. * * @param webResponse the response to analyze * @return <code>true</code> if it can be considered as JavaScript */ protected boolean isJavaScript(final WebResponse webResponse) { final String contentType = webResponse.getContentType().toLowerCase(); return "text/javascript".equals(contentType) || "application/x-javascript".equals(contentType) || webResponse.getRequestSettings().getUrl().getPath().endsWith(".js"); }
private static String getSuffix(final WebResponse response) { // first try to take the one from the requested file final String url = response.getWebRequest().getUrl().toString(); final String fileName = StringUtils.substringAfterLast(StringUtils.substringBefore(url, "?"), "/"); // if there is a suffix with 2-4 letters, the take it final String suffix = StringUtils.substringAfterLast(fileName, "."); if (suffix.length() > 1 && suffix.length() < 5) { return suffix; } // use content type return MimeType.getFileExtension(response.getContentType()); }
@Override public Page createPage(WebResponse webResponse, WebWindow webWindow) throws IOException { String contentType = webResponse.getContentType().toLowerCase(Locale.ENGLISH); if(contentType.equals("application/x-java-jnlp-file")) return createXmlPage(webResponse, webWindow); return super.createPage(webResponse, webWindow); }
@Override public Page createPage(WebResponse webResponse, WebWindow webWindow) throws IOException { String contentType = webResponse.getContentType().toLowerCase(Locale.ENGLISH); if(contentType.equals("application/x-java-jnlp-file")) return createXmlPage(webResponse, webWindow); return super.createPage(webResponse, webWindow); }
@Override public Page createPage(WebResponse webResponse, WebWindow webWindow) throws IOException { String contentType = webResponse.getContentType().toLowerCase(Locale.ENGLISH); if (contentType.equals("application/x-java-jnlp-file")) { return createXmlPage(webResponse, webWindow); } return super.createPage(webResponse, webWindow); } public static final HudsonPageCreator INSTANCE = new HudsonPageCreator();
Page page = webClient.getPage(url); System.out.println(page); WebResponse response = page.getWebResponse(); if (response.getContentType().equals("application/json")) { pagesource = response.getContentAsString(); System.out.println(pagesource); }
private static String getSuffix(final WebResponse response) { // first try to take the one from the requested file final String url = response.getWebRequest().getUrl().toString(); final String fileName = StringUtils.substringAfterLast(StringUtils.substringBefore(url, "?"), "/"); // if there is a suffix with 2-4 letters, the take it final String suffix = StringUtils.substringAfterLast(fileName, "."); if (suffix.length() > 1 && suffix.length() < 5) { return suffix; } // use content type return MimeType.getFileExtension(response.getContentType()); }
public Page goTo(String relative, String expectedContentType) throws IOException, SAXException { Page p = super.getPage(getContextPath() + relative); assertEquals(expectedContentType,p.getWebResponse().getContentType()); return p; }
public Page goTo(String relative, String expectedContentType) throws IOException, SAXException { Page p = super.getPage(getContextPath() + relative); assertEquals(expectedContentType, p.getWebResponse().getContentType()); return p; }
public Page goTo(String relative, String expectedContentType) throws IOException, SAXException { Page p = super.getPage(getContextPath() + relative); assertEquals(expectedContentType,p.getWebResponse().getContentType()); return p; }
/** * Calls the wrapped webconnection and save the received response. * {@inheritDoc} */ @Override public WebResponse getResponse(final WebRequest request) throws IOException { WebResponse response = wrappedWebConnection_.getResponse(request); if (isUncompressJavaScript() && isJavaScript(response.getContentType())) { response = uncompressJavaScript(response); } saveResponse(response, request); return response; }