Skip to content

Instantly share code, notes, and snippets.

@yaniv691
Created September 10, 2014 10:53
Show Gist options
  • Save yaniv691/eb9997f4a2da8efeedfc to your computer and use it in GitHub Desktop.
Save yaniv691/eb9997f4a2da8efeedfc to your computer and use it in GitHub Desktop.
package com.xyz;
import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServerConfig;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.XmlRpcServletServer;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
/**
* @author elad
*/
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private XmlRpcServletServer server;
@Inject
private HandlerRegistrator registrator;
@Override
public void init() throws ServletException {
super.init();
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
setup();
}
private void setup() {
server = new XmlRpcServletServer();
setupHandlers();
setupConfig();
}
private void setupHandlers() {
XmlRpcHandlerMapping mapping = registrator.getMapping();
server.setHandlerMapping(mapping);
}
private void setupConfig() {
XmlRpcServerConfig pConfig = createConfig();
server.setConfig(pConfig);
}
private XmlRpcServerConfig createConfig() {
XmlRpcServerConfigImpl config = new XmlRpcServerConfigImpl();
config.setEnabledForExtensions(true);
return config;
}
@Override
public void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, ServletException {
server.execute(pRequest, pResponse);
}
@Override
public void log(String pMessage, Throwable pThrowable) {
server.getErrorLogger().log(pMessage, pThrowable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment