Skip to content

Commit

Permalink
Fixed: Format ‘XmlRpcEventHandler’
Browse files Browse the repository at this point in the history
(OFBIZ-10284)

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
  • Loading branch information
mthl committed Oct 19, 2019
1 parent 2de3b83 commit 4cc9ba8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -307,7 +307,7 @@ checkstyle {
// the sum of errors that were present before introducing the // the sum of errors that were present before introducing the
// ‘checkstyle’ tool present in the framework and in the official // ‘checkstyle’ tool present in the framework and in the official
// plugins. // plugins.
maxErrors = 37947 maxErrors = 37930
// Currently there are a lot of errors so we need to temporarily // Currently there are a lot of errors so we need to temporarily
// hide them to avoid polluting the terminal output. // hide them to avoid polluting the terminal output.
showViolations = false showViolations = false
Expand Down
Expand Up @@ -16,7 +16,6 @@ Licensed to the Apache Software Foundation (ASF) under one
specific language governing permissions and limitations specific language governing permissions and limitations
under the License. under the License.
*/ */

package org.apache.ofbiz.webapp.event; package org.apache.ofbiz.webapp.event;


import static org.apache.ofbiz.base.util.UtilGenerics.checkMap; import static org.apache.ofbiz.base.util.UtilGenerics.checkMap;
Expand Down Expand Up @@ -71,14 +70,18 @@ Licensed to the Apache Software Foundation (ASF) under one
/** /**
* XmlRpcEventHandler * XmlRpcEventHandler
*/ */
public class XmlRpcEventHandler extends XmlRpcHttpServer implements EventHandler { public final class XmlRpcEventHandler extends XmlRpcHttpServer implements EventHandler {


public static final String module = XmlRpcEventHandler.class.getName(); public static final String MODULE = XmlRpcEventHandler.class.getName();
protected LocalDispatcher dispatcher; private LocalDispatcher dispatcher;


private Boolean enabledForExtensions = null; private Boolean enabledForExtensions = null;
private Boolean enabledForExceptions = null; private Boolean enabledForExceptions = null;


LocalDispatcher getDispatcher() {
return dispatcher;
}

@Override @Override
public void init(ServletContext context) throws EventHandlerException { public void init(ServletContext context) throws EventHandlerException {
String delegatorName = context.getInitParameter("entityDelegatorName"); String delegatorName = context.getInitParameter("entityDelegatorName");
Expand All @@ -97,15 +100,16 @@ public void init(ServletContext context) throws EventHandlerException {
} }


@Override @Override
public String invoke(Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException { public String invoke(Event event, RequestMap requestMap, HttpServletRequest req, HttpServletResponse res)
String report = request.getParameter("echo"); throws EventHandlerException {
String report = req.getParameter("echo");
if (report != null) { if (report != null) {
BufferedReader reader = null; BufferedReader reader = null;
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
try { try {
// read the inputstream buffer // read the inputstream buffer
String line; String line;
reader = new BufferedReader(new InputStreamReader(request.getInputStream())); reader = new BufferedReader(new InputStreamReader(req.getInputStream()));
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
buf.append(line).append("\n"); buf.append(line).append("\n");
} }
Expand All @@ -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 // echo back the request
try { try {
response.setContentType("text/xml"); res.setContentType("text/xml");
Writer out = response.getWriter(); Writer out = res.getWriter();
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.write("<methodResponse>"); out.write("<methodResponse>");
out.write("<params><param>"); out.write("<params><param>");
Expand All @@ -140,9 +144,9 @@ public String invoke(Event event, RequestMap requestMap, HttpServletRequest requ
} }
} else { } else {
try { try {
this.execute(this.getXmlRpcConfig(request), new HttpStreamConnection(request, response)); this.execute(this.getXmlRpcConfig(req), new HttpStreamConnection(req, res));
} catch (XmlRpcException e) { } catch (XmlRpcException e) {
Debug.logError(e, module); Debug.logError(e, MODULE);
throw new EventHandlerException(e.getMessage(), e); throw new EventHandlerException(e.getMessage(), e);
} }
} }
Expand All @@ -152,10 +156,11 @@ public String invoke(Event event, RequestMap requestMap, HttpServletRequest requ


@Override @Override
protected void setResponseHeader(ServerStreamConnection con, String header, String value) { 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); OFBizXmlRpcHttpRequestConfigImpl result = new OFBizXmlRpcHttpRequestConfigImpl(req);
XmlRpcHttpServerConfig serverConfig = (XmlRpcHttpServerConfig) getConfig(); XmlRpcHttpServerConfig serverConfig = (XmlRpcHttpServerConfig) getConfig();


Expand All @@ -178,12 +183,12 @@ protected XmlRpcHttpRequestConfig getXmlRpcConfig(HttpServletRequest req) {
return result; return result;
} }


class OfbizRpcAuthHandler implements AbstractReflectiveHandlerMapping.AuthenticationHandler { final class OfbizRpcAuthHandler implements AbstractReflectiveHandlerMapping.AuthenticationHandler {


@Override @Override
public boolean isAuthorized(XmlRpcRequest xmlRpcReq) throws XmlRpcException { public boolean isAuthorized(XmlRpcRequest xmlRpcReq) throws XmlRpcException {
OFBizXmlRpcHttpRequestConfigImpl config = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); OFBizXmlRpcHttpRequestConfigImpl config = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig();
LocalDispatcher dispatcher = config.getDispatcher(); LocalDispatcher dispatcher = config.getDispatcher();


ModelService model; ModelService model;
try { try {
Expand Down Expand Up @@ -218,8 +223,7 @@ public boolean isAuthorized(XmlRpcRequest xmlRpcReq) throws XmlRpcException {
} }


@Override @Override
public void execute(XmlRpcStreamRequestConfig pConfig, public void execute(XmlRpcStreamRequestConfig pConfig, ServerStreamConnection pConnection) throws XmlRpcException {
ServerStreamConnection pConnection) throws XmlRpcException {
try { try {
Object result = null; Object result = null;
boolean foundError = false; boolean foundError = false;
Expand All @@ -228,7 +232,7 @@ public void execute(XmlRpcStreamRequestConfig pConfig,
XmlRpcRequest request = getRequest(pConfig, istream); XmlRpcRequest request = getRequest(pConfig, istream);
result = execute(request); result = execute(request);
} catch (Exception e) { } catch (Exception e) {
Debug.logError(e, module); Debug.logError(e, MODULE);
foundError = true; foundError = true;
} }


Expand All @@ -246,7 +250,8 @@ public void execute(XmlRpcStreamRequestConfig pConfig,
if (!foundError) { if (!foundError) {
writeResponse(pConfig, ostream, result); writeResponse(pConfig, ostream, result);
} else { } 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"));
} }
} }


Expand Down Expand Up @@ -309,7 +314,7 @@ public Object getParameter(int pIndex) {


class ServiceRpcHandler extends AbstractReflectiveHandlerMapping implements XmlRpcHandler { class ServiceRpcHandler extends AbstractReflectiveHandlerMapping implements XmlRpcHandler {


public ServiceRpcHandler() { ServiceRpcHandler() {
this.setAuthenticationHandler(new OfbizRpcAuthHandler()); this.setAuthenticationHandler(new OfbizRpcAuthHandler());
} }


Expand All @@ -319,7 +324,7 @@ public XmlRpcHandler getHandler(String method) throws XmlRpcNoSuchHandlerExcepti
try { try {
model = dispatcher.getDispatchContext().getModelService(method); model = dispatcher.getDispatchContext().getModelService(method);
} catch (GenericServiceException e) { } catch (GenericServiceException e) {
Debug.logWarning(e, module); Debug.logWarning(e, MODULE);
} }
if (model == null) { if (model == null) {
throw new XmlRpcNoSuchHandlerException("No such service [" + method + "]"); throw new XmlRpcNoSuchHandlerException("No such service [" + method + "]");
Expand All @@ -330,9 +335,9 @@ public XmlRpcHandler getHandler(String method) throws XmlRpcNoSuchHandlerExcepti
@Override @Override
public Object execute(XmlRpcRequest xmlRpcReq) throws XmlRpcException { public Object execute(XmlRpcRequest xmlRpcReq) throws XmlRpcException {


OFBizXmlRpcHttpRequestConfigImpl requestConfig = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); OFBizXmlRpcHttpRequestConfigImpl requestConfig = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig();
LocalDispatcher dispatcher = requestConfig.getDispatcher(); LocalDispatcher dispatcher = requestConfig.getDispatcher();

DispatchContext dctx = dispatcher.getDispatchContext(); DispatchContext dctx = dispatcher.getDispatchContext();
String serviceName = xmlRpcReq.getMethodName(); String serviceName = xmlRpcReq.getMethodName();
ModelService model = null; ModelService model = null;
Expand Down Expand Up @@ -372,7 +377,7 @@ public Object execute(XmlRpcRequest xmlRpcReq) throws XmlRpcException {
throw new XmlRpcException(e.getMessage(), e); throw new XmlRpcException(e.getMessage(), e);
} }
if (ServiceUtil.isError(resp)) { if (ServiceUtil.isError(resp)) {
Debug.logError(ServiceUtil.getErrorMessage(resp), module); Debug.logError(ServiceUtil.getErrorMessage(resp), MODULE);
throw new XmlRpcException(ServiceUtil.getErrorMessage(resp)); throw new XmlRpcException(ServiceUtil.getErrorMessage(resp));
} }


Expand All @@ -382,8 +387,8 @@ public Object execute(XmlRpcRequest xmlRpcReq) throws XmlRpcException {


protected Map<String, Object> getContext(XmlRpcRequest xmlRpcReq, String serviceName) throws XmlRpcException { protected Map<String, Object> getContext(XmlRpcRequest xmlRpcReq, String serviceName) throws XmlRpcException {
ModelService model; ModelService model;
OFBizXmlRpcHttpRequestConfigImpl requestConfig = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig(); OFBizXmlRpcHttpRequestConfigImpl requestConfig = (OFBizXmlRpcHttpRequestConfigImpl) xmlRpcReq.getConfig();
LocalDispatcher dispatcher = requestConfig.getDispatcher(); LocalDispatcher dispatcher = requestConfig.getDispatcher();
try { try {
model = dispatcher.getDispatchContext().getModelService(serviceName); model = dispatcher.getDispatchContext().getModelService(serviceName);
} catch (GenericServiceException e) { } catch (GenericServiceException e) {
Expand All @@ -408,18 +413,18 @@ protected Map<String, Object> 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) { } else if (parameterCount == 1) {
Object param = xmlRpcReq.getParameter(0); Object param = xmlRpcReq.getParameter(0);
if (param instanceof Map<?, ?>) { if (param instanceof Map<?, ?>) {
context = checkMap(param, String.class, Object.class); 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 { } else {
if (model.getDefinedInCount() == 1) { throw new XmlRpcException(
String paramName = model.getInParamNames().iterator().next(); "More than one parameter defined on service; cannot call via RPC with parameter list");
context.put(paramName, xmlRpcReq.getParameter(0));
} else {
throw new XmlRpcException("More than one parameter defined on service; cannot call via RPC with parameter list");
}
} }
} }


Expand All @@ -433,8 +438,8 @@ protected Map<String, Object> getContext(XmlRpcRequest xmlRpcReq, String service


class HttpStreamConnection implements ServerStreamConnection { class HttpStreamConnection implements ServerStreamConnection {


protected HttpServletRequest request; private HttpServletRequest request;
protected HttpServletResponse response; private HttpServletResponse response;


protected HttpStreamConnection(HttpServletRequest req, HttpServletResponse res) { protected HttpStreamConnection(HttpServletRequest req, HttpServletResponse res) {
this.request = req; this.request = req;
Expand Down Expand Up @@ -466,17 +471,15 @@ public void close() throws IOException {
} }
} }


class OFBizXmlRpcHttpRequestConfigImpl extends XmlRpcHttpRequestConfigImpl { class OFBizXmlRpcHttpRequestConfigImpl extends XmlRpcHttpRequestConfigImpl {
private LocalDispatcher dispatcher; private LocalDispatcher dispatcher;


public OFBizXmlRpcHttpRequestConfigImpl (HttpServletRequest request) { OFBizXmlRpcHttpRequestConfigImpl(HttpServletRequest request) {
dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
} }

public LocalDispatcher getDispatcher() { public LocalDispatcher getDispatcher() {
return dispatcher; return dispatcher;
} }
} }


} }

0 comments on commit 4cc9ba8

Please sign in to comment.