Skip to content

Commit

Permalink
sonarcloud suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Dec 21, 2023
1 parent a790dda commit 9ffa773
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions java/code/src/com/redhat/rhn/taskomatic/TaskoXmlRpcInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@
*/
public class TaskoXmlRpcInvoker implements ProtocolHandler {

private static Logger log = LogManager.getLogger(TaskoXmlRpcInvoker.class);
private XmlRpcServer server;
private static final Logger LOG = LogManager.getLogger(TaskoXmlRpcInvoker.class);
private final XmlRpcServer server;

/**
* Constructor
*
* @param xmlrpcServer
* handles actual XML-RPC calls
* @param xmlrpcServer handles actual XML-RPC calls
*/
public TaskoXmlRpcInvoker(XmlRpcServer xmlrpcServer) {
server = xmlrpcServer;
Expand All @@ -58,10 +57,11 @@ public void handle(Request request, Response response) {
String uri = request.getURI();
InetAddress ip = request.getInetAddress();

try {
try (StringWriter writer = new StringWriter()) {
if (!uri.startsWith("/RPC2")) {
String url = StringUtil.htmlifyText(uri);

LOG.info("Invalid request from {} to {}", ip, uri);
response.setCode(404);
response.setText(url);
PrintStream out = response.getPrintStream();
Expand All @@ -74,7 +74,6 @@ public void handle(Request request, Response response) {
}
else {
InputStream in = request.getInputStream();
StringWriter writer = new StringWriter();
server.execute(in, writer);
OutputStream out = response.getOutputStream();
response.set("Content-Type", "text/xml");
Expand All @@ -85,19 +84,15 @@ public void handle(Request request, Response response) {
}
}
catch (IOException e) {
log.error("Error handling request", e);
LOG.error("Failed request by {}", ip, e);
}
finally {
try {
response.commit();
}
catch (IOException e) {
log.error("Error sending response", e);
LOG.error("Error sending response", e);
}
}



}

}

0 comments on commit 9ffa773

Please sign in to comment.