Tag: 遗产

如何使用HttpURLConnection在Java中等待Expect 100-continue响应

我被困在使用HttpURLConnection向Web服务器发出PUT http请求。 我有一些代码可以使PUT请求很好,我可以在标题中包含’期望100-继续请求属性’然后尝试我可能似乎无法让函数等待’100继续’在发送实际的http有效负载之前从服务器响应。 我得到以下(来自Wireshark) PUT /post/ HTTP/1.1 User-Agent: curl/7.35.0 Accept: */* Content-Type: application/x-www-form-urlencoded Expect: 100-continue Host: somerandomdomain.info Connection: keep-alive Content-Length: 17 Some data for you HTTP/1.1 100 Continue …rest of web-server response… 我确定我错过了一些明显的东西然而在谷歌搜索后我画了一个空白 – 有人可以帮忙吗? 非常感谢如果:) 下面的Http PUT代码片段: String url = “http://somerandomdomain.info”; String postJsonData = “Some data for you\n”; URL obj = new URL(url); HttpURLConnection […]

我们应该测试控制台输出吗?

我正在使用一些遗留代码本身有一些System.out.print命令。 我的eCobertura插件显示这条线为红色,所以我想对它们进行unit testing。 在stackoverflow中,我找到了一种unit testing控制台输出的方法,我觉得非常有趣。 我是这样做的: private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); @Before public void setUpStreams() { System.setOut(new PrintStream(outContent)); } @After public void cleanUpStreams() { System.setOut(null); } @Test public void out() { System.out.print(“Some message from the system”); assertEquals(“Some message from the system”, outContent.toString()); } 到目前为止,测试变得很好,但是当我再次运行代码覆盖率插件时,我收到以下消息: 网络“Thread-0”中的exceptionjava.lang.NullPointerException net.sourceforge.cobertura.coveragedata.TouchCollector.applyTouchesOnProjectData(TouchCollector.java:186)at net.sourceforge.cobertura.coveragedata.ProjectData.saveGlobalProjectData(ProjectData.java:267) )at java.slang.Thread.run(Thread.java:662)的net.sourceforge.cobertura.coveragedata.SaveTimer.run(SaveTimer.java:31) 我有些疑惑: 尝试unit testingSystem.out.print()’s是否正确? eCobertura是否与此类测试兼容? […]

JDK 1.6和Xerces?

在我当前的项目中,我们的目标是JDK 1.6 Runtime环境。 对于传统rasons,Xerces JAR文件捆绑在应用程序中。 这些不再需要了吗? JDK(有一段时间)在JDK中捆绑了XML解析库吗?