本文将为您提供关于com.sun.jersey.api.client.WebResource的实例源码的详细介绍,我们还将为您解释jasperreport源码解读的相关知识,同时,我们还将为您提供关于
本文将为您提供关于com.sun.jersey.api.client.WebResource的实例源码的详细介绍,我们还将为您解释jasperreport源码解读的相关知识,同时,我们还将为您提供关于android.webkit.WebResourceResponse的实例源码、com.google.gwt.user.client.ui.ImageResourceRenderer的实例源码、com.google.gwt.user.client.ui.SourcesMouseEvents的实例源码、com.google.gwt.user.client.ui.SourcesTabEvents的实例源码的实用信息。
本文目录一览:- com.sun.jersey.api.client.WebResource的实例源码(jasperreport源码解读)
- android.webkit.WebResourceResponse的实例源码
- com.google.gwt.user.client.ui.ImageResourceRenderer的实例源码
- com.google.gwt.user.client.ui.SourcesMouseEvents的实例源码
- com.google.gwt.user.client.ui.SourcesTabEvents的实例源码
com.sun.jersey.api.client.WebResource的实例源码(jasperreport源码解读)
@Test public void testJobsQueryStateNone() throws JSONException,Exception { WebResource r = resource(); ArrayList<JobState> JOB_STATES = new ArrayList<JobState>(Arrays.asList(JobState.values())); // find a state that isn't in use Map<JobId,Job> jobsMap = appContext.getAllJobs(); for (Map.Entry<JobId,Job> entry : jobsMap.entrySet()) { JOB_STATES.remove(entry.getValue().getState()); } assertTrue("No unused job states",JOB_STATES.size() > 0); JobState notinUse = JOB_STATES.get(0); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").queryParam("state",notinUse.toString()) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements",1,json.length()); assertEquals("jobs is not null",JSONObject.NULL,json.get("jobs")); }
@Test public void testTaskIdSlash() throws JSONException,Exception { WebResource r = resource(); Map<JobId,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).path("tasks").path(tid + "/") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements",json.length()); JSONObject info = json.getJSONObject("task"); verifyAMSingleTask(info,task); } } }
@Test public void testCreate() throws Exception { String path = "/"; String name = "roottest-create"; byte[] data = "foo".getBytes(); WebResource wr = znodesr.path(path).queryParam("dataformat","utf8") .queryParam("name",name); Builder builder = wr.accept(MediaType.APPLICATION_JSON); ClientResponse cr; cr = builder.post(ClientResponse.class,data); Assert.assertEquals(ClientResponse.Status.CREATED,cr.getClientResponseStatus()); ZPath zpath = cr.getEntity(ZPath.class); Assert.assertEquals(new ZPath(path + name),zpath); Assert.assertEquals(znodesr.path(path).toString(),zpath.uri); // use out-of-band method to verify byte[] rdata = zk.getData(zpath.path,false,new Stat()); Assert.assertTrue(new String(rdata) + " == " + new String(data),Arrays.equals(rdata,data)); }
@Test public void testFromTs() throws Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("timeline") .path("type_1").queryParam("fromTs",Long.toString(beforeTime)) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); assertEquals(0,response.getEntity(TimelineEntities.class).getEntities() .size()); response = r.path("ws").path("v1").path("timeline") .path("type_1").queryParam("fromTs",Long.toString( System.currentTimeMillis())) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); assertEquals(3,response.getEntity(TimelineEntities.class).getEntities() .size()); }
@Test public void testSendHeartbeat() throws InterruptedException { ZSession session = createSession("2"); Thread.sleep(1000); WebResource wr = sessionsr.path(session.id); Builder b = wr.accept(MediaType.APPLICATION_JSON); ClientResponse cr = b.put(ClientResponse.class,null); assertEquals(ClientResponse.Status.OK,cr.getClientResponseStatus()); Thread.sleep(1500); assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH,session.id)); Thread.sleep(1000); assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH,session.id)); }
@Test public void testCreate() throws Exception { LOG.info("STARTING " + getName()); String path = "/"; String name = "roottest-create"; byte[] data = "foo".getBytes(); WebResource wr = znodesr.path(path).queryParam("dataformat",data); assertEquals(ClientResponse.Status.CREATED,cr.getClientResponseStatus()); ZPath zpath = cr.getEntity(ZPath.class); assertEquals(new ZPath(path + name),zpath); assertEquals(znodesr.path(path).toString(),new Stat()); assertTrue(new String(rdata) + " == " + new String(data),data)); }
@Test public void testNodeAppsstate() throws JSONException,Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(),app); addAppContainers(app); MockApp app2 = new MockApp("foo",1234,2); nmContext.getApplications().put(app2.getAppId(),app2); HashMap<String,String> hash2 = addAppContainers(app2); app2.setState(ApplicationState.RUNNING); ClientResponse response = r.path("ws").path("v1").path("node").path("apps") .queryParam("state",ApplicationState.RUNNING.toString()) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject json = response.getEntity(JSONObject.class); JSONObject info = json.getJSONObject("apps"); assertEquals("incorrect number of elements",info.length()); JSONArray appInfo = info.getJSONArray("app"); assertEquals("incorrect number of elements",appInfo.length()); verifyNodeAppInfo(appInfo.getJSONObject(0),app2,hash2); }
@Test public void testInvalidAttempt() { ApplicationId appId = ApplicationId.newInstance(0,1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId,MAX_APPS + 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()).path("appattempts") .path(appAttemptId.toString()) .queryParam("user.name",USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); if (round == 1) { assertEquals(Status.FORBIDDEN,response.getClientResponseStatus()); return; } assertEquals("404 not found expected",Status.NOT_FOUND,response.getClientResponseStatus()); }
@Test public void testTaskIdCounters() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).path("tasks").path(tid).path("counters") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,json.length()); JSONObject info = json.getJSONObject("jobTaskCounters"); verifyAMJobTaskCounters(info,task); } } }
@Test public void testNonexistNodeDefault() throws JSONException,Exception { rm.registerNode("h1:1234",5120); rm.registerNode("h2:1235",5121); WebResource r = resource(); try { r.path("ws").path("v1").path("cluster").path("nodes") .path("node_invalid:99").get(JSONObject.class); fail("should have thrown exception on non-existent nodeid"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.NOT_FOUND,response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("remoteexception"); assertEquals("incorrect number of elements",3,exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); verifyNonexistNodeException(message,type,classname); } finally { rm.stop(); } }
@Test public void testTasksQueryMap() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); String type = "m"; ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).path("tasks").queryParam("type",type) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements",json.length()); JSONObject tasks = json.getJSONObject("tasks"); JSONArray arr = tasks.getJSONArray("task"); assertEquals("incorrect number of elements",arr.length()); verifyAMTask(arr,jobsMap.get(id),type); } }
@Private @VisibleForTesting public ClientResponse doPostingObject(Object object,String path) { WebResource webResource = client.resource(resURI); if (path == null) { return webResource.accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .post(ClientResponse.class,object); } else if (path.equals("domain")) { return webResource.path(path).accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON) .put(ClientResponse.class,object); } else { throw new YarnRuntimeException("UnkNown resource type"); } }
@Test public void testTasksXML() throws JSONException,Exception { WebResource r = resource(); Map<JobId,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks") .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE,response.getType()); String xml = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList tasks = dom.getElementsByTagName("tasks"); assertEquals("incorrect number of elements",tasks.getLength()); NodeList task = dom.getElementsByTagName("task"); verifyHsTaskXML(task,jobsMap.get(id)); } }
@Test public void testJobAttemptsSlash() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("jobattempts/") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,json.length()); JSONObject info = json.getJSONObject("jobAttempts"); verifyHsJobAttempts(info,appContext.getJob(id)); } }
@Test public void testJobConf() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce") .path("jobs").path(jobId).path("conf") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,json.length()); JSONObject info = json.getJSONObject("conf"); verifyHsJobConf(info,jobsMap.get(id)); } }
@Test public void testFromId() throws Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("timeline") .path("type_1").queryParam("fromId","id_2") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); assertEquals(2,response.getEntity(TimelineEntities.class).getEntities() .size()); response = r.path("ws").path("v1").path("timeline") .path("type_1").queryParam("fromId","id_1") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getEntity(TimelineEntities.class).getEntities() .size()); }
@Test public void testTasksSlash() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks/") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,2,arr.length()); verifyHsTask(arr,null); } }
@Test public void testNodesQueryHealthyFalse() throws JSONException,Exception { WebResource r = resource(); MockNM nm1 = rm.registerNode("h1:1234",5120); MockNM nm2 = rm.registerNode("h2:1235",5121); rm.sendNodeStarted(nm1); rm.NMwaitForState(nm1.getNodeId(),NodeState.RUNNING); rm.NMwaitForState(nm2.getNodeId(),NodeState.NEW); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").queryParam("states","UNHEALTHY") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,json.length()); assertEquals("nodes is not null",json.get("nodes")); }
@Test public void testJobAttemptsXML() throws Exception { WebResource r = resource(); Map<JobId,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1") .path("mapreduce").path("jobs").path(jobId).path("jobattempts") .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE,response.getType()); String xml = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList attempts = dom.getElementsByTagName("jobAttempts"); assertEquals("incorrect number of elements",attempts.getLength()); NodeList info = dom.getElementsByTagName("jobAttempt"); verifyJobAttemptsXML(info,jobsMap.get(id)); } }
@Test public void testCreateEphemeralZNode() throws KeeperException,InterruptedException,IOException { ZSession session = createSession("30"); WebResource wr = znodesr.path("/") .queryParam("op","create") .queryParam("name","ephemeral-test") .queryParam("ephemeral","true") .queryParam("session",session.id) .queryParam("null","true"); Builder b = wr.accept(MediaType.APPLICATION_JSON); ClientResponse cr = b.post(ClientResponse.class); assertEquals(ClientResponse.Status.CREATED,cr.getClientResponseStatus()); Stat stat = new Stat(); zk.getData("/ephemeral-test",stat); ZooKeeper sessionZK = ZooKeeperService.getClient(CONTEXT_PATH,session.id); assertEquals(stat.getEphemeralOwner(),sessionZK.getSessionId()); }
@Test public void testInvalidUri() throws JSONException,Exception { WebResource r = resource(); String responseStr = ""; try { responseStr = r.path("ws").path("v1").path("applicationhistory").path("bogus") .queryParam("user.name",USERS[round]) .accept(MediaType.APPLICATION_JSON).get(String.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.NOT_FOUND,response.getClientResponseStatus()); WebServicesTestUtils.checkStringMatch( "error string exists and shouldn't","",responseStr); } }
@Test public void testInvalidAccept() throws JSONException,Exception { WebResource r = resource(); String responseStr = ""; try { responseStr = r.path("ws").path("v1").path("node") .accept(MediaType.TEXT_PLAIN).get(String.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.INTERNAL_SERVER_ERROR,response.getClientResponseStatus()); WebServicesTestUtils.checkStringMatch( "error string exists and shouldn't",responseStr); } }
@Test public void testJobAttemptsDefault() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1") .path("mapreduce").path("jobs").path(jobId).path("jobattempts") .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,json.length()); JSONObject info = json.getJSONObject("jobAttempts"); verifyJobAttempts(info,jobsMap.get(id)); } }
@Test public void testTasksDefault() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks") .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,null); } }
@Test public void testInvalidAccept() throws JSONException,Exception { WebResource r = resource(); String responseStr = ""; try { responseStr = r.path("ws").path("v1").path("history") .accept(MediaType.TEXT_PLAIN).get(String.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.INTERNAL_SERVER_ERROR,responseStr); } }
@Test public void testTaskIdSlash() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks") .path(tid + "/").accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,json.length()); JSONObject info = json.getJSONObject("task"); verifyHsSingleTask(info,task); } } }
@Test public void testJobsQueryStartTimeNegative() throws JSONException,Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs") .queryParam("startedTimeBegin",String.valueOf(-1000)) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(Status.BAD_REQUEST,response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("remoteexception"); assertEquals("incorrect number of elements",exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils .checkStringMatch("exception message","java.lang.Exception: startedTimeBegin must be greater than 0",message); WebServicesTestUtils.checkStringMatch("exception type","BadRequestException",type); WebServicesTestUtils.checkStringMatch("exception classname","org.apache.hadoop.yarn.webapp.BadRequestException",classname); }
@Test public void testTaskAttempts() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).path("tasks").path(tid).path("attempts") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyAMTaskAttempts(json,task); } } }
@Test public void testTaskIdDefault() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,task); } } }
@Test public void testAppsQueryStatesNone() throws JSONException,Exception { rm.start(); MockNM amNodeManager = rm.registerNode("127.0.0.1:1234",2048); rm.submitApp(CONTAINER_MB); amNodeManager.nodeHeartbeat(true); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("apps") .queryParam("states",YarnApplicationState.RUNNING.toString()) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,json.length()); assertEquals("apps is not null",json.get("apps")); rm.stop(); }
@Test public void testTasksQueryMap() throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); String type = "m"; ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks") .queryParam("type",type).accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,arr.length()); verifyHsTask(arr,type); } }
@Test public void testNodeSingleAppsMissing() throws JSONException,app); addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(),app2); addAppContainers(app2); try { r.path("ws").path("v1").path("node").path("apps") .path("application_1234_0009").accept(MediaType.APPLICATION_JSON) .get(JSONObject.class); fail("should have thrown exception on invalid user query"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.NOT_FOUND,exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils.checkStringMatch("exception message","java.lang.Exception: app with id application_1234_0009 not found",message); WebServicesTestUtils.checkStringMatch("exception type","NotFoundException",type); WebServicesTestUtils.checkStringMatch("exception classname","org.apache.hadoop.yarn.webapp.NotFoundException",classname); } }
@Test public void testClusterSchedulerDefault() throws JSONException,Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("scheduler").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterScheduler(json); }
@Test public void testClusterSchedulerFifoXML() throws JSONException,Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("scheduler").accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE,response.getType()); String xml = response.getEntity(String.class); verifySchedulerFifoXML(xml); }
@Test public void testClusterMetricsSlash() throws JSONException,Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("metrics/").accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterMetricsJSON(json); }
@Test public void testAppsQueryFinalStatusInvalid() throws JSONException,2048); rm.submitApp(CONTAINER_MB); amNodeManager.nodeHeartbeat(true); WebResource r = resource(); try { r.path("ws").path("v1").path("cluster").path("apps") .queryParam("finalStatus","INVALID_test") .accept(MediaType.APPLICATION_JSON).get(JSONObject.class); fail("should have thrown exception on invalid state query"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.BAD_REQUEST,exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils .checkStringContains( "exception message","org.apache.hadoop.yarn.api.records.FinalApplicationStatus.INVALID_test","IllegalArgumentException","java.lang.IllegalArgumentException",classname); } finally { rm.stop(); } }
@Test public void testJobsQueryFinishTimeBeginEndInvalid() throws JSONException,Exception { WebResource r = resource(); Long Now = System.currentTimeMillis(); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs") .queryParam("finishedTimeBegin",String.valueOf(Now)) .queryParam("finishedTimeEnd",String.valueOf(40000)) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(Status.BAD_REQUEST,exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils .checkStringMatch( "exception message","java.lang.Exception: finishedTimeEnd must be greater than finishedTimeBegin",classname); }
@Test public void testDeleteSession() { ZSession session = createSession("30"); WebResource wr = sessionsr.path(session.id); Builder b = wr.accept(MediaType.APPLICATION_JSON); assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH,session.id)); ClientResponse cr = b.delete(ClientResponse.class,null); assertEquals(ClientResponse.Status.NO_CONTENT,cr.getClientResponseStatus()); assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH,session.id)); }
@Test public void testBlacklistednodesXML() throws Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("blacklistednodes").accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE,response.getType()); String xml = response.getEntity(String.class); verifyBlacklistednodesInfoXML(xml,appContext); }
private void testTaskAttemptIdErrorGeneric(String attid,String error) throws JSONException,Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); try { r.path("ws").path("v1").path("mapreduce").path("jobs").path(jobId) .path("tasks").path(tid).path("attempts").path(attid) .accept(MediaType.APPLICATION_JSON).get(JSONObject.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.NOT_FOUND,response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE,response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("remoteexception"); assertEquals("incorrect number of elements",exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils.checkStringMatch("exception message",error,message); WebServicesTestUtils.checkStringMatch("exception type",type); WebServicesTestUtils.checkStringMatch("exception classname",classname); } } } }
android.webkit.WebResourceResponse的实例源码
@Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { // Intercept requests for private images and add the WP.com authorization header if (mIsPrivatePost && !TextUtils.isEmpty(mToken) && UrlUtils.isImageUrl(url)) { try { URL imageUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection(); conn.setReadTimeout(WPRestClient.REST_TIMEOUT_MS); conn.setConnectTimeout(WPRestClient.REST_TIMEOUT_MS); conn.setRequestProperty("Authorization","Bearer " + mToken); conn.setRequestProperty("User-Agent",wordpress.getUserAgent()); conn.setRequestProperty("Connection","Keep-Alive"); conn.connect(); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { InputStream inputStream = new BufferedInputStream(conn.getInputStream()); return new WebResourceResponse(conn.getContentType(),"UTF-8",inputStream); } } catch (IOException e) { AppLog.e(AppLog.T.READER,e); } } return null; }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,WebResourceRequest request) { /* ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes()); if (mAdBlock.isAd(request.getUrl().getHost())) { return new WebResourceResponse("text/plain","utf-8",EMPTY); } if(request.getUrl().getHost().indexOf("127.0.0.1")>=0){ //ToastUtil.showMessage("this site is insecure"); return new WebResourceResponse("text/plain",EMPTY); } */ return super.shouldInterceptRequest(view,request); }
public WebResourceResponse getResource(String path) { int index = path.lastIndexOf("."); if (index == -1) { return null; } String ext = path.substring(index); Log.d("wlx",ext); String mini = (String) this.minitype.get(ext); if (mini == null) { return null; } try { return new WebResourceResponse(mini,new FileInputStream(this.resource + path)); } catch (FileNotFoundException e) { e.printstacktrace(); return null; } }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { WebResourceResponse webResourceResponse = null; if (mCustomWebViewClient!=null){ webResourceResponse = mCustomWebViewClient.shouldInterceptRequest(view,url); } if (webResourceResponse != null){ return webResourceResponse; } if (!mIsEnableCache){ return null; } return mWebViewCache.getWebResourceResponse(this,url,mCacheStrategy,mEncoding,mCacheInterceptor); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WebResourceResponse shouldInterceptRequest(WebView view,WebResourceRequest request) { WebResourceResponse webResourceResponse = null; if (mCustomWebViewClient!=null){ webResourceResponse = mCustomWebViewClient.shouldInterceptRequest(view,request); } if (webResourceResponse != null){ return webResourceResponse; } if (!mIsEnableCache){ return null; } return mWebViewCache.getWebResourceResponse(this,request.getUrl().toString(),mCacheInterceptor); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WebResourceResponse shouldInterceptRequest(WebView view,WebResourceRequest request) { //此处对文件资源,js,css等请求资源进行拦截,替换 Log.d(TAG,"shouldInterceptRequest: request = \n" + "\nurl = " + request.getUrl().toString() + "\nmethod = " + request.getmethod() + "\nheaders = " + request.getRequestHeaders().toString()); // String url = request.getUrl().toString(); // if ((url.startsWith("https://") || url.startsWith("http://")) && (url.endsWith(".png") || url.endsWith(".jpg"))) { // Log.d(TAG,"拦截资源 :" + url); // try { // WebResourceResponse response = new WebResourceResponse(MimeTypeMap.getFileExtensionFromUrl(".jpg"),FileUtils.getInputStreamFromAssets("img/dog.jpg")); // return response; // } catch (IOException e) { // e.printstacktrace(); // } // } return super.shouldInterceptRequest(view,request); }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,request); }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { // Uses cache to determine if the url is ad,// and returns an empty resource for ads. boolean ad; if (!mloadedUrls.containsKey(url)) { ad = mAdBlocker.isAd(url); mloadedUrls.put(url,ad); } else { ad = mloadedUrls.get(url); } // Verbose blocked or passed urls Log.v(getClass().getSimpleName(),(ad ? "Blocked" : "Pass") + ": " + Uri.parse(url).getHost()); // Return appropriate response if(ad) { return mAdBlocker.createEmptyResource(); } return super.shouldInterceptRequest(view,url); }
/** * 获取本地资源 */ @Nullable private WebResourceResponse getWebResourceResponse(String url) { try { // 如果是图片且本地有缓存 if (isImageSuffix(url) || isgifSuffix(url)) { FileInputStream inputStream = mCache.getStream(url); if (null != inputStream) { return new WebResourceResponse(getMimeType(url),"base64",inputStream); } } } catch (Exception e) { e.printstacktrace(); } return null; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { if (prefs.getBoolean("adblock",true)) { boolean ad; if (!loadedUrls.containsKey(url)) { ad = AdBlocker.isAd(url); loadedUrls.put(url,ad); } else { ad = loadedUrls.get(url); } return ad ? AdBlocker.createEmptyResource() : super.shouldInterceptRequest(view,url); } return super.shouldInterceptRequest(view,url); }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,WebResourceRequest request) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (mAdBlock.isAd(request.getUrl().toString())) { String stweb = "\n \n \n \n BLOCKED BY AD-BLOCKER" + "\n" + "\n" + " \n" + " \n" + " \n - TO disABLE AD-BLOCKER GO TO SETTINGS/GENEARL SETTING"; ByteArrayInputStream EMPTY = new ByteArrayInputStream(stweb.getBytes()); return new WebResourceResponse("text/plain",EMPTY); } } return super.shouldInterceptRequest(view,request); }
@SuppressLint("NewApi") public WebResourceResponse shouldInterceptRequest (WebView view,WebResourceRequest request) { String url = request.getUrl().toString(); try { URL urlData = new URL(url); String path = urlData.getPath().substring(1); if (!path.endsWith(".js") && !path.endsWith(".css")) { return null; } Log.d("BasicWebViewClient","Find " + path + " from asset."); InputStream localStream = assetMgr.open(path); Log.d("BasicWebViewClient",url + " found,try load from asset."); return new WebResourceResponse((path.endsWith(".js") ? "text/javascript" : "text/css"),localStream); } catch (Exception e) { return null; } }
@SuppressWarnings("deprecation") @Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { try { URL urlData = new URL(url); String path = urlData.getPath().substring(1); if (!path.endsWith(".js") && !path.endsWith(".css")) { return null; } Log.d("BasicWebViewClient",try load from asset."); return new WebResourceResponse((url.contains(".js") ? "text/javascript" : "text/css"),localStream); } catch (Exception e) { return null; } }
/** * Attempt to retrieve the WebResourceResponse associated with the given <code>url</code>. * This method should be invoked from within * {@link android.webkit.WebViewClient#shouldInterceptRequest(android.webkit.WebView,String)}. * * @param url the url to process. * @return a response if the request URL had a matching handler,null if no handler was found. */ public WebResourceResponse shouldInterceptRequest(String url) { PathHandler handler = null; Uri uri = parseAndVerifyUrl(url); if (uri != null) { synchronized (uriMatcher) { handler = (PathHandler) uriMatcher.match(uri); } } if (handler == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return new WebResourceResponse(handler.getMimeType(),handler.getEncoding(),new LegacyLazyInputStream(handler,uri)); } else { InputStream is = handler.handle(uri); return new WebResourceResponse(handler.getMimeType(),is); } }
public void testHostAssets() { final String testHtmlContents = "<body><div>hah</div></body>"; WebViewLocalServer assetServer = new WebViewLocalServer(new MockProtocolHandler() { @Override public InputStream openAsset(String path) throws IOException { if (path.equals("/www/test.html")) { return new ByteArrayInputStream(testHtmlContents.getBytes("utf-8")); } return null; } }); WebViewLocalServer.AssetHostingDetails details = assetServer.hostAssets("androidplatform.net","/www","/assets",true,true); assertEquals(details.getHttpPrefix(),Uri.parse("http://androidplatform.net/assets")); assertEquals(details.getHttpsPrefix(),Uri.parse("https://androidplatform.net/assets")); WebResourceResponse response = assetServer.shouldInterceptRequest("http://androidplatform.net/assets/test.html"); assertNotNull(response); assertEquals(testHtmlContents,readAsstring(response.getData(),"utf-8")); }
private WebResourceResponse loadFromAssets( String url,String assetPath,String mimeType,String encoding ) { AssetManager assetManager = this.activity.getAssets(); InputStream input = null; try { Log.d(LOG_TAG,"Loading from assets: " + assetPath); input = assetManager.open("/images/logo.png"); WebResourceResponse response = new WebResourceResponse(mimeType,encoding,input); return response; } catch (IOException e) { Log.e("WEB-APP","Error loading " + assetPath + " from assets: " + e.getMessage(),e); } return null; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WebResourceResponse shouldInterceptRequest(WebView aWebView,WebResourceRequest request) { String strMimeType = getFileMimeType(request.getUrl().toString()); if (strMimeType != null) { String lowerCaseUrl = strMimeType.toLowerCase(); if (lowerCaseUrl.contains("png") || lowerCaseUrl.contains("jpg") || lowerCaseUrl.contains("jpeg")) { return handleImageRequest(aWebView,request,strMimeType); } } return super.shouldInterceptRequest(aWebView,request); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private WebResourceResponse handleImageRequest(final WebView aWebView,final WebResourceRequest request,String strMimeType) { KCWebView webView = (KCWebView) aWebView; if (mImageDownloader == null) mImageDownloader = new KCWebImageDownloader(webView.getContext(),webView.getWebPath()); if (mWebImageHandler==null) mWebImageHandler = new KCWebImageHandler(mWebImageListener); KCWebImage webImage = mImageDownloader.downloadImageFile(request.getUrl().toString(),mWebImageHandler.add(request.getUrl().toString())); InputStream stream = webImage.getInputStream(); if (stream == null) { Log.e("image","current stream is null,download image from net"); return null; } return new WebResourceResponse(strMimeType,stream); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private WebResourceResponse handleImageRequest(final WebView aWebView,final String aUrl,String strMimeType) { KCWebView webView = (KCWebView) aWebView; if (mImageDownloader == null) mImageDownloader = new KCWebImageDownloader(aWebView.getContext(),webView.getWebPath()); if (mWebImageHandler==null) mWebImageHandler = new KCWebImageHandler(mWebImageListener); KCWebImage webImage = mImageDownloader.downloadImageFile(aUrl,mWebImageHandler.add(aUrl)); InputStream stream = webImage.getInputStream(); if (stream == null) { Log.e("image",stream); }
@Override public WebResourceResponse loadUrl(String url) { NetflixUrl netflixUrl = new NetflixUrl(url); // note due to shouldOverrideUrlLoading,no /watch url ever gets here,so no need to cater for it if (netflixUrl.isNetflixUrl()) { client.getParams().setParameter(AllClientPNames.USER_AGENT,UserAgents.Mobile); if (netflixUrl.isTitle()) { client.getParams().setParameter(AllClientPNames.USER_AGENT,UserAgents.Desktop); return doLoadUrl(url); } else if (netflixUrl.isbrowse() || netflixUrl.isDefault()) { return doLoadUrl(url); } } // else return null; }
@SuppressWarnings("deprecation") @Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { if (url.startsWith("http://") || url.startsWith("https://")) { if (url.endsWith("//127.0.0.1/image.jpeg")) { InputStream inputStream = null; try { inputStream = fileHolder.openInputStream(); return new WebResourceResponse(fileHolder.getimageType() == FileHolder.ImageType.IMAGE_SVG ? "image/svg+xml" : "image/jpeg",null,inputStream); } catch (IOException e) { IoUtils.close(inputStream); } } return new WebResourceResponse("text/html",null); } else { return null; } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WebResourceResponse shouldInterceptRequest(@NonNull WebView view,@NonNull WebResourceRequest request) { String url = request.getUrl().toString(); if (url.contains("ads.js") || url.contains("f.js") || url.contains("pop.js") || url.contains("syndication.exoclick.com")) { return new WebResourceResponse("text/plain",nothing); } else if (url.contains("main.js")) { return getWebResourceResponseFromAsset(getSite(),"main.js",TYPE.JS); } else if (url.contains("exoclick.com") || url.contains("juicyadultads.com")) { return new WebResourceResponse("text/plain",nothing); } else { return super.shouldInterceptRequest(view,request); } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { try { // Check the against the whitelist and lock out access to the WebView directory // Changing this will cause problems for your application if (!parentEngine.pluginManager.shouldAllowRequest(url)) { LOG.w(TAG,"URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain",null); } CordovaResourceApi resourceApi = parentEngine.resourceApi; Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsspecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri,true); return new WebResourceResponse(result.mimeType,result.inputStream); } // If we don't need to special-case the request,let the browser load it. return null; } catch (IOException e) { if (!(e instanceof FileNotFoundException)) { LOG.e(TAG,"Error occurred while loading a file (returning a 404).",e); } // Results in a 404. return new WebResourceResponse("text/plain",null); } }
protected WebResourceResponse shouldInterceptRequest(WebView webView,Uri uri) { if (!CID_SCHEME.equals(uri.getScheme())) { return RESULT_DO_NOT_INTERCEPT; } if (attachmentResolver == null) { return RESULT_DUMMY_RESPONSE; } String cid = uri.getSchemeSpecificPart(); if (TextUtils.isEmpty(cid)) { return RESULT_DUMMY_RESPONSE; } Uri attachmentUri = attachmentResolver.getAttachmentUriForContentId(cid); if (attachmentUri == null) { return RESULT_DUMMY_RESPONSE; } Context context = webView.getContext(); ContentResolver contentResolver = context.getContentResolver(); try { String mimeType = contentResolver.getType(attachmentUri); InputStream inputStream = contentResolver.openInputStream(attachmentUri); WebResourceResponse webResourceResponse = new WebResourceResponse(mimeType,inputStream); addCacheControlHeader(webResourceResponse); return webResourceResponse; } catch (Exception e) { Timber.e(e,"Error while intercepting URI: %s",uri); return RESULT_DUMMY_RESPONSE; } }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { url = url.toLowerCase(); if(!url.contains(homeurl)){ if (!ADFilterTool.hasAd(context,url)) { return super.shouldInterceptRequest(view,url); }else{ return new WebResourceResponse(null,null); } }else{ return super.shouldInterceptRequest(view,url); }}
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public WebResourceResponse shouldInterceptRequest(WebView view,null); } }
@Override public Object createWebResourceResponse(String mimeType,String encoding,InputStream data,Map<String,String> headers) { WebResourceResponse resourceResponse = new WebResourceResponse(mimeType,data); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { resourceResponse.setResponseHeaders(headers); } return resourceResponse; }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { if (sonicSession != null) { return (WebResourceResponse) sonicSession.getSessionClient().requestResource(url); } return null; }
@Deprecated public WebResourceResponse shouldInterceptRequest(WebView view,String url) { if(mWebViewClient!=null){ return mWebViewClient.shouldInterceptRequest(view,url); } return super.shouldInterceptRequest(view,url); }
public WebResourceResponse shouldInterceptRequest(WebView view,WebResourceRequest request) { if(mWebViewClient!=null){ return mWebViewClient.shouldInterceptRequest(view,request); } return super.shouldInterceptRequest(view,request); }
public void onReceivedHttpError( WebView view,WebResourceRequest request,WebResourceResponse errorResponse) { if(mWebViewClient!=null){ mWebViewClient.onReceivedHttpError(view,errorResponse); return; } super.onReceivedHttpError(view,errorResponse); }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { if (mAdBlock.isAd(url)) { ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes()); return new WebResourceResponse("text/plain",EMPTY); } return null; }
/** * 加载资源 * android5.0以下支持,注意:5.0+系统也会执行该方法 * * @param view * @param url * @return */ @Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { return super.shouldInterceptRequest(view,url); } else { return loadPage.shouldInterceptRequest(view,url); } }
/** * 加载资源 * android5.0+支持 * * @param view * @param request * @return */ @Override public WebResourceResponse shouldInterceptRequest(WebView view,WebResourceRequest request) { WebResourceResponse resourceResponse = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { resourceResponse = loadPage.shouldInterceptRequest(view,request.getUrl().toString()); } if (resourceResponse == null) { return super.shouldInterceptRequest(view,request); } else { return resourceResponse; } }
@Override public Object createWebResourceResponse(String mimeType,String> headers) { WebResourceResponse resourceResponse = new WebResourceResponse(mimeType,data); if (SysUtils.hasLollipop()) { resourceResponse.setResponseHeaders(headers); } return resourceResponse; }
@Override public WebResourceResponse shouldInterceptRequest(WebView view,String url) { if (sonicSession != null) { return (WebResourceResponse) sonicSession.getSessionClient().requestResource(url); } return null; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WebResourceResponse shouldInterceptRequest(WebView view,WebResourceRequest request) { Uri url = request.getUrl(); if ("https://www.fengshihao.com/user.js".indexOf(url.toString()) == 0) { final WebResourceResponse userjs = new WebResourceResponse("text/javascript",new ByteArrayInputStream("console.log('hello user js');".getBytes())); return userjs; } return super.shouldInterceptRequest(view,request); }
@TargetApi(21) public WebResourceResponse shouldInterceptRequest(WebView view,WebResourceRequest request) { LogInfo.log("ZSM sFromNative shouldInterceptRequest == " + NativeWebViewUtils.getInstance().getFromNative() + " request == " + request.getUrl().toString()); if (!NativeWebViewUtils.getInstance().getFromNative()) { return super.shouldInterceptRequest(view,request); } super.shouldInterceptRequest(view,request); return NativeWebViewUtils.getInstance().getResource(request.getUrl().toString()); }
@Override public void onReceivedHttpError(WebView view,WebResourceResponse errorResponse) { if (mCustomWebViewClient!=null){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mCustomWebViewClient.onReceivedHttpError(view,errorResponse); } return; } super.onReceivedHttpError(view,errorResponse); }
com.google.gwt.user.client.ui.ImageResourceRenderer的实例源码
private void columnDeleteRestore(SafeHtmlBuilder sb,FileInfo info) { sb.openTd().setStyleName(R.css().restoreDelete()); if (hasUser) { if (!Patch.isMagic(info.path())) { boolean editable = isEditable(info); sb.openDiv() .openElement("button") .setAttribute("title",Resources.C.restoreFileInline()) .setAttribute("onclick",RESTORE + "(event," + info._row() + ")") .append(new ImageResourceRenderer().render(Gerrit.RESOURCES.editUndo())) .closeElement("button"); if (editable) { sb.openElement("button") .setAttribute("title",Resources.C.removeFileInline()) .setAttribute("onclick",DELETE + "(event," + info._row() + ")") .append(new ImageResourceRenderer().render(Gerrit.RESOURCES.rednot())) .closeElement("button"); } sb.closeDiv(); } } sb.closeTd(); }
@UiConstructor public MyMenuItem(String text,ImageResource res) { super(SafeHtmlUtils.fromString(text)); ImageResourceRenderer renderer = new ImageResourceRenderer(); setHTML(renderer.render(res).asstring() + " " + text); }
void populate(int row,PluginInfo plugin) { if (plugin.disabled() || plugin.indexUrl() == null) { table.setText(row,1,plugin.name()); } else { table.setWidget( row,new Anchor(plugin.name(),Gerrit.selfRedirect(plugin.indexUrl()),"_blank")); if (new ExtensionScreen(plugin.name() + "/settings").isFound()) { InlineHyperlink adminScreenLink = new InlineHyperlink(); adminScreenLink.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.gear())); adminScreenLink.setTargetHistoryToken("/x/" + plugin.name() + "/settings"); adminScreenLink.setTitle(AdminConstants.I.pluginSettingsToolTip()); table.setWidget(row,2,adminScreenLink); } } table.setText(row,3,plugin.version()); table.setText( row,4,plugin.disabled() ? AdminConstants.I.plugindisabled() : AdminConstants.I.pluginEnabled()); final FlexCellFormatter fmt = table.getFlexCellFormatter(); fmt.addStyleName(row,Gerrit.RESOURCES.css().dataCell()); fmt.addStyleName(row,Gerrit.RESOURCES.css().dataCell()); setRowItem(row,plugin); }
private List<InlineHyperlink> getUnifiedDiffLink() { InlineHyperlink toUnifiedDiffLink = new InlineHyperlink(); toUnifiedDiffLink.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.unifiedDiff())); toUnifiedDiffLink.setTargetHistoryToken( dispatcher.toUnified(getProject(),base,revision,path)); toUnifiedDiffLink.setTitle(PatchUtil.C.unifiedDiff()); return Collections.singletonList(toUnifiedDiffLink); }
private Widget createEditIcon() { PatchSet.Id id = idActive.isBaSEOrAutoMerge() ? other.idActive.asPatchSetId() : idActive.asPatchSetId(); Anchor anchor = new Anchor( new ImageResourceRenderer().render(Gerrit.RESOURCES.edit()),"#" + dispatcher.toEditScreen(project,id,path)); anchor.setTitle(PatchUtil.C.edit()); return anchor; }
private Anchor createDownloadLink() { DiffObject diffObject = idActive.isBaSEOrAutoMerge() ? other.idActive : idActive; String sideURL = idActive.isBaSEOrAutoMerge() ? "1" : "0"; String base = GWT.getHostPageBaseURL() + "cat/"; Anchor anchor = new Anchor( new ImageResourceRenderer().render(Gerrit.RESOURCES.downloadIcon()),base + KeyUtil.encode(diffObject.asPatchSetId() + "," + path) + "^" + sideURL); anchor.setTitle(PatchUtil.C.download()); return anchor; }
private List<InlineHyperlink> getSideBySideDiffLink() { InlineHyperlink toSideBySideDiffLink = new InlineHyperlink(); toSideBySideDiffLink.setHTML( new ImageResourceRenderer().render(Gerrit.RESOURCES.sideBySideDiff())); toSideBySideDiffLink.setTargetHistoryToken( dispatcher.toSideBySide(getProject(),path)); toSideBySideDiffLink.setTitle(PatchUtil.C.sideBySideDiff()); return Collections.singletonList(toSideBySideDiffLink); }
private SafeHtmlBuilder formatHashtags(JsArrayString hashtags) { SafeHtmlBuilder html = new SafeHtmlBuilder(); Iterator<String> itr = Natives.asList(hashtags).iterator(); while (itr.hasNext()) { String hashtagName = itr.next(); html.openSpan() .setAttribute(DATA_ID,hashtagName) .setStyleName(style.hashtagName()) .openAnchor() .setAttribute("href","#" + PageLinks.tochangeQuery("hashtag:\"" + hashtagName + "\"")) .setAttribute("role","listitem") .openSpan() .setStyleName(style.hashtagIcon()) .append(new ImageResourceRenderer().render(Gerrit.RESOURCES.hashtag())) .closeSpan() .append(" ") .append(hashtagName) .closeAnchor(); if (canEdit) { html.openElement("button") .setAttribute("title","Remove hashtag") .setAttribute("onclick",REMOVE + "(event)") .append("×") .closeElement("button"); } html.closeSpan(); if (itr.hasNext()) { html.append(' '); } } return html; }
private void renderLinksToDiff() { InlineHyperlink sbs = new InlineHyperlink(); sbs.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.sideBySideDiff())); sbs.setTargetHistoryToken( dispatcher.toPatch(projectKey,"sidebyside",null,new Patch.Key(revision,path))); sbs.setTitle(PatchUtil.C.sideBySideDiff()); linkPanel.add(sbs); InlineHyperlink unified = new InlineHyperlink(); unified.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.unifiedDiff())); unified.setTargetHistoryToken( dispatcher.toPatch(projectKey,"unified",path))); unified.setTitle(PatchUtil.C.unifiedDiff()); linkPanel.add(unified); }
private Anchor createblameIcon() { Anchor anchor = new Anchor(new ImageResourceRenderer().render(Gerrit.RESOURCES.blame())); anchor.setTitle(PatchUtil.C.blame()); return anchor; }
public FerriesRouteSchedulesViewGwtImpl() { pullToRefresh = new PullPanel(); pullArrowHeader = new PullArrowHeader(); pullToRefresh.setHeader(pullArrowHeader); cellList = new CellList<FerriesRouteItem>( new FerriesRouteSchedulesCell<FerriesRouteItem>() { private ImageResourceRenderer imageRenderer = new ImageResourceRenderer(); @Override public String getDescription(FerriesRouteItem model) { return model.getDescription(); } @Override public String getLastUpdated(FerriesRouteItem model) { return ParserUtils.relativeTime(model.getCacheDate(),"MMMM d,yyyy h:mm a",false); } @Override public SafeHtml getAlertimage(FerriesRouteItem model) { boolean hasAlerts = false; if (!model.getRoutealert().equals("[]")) hasAlerts = true; SafeHtml image = imageRenderer.render(AppBundle.INSTANCE.btnAlertPNG()); return hasAlerts ? image : SafeHtmlUtils.fromString(""); } @Override public String getCrossingTime(FerriesRouteItem model) { try { if (model.getCrossingTime().equalsIgnoreCase("null")) { return ""; } else { return "Crossing Time: ~ " + model.getCrossingTime() + " min"; } } catch (Exception e) { return ""; } } }); initWidget(uiBinder.createAndBindUi(this)); accessibilityPrepare(); if (MGWT.getosDetection().isAndroid()) { leftFlexSpacer.setVisible(false); } }
com.google.gwt.user.client.ui.SourcesMouseEvents的实例源码
public ItemWidget(ObjectBean object) { setStyleName(PlayerStyles.OBJECT_IN_BAG); this.object = object; SourcesMouseEvents widget; if (object.getIcon()==null) { getElement().getStyle().setdisplay(model.getSettings().isverticalObjects() ? display.BLOCK : display.INLINE_BLOCK); setTitle(AppLocale.getAppConstants().playerClickToUse()); text = new Label(); if (model.getSettings().isverticalObjects()) { text.setText(object.getName()); text.setWordWrap(false); } else { text.setText(object.getName()+","); } widget = text; add(text); } else { getElement().getStyle().setdisplay(display.INLINE_BLOCK); setTitle(object.getName()); image = new Image(); image.addLoadHandler(this); if (object.getIcon().getBigUrl()==null) { image.setUrl(object.getIcon().getUrl() ); } else { big = true; image.setUrl(object.getIcon().getBigUrl()); } add(image); widget = image; } if (model.getSettings().isHiddenUsingObjects()) { addStyleName(PlayerStyles.CLICKABLE); widget.addMouseListener(this); } animationTimer.add(this); }
public void makeDraggable(SourcesMouseEvents w,boolean revert) { Draggable d = new Draggable(); d.widget = (Widget) w; d.listener = new DragSupportListener((Widget) w,revert); w.addMouseListener(d.listener); draggables.put(d.widget,d); }
public DragControl(Widget dragWidget,SourcesMouseEvents drag) { drag.addMouseListener(this); this.dragWidget = dragWidget; }
public DragControl(Widget dragWidget,SourcesMouseEvents drag) { drag.addMouseListener(this); this.dragWidget = dragWidget; }
public void addDragListener(SourcesMouseEvents w,DragListener l) { Draggable d = this.draggables.get((Widget) w); d.listeners.add(l); }
public void removeDragListener(SourcesMouseEvents w,DragListener l) { Draggable d = this.draggables.get((Widget) w); d.listeners.remove(l); }
public void removeDraggable(SourcesMouseEvents w) { Draggable d = this.draggables.get((Widget) w); w.removeMouseListener(d.listener); this.draggables.remove(d.widget); }
public void removeDropListeners(SourcesMouseEvents w,DropListener dl) { List<DropListener> listeners = (dropListeners.get((Widget) w) != null) ? dropListeners.get((Widget) w) : new ArrayList<DropListener>(); listeners.remove(dl); }
com.google.gwt.user.client.ui.SourcesTabEvents的实例源码
public boolean onBeforeTabSelected(SourcesTabEvents sender,int tabIndex) { if (tabIndex == TabIndexes.VIEW) { //if (_uiStateManager.) return true; } else { //if true isn't returned the tab cannot be selected return true; } }
public void onTabSelected(SourcesTabEvents sender,int tabIndex) { if (tabIndex == TabIndexes.VIEW) { _tabPanelBackGround.addStyleName("mainBackground"); _mapManager.setMode(MapManager.MODE_SETTING_VIEW); } else if (tabIndex == TabIndexes.ADD) { _tabPanelBackGround.removeStyleName("mainBackground"); _mapManager.setMode(MapManager.MODE_SETTING_ADD); } else if (tabIndex == TabIndexes.HELP) { _tabPanelBackGround.addStyleName("mainBackground"); _mapManager.setMode(MapManager.MODE_SETTING_HELP); } else if (tabIndex == TabIndexes.MY_BINGLES) { _tabPanelBackGround.removeStyleName("mainBackground"); _mapManager.setMode(MapManager.MODE_SETTING_MY_BINGLES); } else { throw new RuntimeException("didn't kNow about this tab"); } }
public boolean onBeforeTabSelected(SourcesTabEvents sender,int tabIndex) { return true; }
public void onTabSelected(SourcesTabEvents sender,int tabIndex) { Widget selected = tab.getWidget(tabIndex); if (selected instanceof BaseScreen) { ((BaseScreen)selected).load(objectType,objectId); } }
public boolean onBeforeTabSelected(SourcesTabEvents sender,int tabIndex) { return true; }
public void onTabSelected(SourcesTabEvents sender,objectId); } }
public void onTabSelected(SourcesTabEvents sender,int tabIndex) { //dont do anything here,yet }
public boolean onBeforeTabSelected(SourcesTabEvents sender,int tabIndex) { //if true isn't returned the tab cannot be selected return true; }
关于com.sun.jersey.api.client.WebResource的实例源码和jasperreport源码解读的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于android.webkit.WebResourceResponse的实例源码、com.google.gwt.user.client.ui.ImageResourceRenderer的实例源码、com.google.gwt.user.client.ui.SourcesMouseEvents的实例源码、com.google.gwt.user.client.ui.SourcesTabEvents的实例源码的相关知识,请在本站寻找。
本文标签: