
org.bonitasoft.engine.api.internal.servlet.HttpAPIServletCall Maven / Gradle / Ivy
/**
* Copyright (C) 2012 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.api.internal.servlet;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileUploadException;
import org.bonitasoft.engine.api.impl.ServerAPIImpl;
import org.bonitasoft.engine.api.internal.ServerWrappedException;
import org.bonitasoft.engine.exception.BonitaRuntimeException;
import com.thoughtworks.xstream.XStream;
/**
* @author Julien Mege
*/
public class HttpAPIServletCall extends ServletCall {
private static final String SLASH = "/";
private static final String ARRAY = "[]";
private static final String NULL = "null";
private static final String BYTE_ARRAY = "==ByteArray==";
private static final String CLASS_NAME_PARAMETERS = "classNameParameters";
private static final String PARAMETERS_VALUES = "parametersValues";
private static final String OPTIONS = "options";
public HttpAPIServletCall(final HttpServletRequest request, final HttpServletResponse response) throws FileUploadException, IOException {
super(request, response);
}
@Override
public void doGet() {
error("GET method forbidden", HttpServletResponse.SC_FORBIDDEN);
}
@Override
public void doPost() {
try {
String apiInterfaceName = null;
String methodName = null;
final String[] pathParams = getRequestURL().split(SLASH);
if (pathParams != null && pathParams.length >= 2) {
apiInterfaceName = pathParams[pathParams.length - 2];
methodName = pathParams[pathParams.length - 1];
}
final String options = this.getParameter(OPTIONS);
final String parametersValues = this.getParameter(PARAMETERS_VALUES);
final String parametersClasses = this.getParameter(CLASS_NAME_PARAMETERS);
final XStream xstream = new XStream();
TreeMap myOptions = new TreeMap();
if (options != null && !options.isEmpty()) {
myOptions = this.> fromXML(options, xstream);
}
List myClassNameParameters = new ArrayList();
if (parametersClasses != null && !parametersClasses.isEmpty() && !parametersClasses.equals(ARRAY)) {
myClassNameParameters = this.> fromXML(parametersClasses, xstream);
}
Object[] myParametersValues = new Object[0];
if (parametersValues != null && !parametersValues.isEmpty() && !parametersValues.equals(NULL)) {
myParametersValues = this.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy