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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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");
}
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
try {
response.setContentType("text/xml");
Writer out = response.getWriter();
res.setContentType("text/xml");
Writer out = res.getWriter();
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.write("<methodResponse>");
out.write("<params><param>");
Expand All @@ -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);
}
}
Expand All @@ -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();

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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"));
}
}

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

class ServiceRpcHandler extends AbstractReflectiveHandlerMapping implements XmlRpcHandler {

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

Expand All @@ -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 + "]");
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}

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

protected Map<String, Object> 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) {
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) {
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");
}
}

Expand All @@ -433,8 +438,8 @@ protected Map<String, Object> 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;
Expand Down Expand Up @@ -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;
}
}


}

0 comments on commit 4cc9ba8

Please sign in to comment.