httpconduit PUT. socket超时异常



我有一个测试,花费了很多时间,最终导致了超时。我尝试了解决方案鲍勃和没有它不工作。在测试PUT时出现错误。

My Test:

@Test
public void testUpdateUse(){
    setExpectedResponse("{"id":1,"username":"test","email":"bob@test.ca"}");
    User userToUpdate = new User();
    userToUpdate.setEmail("bob@test.ca");
    userToUpdate.setUsername("superbob");
    userToUpdate.setId(1);
    UserOrganization userOrganization = new UserOrganization();
    userOrganization.setOrganizationId(1);
    List<UserOrganization> userOrganizations = new ArrayList<>();
    userOrganizations.add(userOrganization);
    UserOrganizationUnit userOrganizationUnit = new UserOrganizationUnit();
    userOrganizationUnit.setOrganizationUnitId(1);
    List<UserOrganizationUnit> userOrganizationUnits = new ArrayList<>();
    userOrganizationUnits.add(userOrganizationUnit);
    userToUpdate.setOrganizations(userOrganizations);
    userToUpdate.setOrganizationUnits(userOrganizationUnits);
    userAPIService.update(1, userToUpdate);
    assertLatestRequest("PUT", "/users/1");
}
@Before
public void setUpServer() throws Exception {
    Thread.sleep(500);
    expectedResponse = null;
    final Authenticator authenticator = new BasicAuthenticator("") {
        @Override
        public boolean checkCredentials(final String username, final String password) {
            return getUsername().equals(username) && getPassword().equals(password);
        }
    };
    final HttpHandler handler = new HttpHandler() {
        @Override
        public void handle(HttpExchange exchange) throws IOException {
            final Authenticator.Result authResult = authenticator.authenticate(exchange);
            if (authResult instanceof Authenticator.Success || !basicAuthRequired) {
                latestExchange = exchange;
                StringWriter writer = new StringWriter();
                try {
                    IOUtils.copy(new InputStreamReader(latestExchange.getRequestBody()), writer, 1024);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                latestRequestBody = writer.toString();
                byte[] response = expectedResponse.getBytes();
                exchange.getResponseHeaders().add("Content-type", expectedContentType);
                exchange.sendResponseHeaders(expectedStatus, response.length);
                exchange.getResponseBody().write(response);
            }
            exchange.close();
            expectedResponse = null;
        }
    };
    httpServer = HttpServer.create(new InetSocketAddress(testPort), 0);
    httpServer.createContext("/", handler);
    httpServer.start();
}
@After
public void tearDownServer() throws Exception {
    if (httpServer != null) {
        httpServer.stop(0);
    }
    context.assertIsSatisfied();
    Thread.sleep(500);
}

applicationContext.xml的示例代码:

<http:conduit name="{http://service.clientapi.user.com/}*.http-conduit">
    <http:client CacheControl="no-store" Connection="Keep-Alive" AllowChunking="false" ConnectionTimeout="10000" ReceiveTimeout="60000"/>
</http:conduit>

Version CXF: 2.7.3Spring 3Java 7

我的解决方案是在我的测试context.xml中覆盖httpconduit

<http:conduit name="*.http-conduit">
    <http:client CacheControl="no-store" Connection="Keep-Alive" AllowChunking="false" ConnectionTimeout="10000" ReceiveTimeout="60000"/>
</http:conduit>

相关内容

  • 没有找到相关文章

最新更新