From 4cc9ba8968bdeb62b9266d326d85e1cfb4bd1814 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Sat, 19 Oct 2019 13:20:01 +0000 Subject: [PATCH] =?UTF-8?q?Fixed:=20Format=20=E2=80=98XmlRpcEventHandler?= =?UTF-8?q?=E2=80=99=20(OFBIZ-10284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes coding style errors introduced in revision 1868611. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1868621 13f79535-47bb-0310-9956-ffa450edef68 --- build.gradle | 2 +- .../webapp/event/XmlRpcEventHandler.java | 93 ++++++++++--------- 2 files changed, 49 insertions(+), 46 deletions(-) diff --git a/build.gradle b/build.gradle index 393b9b87606..4b9983262d1 100644 --- a/build.gradle +++ b/build.gradle @@ -307,7 +307,7 @@ checkstyle { // the sum of errors that were present before introducing the // ‘checkstyle’ tool present in the framework and in the official // plugins. - maxErrors = 37947 + maxErrors = 37930 // Currently there are a lot of errors so we need to temporarily // hide them to avoid polluting the terminal output. showViolations = false diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/XmlRpcEventHandler.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/XmlRpcEventHandler.java index 438dcafd96e..6bc78060438 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/XmlRpcEventHandler.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/XmlRpcEventHandler.java @@ -16,7 +16,6 @@ Licensed to the Apache Software Foundation (ASF) under one specific language governing permissions and limitations under the License. */ - package org.apache.ofbiz.webapp.event; import static org.apache.ofbiz.base.util.UtilGenerics.checkMap; @@ -71,14 +70,18 @@ Licensed to the Apache Software Foundation (ASF) under one /** * XmlRpcEventHandler */ -public class XmlRpcEventHandler extends XmlRpcHttpServer implements EventHandler { +public final class XmlRpcEventHandler extends XmlRpcHttpServer implements EventHandler { - public static final String module = XmlRpcEventHandler.class.getName(); - protected LocalDispatcher dispatcher; + public static final String MODULE = XmlRpcEventHandler.class.getName(); + private LocalDispatcher dispatcher; private Boolean enabledForExtensions = null; private Boolean enabledForExceptions = null; + LocalDispatcher getDispatcher() { + return dispatcher; + } + @Override public void init(ServletContext context) throws EventHandlerException { String delegatorName = context.getInitParameter("entityDelegatorName"); @@ -97,15 +100,16 @@ public void init(ServletContext context) throws EventHandlerException { } @Override - public String invoke(Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException { - String report = request.getParameter("echo"); + public String invoke(Event event, RequestMap requestMap, HttpServletRequest req, HttpServletResponse res) + throws EventHandlerException { + String report = req.getParameter("echo"); if (report != null) { BufferedReader reader = null; StringBuilder buf = new StringBuilder(); try { // read the inputstream buffer String line; - reader = new BufferedReader(new InputStreamReader(request.getInputStream())); + reader = new BufferedReader(new InputStreamReader(req.getInputStream())); while ((line = reader.readLine()) != null) { buf.append(line).append("\n"); } @@ -120,12 +124,12 @@ public String invoke(Event event, RequestMap requestMap, HttpServletRequest requ } } } - Debug.logInfo("Echo: " + buf.toString(), module); + Debug.logInfo("Echo: " + buf.toString(), MODULE); // echo back the request try { - response.setContentType("text/xml"); - Writer out = response.getWriter(); + res.setContentType("text/xml"); + Writer out = res.getWriter(); out.write(""); out.write(""); out.write(""); @@ -140,9 +144,9 @@ public String invoke(Event event, RequestMap requestMap, HttpServletRequest requ } } else { try { - this.execute(this.getXmlRpcConfig(request), new HttpStreamConnection(request, response)); + this.execute(this.getXmlRpcConfig(req), new HttpStreamConnection(req, res)); } catch (XmlRpcException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); throw new EventHandlerException(e.getMessage(), e); } } @@ -152,10 +156,11 @@ public String invoke(Event event, RequestMap requestMap, HttpServletRequest requ @Override protected void setResponseHeader(ServerStreamConnection con, String header, String value) { - ((HttpStreamConnection) con).getResponse().setHeader(header, value); + HttpStreamConnection hscon = (HttpStreamConnection) con; + hscon.getResponse().setHeader(header, value); } - protected XmlRpcHttpRequestConfig getXmlRpcConfig(HttpServletRequest req) { + private XmlRpcHttpRequestConfig getXmlRpcConfig(HttpServletRequest req) { OFBizXmlRpcHttpRequestConfigImpl result = new OFBizXmlRpcHttpRequestConfigImpl(req); XmlRpcHttpServerConfig serverConfig = (XmlRpcHttpServerConfig) getConfig(); @@ -178,12 +183,12 @@ protected XmlRpcHttpRequestConfig getXmlRpcConfig(HttpServletRequest req) { return result; } - class OfbizRpcAuthHandler implements AbstractReflectiveHandlerMapping.AuthenticationHandler { + final class OfbizRpcAuthHandler implements AbstractReflectiveHandlerMapping.AuthenticationHandler { @Override public boolean isAuthorized(XmlRpcRequest xmlRpcReq) throws XmlRpcException { - OFBizXmlRpcHttpRequestConfigImpl config = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); - LocalDispatcher dispatcher = config.getDispatcher(); + OFBizXmlRpcHttpRequestConfigImpl config = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); + LocalDispatcher dispatcher = config.getDispatcher(); ModelService model; try { @@ -218,8 +223,7 @@ public boolean isAuthorized(XmlRpcRequest xmlRpcReq) throws XmlRpcException { } @Override - public void execute(XmlRpcStreamRequestConfig pConfig, - ServerStreamConnection pConnection) throws XmlRpcException { + public void execute(XmlRpcStreamRequestConfig pConfig, ServerStreamConnection pConnection) throws XmlRpcException { try { Object result = null; boolean foundError = false; @@ -228,7 +232,7 @@ public void execute(XmlRpcStreamRequestConfig pConfig, XmlRpcRequest request = getRequest(pConfig, istream); result = execute(request); } catch (Exception e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); foundError = true; } @@ -246,7 +250,8 @@ public void execute(XmlRpcStreamRequestConfig pConfig, if (!foundError) { writeResponse(pConfig, ostream, result); } else { - writeError(pConfig, ostream, new Exception("Failed to read XML-RPC request. Please check logs for more information")); + writeError(pConfig, ostream, + new Exception("Failed to read XML-RPC request. Please check logs for more information")); } } @@ -309,7 +314,7 @@ public Object getParameter(int pIndex) { class ServiceRpcHandler extends AbstractReflectiveHandlerMapping implements XmlRpcHandler { - public ServiceRpcHandler() { + ServiceRpcHandler() { this.setAuthenticationHandler(new OfbizRpcAuthHandler()); } @@ -319,7 +324,7 @@ public XmlRpcHandler getHandler(String method) throws XmlRpcNoSuchHandlerExcepti try { model = dispatcher.getDispatchContext().getModelService(method); } catch (GenericServiceException e) { - Debug.logWarning(e, module); + Debug.logWarning(e, MODULE); } if (model == null) { throw new XmlRpcNoSuchHandlerException("No such service [" + method + "]"); @@ -330,9 +335,9 @@ public XmlRpcHandler getHandler(String method) throws XmlRpcNoSuchHandlerExcepti @Override public Object execute(XmlRpcRequest xmlRpcReq) throws XmlRpcException { - OFBizXmlRpcHttpRequestConfigImpl requestConfig = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); - LocalDispatcher dispatcher = requestConfig.getDispatcher(); - + OFBizXmlRpcHttpRequestConfigImpl requestConfig = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); + LocalDispatcher dispatcher = requestConfig.getDispatcher(); + DispatchContext dctx = dispatcher.getDispatchContext(); String serviceName = xmlRpcReq.getMethodName(); ModelService model = null; @@ -372,7 +377,7 @@ public Object execute(XmlRpcRequest xmlRpcReq) throws XmlRpcException { throw new XmlRpcException(e.getMessage(), e); } if (ServiceUtil.isError(resp)) { - Debug.logError(ServiceUtil.getErrorMessage(resp), module); + Debug.logError(ServiceUtil.getErrorMessage(resp), MODULE); throw new XmlRpcException(ServiceUtil.getErrorMessage(resp)); } @@ -382,8 +387,8 @@ public Object execute(XmlRpcRequest xmlRpcReq) throws XmlRpcException { protected Map getContext(XmlRpcRequest xmlRpcReq, String serviceName) throws XmlRpcException { ModelService model; - OFBizXmlRpcHttpRequestConfigImpl requestConfig = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); - LocalDispatcher dispatcher = requestConfig.getDispatcher(); + OFBizXmlRpcHttpRequestConfigImpl requestConfig = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); + LocalDispatcher dispatcher = requestConfig.getDispatcher(); try { model = dispatcher.getDispatchContext().getModelService(serviceName); } catch (GenericServiceException e) { @@ -408,18 +413,18 @@ protected Map getContext(XmlRpcRequest xmlRpcReq, String service } } - // only one parameter; if its a map use it as the context; otherwise make sure the service takes one param + // only one parameter; if its a map use it as the context; + // otherwise make sure the service takes one param. } else if (parameterCount == 1) { Object param = xmlRpcReq.getParameter(0); if (param instanceof Map) { context = checkMap(param, String.class, Object.class); + } else if (model.getDefinedInCount() == 1) { + String paramName = model.getInParamNames().iterator().next(); + context.put(paramName, xmlRpcReq.getParameter(0)); } else { - if (model.getDefinedInCount() == 1) { - String paramName = model.getInParamNames().iterator().next(); - context.put(paramName, xmlRpcReq.getParameter(0)); - } else { - throw new XmlRpcException("More than one parameter defined on service; cannot call via RPC with parameter list"); - } + throw new XmlRpcException( + "More than one parameter defined on service; cannot call via RPC with parameter list"); } } @@ -433,8 +438,8 @@ protected Map getContext(XmlRpcRequest xmlRpcReq, String service class HttpStreamConnection implements ServerStreamConnection { - protected HttpServletRequest request; - protected HttpServletResponse response; + private HttpServletRequest request; + private HttpServletResponse response; protected HttpStreamConnection(HttpServletRequest req, HttpServletResponse res) { this.request = req; @@ -466,17 +471,15 @@ public void close() throws IOException { } } - class OFBizXmlRpcHttpRequestConfigImpl extends XmlRpcHttpRequestConfigImpl { + class OFBizXmlRpcHttpRequestConfigImpl extends XmlRpcHttpRequestConfigImpl { private LocalDispatcher dispatcher; - public OFBizXmlRpcHttpRequestConfigImpl (HttpServletRequest request) { - dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + OFBizXmlRpcHttpRequestConfigImpl(HttpServletRequest request) { + dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); } - + public LocalDispatcher getDispatcher() { - return dispatcher; + return dispatcher; } } - - }