Throwable cause = e.getCause();
if (cause != null && cause instanceof ClientAbortException) {
// Request has been aborted by the client, nothing can been done as Tomcat has committed the response
- LOGGER.warn("Request {} has been aborted by client, error is '{}'", request, e.getMessage());
+ LOGGER.debug("Request {} has been aborted by client, error is '{}'", request, e.getMessage());
return;
}
LOGGER.error("Fail to process request " + request, e);
package org.sonar.server.ws;
import com.google.common.base.Optional;
-import com.google.common.base.Throwables;
import com.google.protobuf.Message;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
}
}
} catch (Exception e) {
- LOG.error("Error while writing protobuf message {}", MessageFormatter.print(msg));
- Throwables.propagate(e);
+ throw new IllegalStateException(format("Error while writing protobuf message %s", MessageFormatter.print(msg)), e);
} finally {
IOUtils.closeQuietly(output);
}
underTest.execute(request, response);
assertThat(response.stream().outputAsString()).isEmpty();
- assertThat(logTester.logs(LoggerLevel.WARN)).isNotEmpty();
+ assertThat(logTester.logs(LoggerLevel.DEBUG)).isNotEmpty();
}
static class SystemWs implements WebService {
import org.sonarqube.ws.WsPermissions;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.test.ExceptionCauseMatcher.hasType;
public class WsUtilsTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
+
@Rule
public LogTester logger = new LogTester();
WsPermissions.Permission message = WsPermissions.Permission.newBuilder().setName("permission-name").build();
- try {
- // provoke NullPointerException
- WsUtils.writeProtobuf(message, null, new DumbResponse());
- } catch (Exception e) {
- assertThat(e).isInstanceOf(NullPointerException.class);
- assertThat(logger.logs()).contains("Error while writing protobuf message org.sonarqube.ws.WsPermissions.Permission[name: \"permission-name\"]");
- }
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectCause(hasType(NullPointerException.class));
+ expectedException.expectMessage("Error while writing protobuf message org.sonarqube.ws.WsPermissions.Permission[name: \"permission-name\"]");
+ // provoke NullPointerException
+ WsUtils.writeProtobuf(message, null, new DumbResponse());
}
@Test