gpt4 book ai didi

java - SocketTimeoutException cxf httpconduit PUT

转载 作者:行者123 更新时间:2023-11-30 09:07:33 25 4
gpt4 key购买 nike

我有一个测试需要花费很多时间并最终超时。我尝试了解决方案 bob 但没有任何效果。该错误仅在测试 PUT 时发生。

我的测试:

@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>

版本 CXF:2.7.3 Spring 版本 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>

关于java - SocketTimeoutException cxf httpconduit PUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23942990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com