private final HttpPost createHttpPost(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws IOException { final HttpEntity httpEntity = buildEntity(options, classNameParameters, parametersValues); final StringBuilder sBuilder = new StringBuilder(serverUrl); sBuilder.append(SLASH).append(applicationName).append(SERVER_API).append(apiInterfaceName).append(SLASH).append(methodName); final HttpPost httpPost = new HttpPost(sBuilder.toString()); httpPost.setEntity(httpEntity); // Basic authentication if (basicAuthenticationActive) { final StringBuilder credentials = new StringBuilder(); credentials.append(basicAuthenticationUserName).append(":").append(basicAuthenticationPassword); final Base64 encoder = new Base64(); final String encodedCredentials = encoder.encodeAsString(credentials.toString().getBytes("UTF-8")); httpPost.setHeader("Authorization", "Basic " + encodedCredentials); } return httpPost; }
@Override public Object invokeMethod(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws ServerWrappedException { String response = null; try { response = executeHttpPost(options, apiInterfaceName, methodName, classNameParameters, parametersValues); return checkInvokeMethodReturn(response); } catch (final UndeclaredThrowableException e) { throw new ServerWrappedException(e); } catch (final Throwable e) { final StackTraceElement[] stackTrace = new Exception().getStackTrace(); StackTraceTransformer.addStackTo(e, stackTrace); throw new ServerWrappedException(e.getMessage() + " / response: " + response, e); } }
String executeHttpPost(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws IOException { final HttpPost httpost = createHttpPost(options, apiInterfaceName, methodName, classNameParameters, parametersValues); try { return httpclient.execute(httpost, RESPONSE_HANDLER); } catch (final ClientProtocolException e) { String httpCodeMessage = ""; // required as the http code is not included in the exception message if (e instanceof HttpResponseException) { final int statusCode = ((HttpResponseException) e).getStatusCode(); httpCodeMessage = format(" (http code: %s)", statusCode); } throw new IOException("Error while executing POST request" + httpCodeMessage + " <" + httpost + ">", e); } }
ServerAPI getServerAPI() throws ServerAPIException, UnknownAPITypeException { try { final ApiAccessType apiType = APITypeManager.getAPIType(); Map<String, String> parameters; switch (apiType) { case LOCAL: return LocalServerAPIFactory.getServerAPI(); case EJB3: parameters = APITypeManager.getAPITypeParameters(); return new EJB3ServerAPI(parameters); case HTTP: parameters = APITypeManager.getAPITypeParameters(); return new HTTPServerAPI(parameters); case TCP: parameters = APITypeManager.getAPITypeParameters(); return new TCPServerAPI(parameters); default: throw new UnknownAPITypeException("Unsupported API Type: " + apiType); } } catch (IOException e) { throw new ServerAPIException(e); } }
int i = 0; for (final Object object : bytearrayParameters) { entityBuilder.addPart(BINARY_PARAMETER + i, new ByteArrayBody(serialize(object), BINARY_PARAMETER + i)); i++;
ServerAPI getServerAPI() throws ServerAPIException, UnknownAPITypeException { try { final ApiAccessType apiType = APITypeManager.getAPIType(); Map<String, String> parameters; switch (apiType) { case LOCAL: return LocalServerAPIFactory.getServerAPI(); case EJB3: parameters = APITypeManager.getAPITypeParameters(); return new EJB3ServerAPI(parameters); case HTTP: parameters = APITypeManager.getAPITypeParameters(); return new HTTPServerAPI(parameters); case TCP: parameters = APITypeManager.getAPITypeParameters(); return new TCPServerAPI(parameters); default: throw new UnknownAPITypeException("Unsupported API Type: " + apiType); } } catch (IOException e) { throw new ServerAPIException(e); } }
int i = 0; for (final Object object : bytearrayParameters) { entityBuilder.addPart(BINARY_PARAMETER + i, new ByteArrayBody(serialize(object), BINARY_PARAMETER + i)); i++;
@Override public Object invokeMethod(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws ServerWrappedException { String response = null; try { response = executeHttpPost(options, apiInterfaceName, methodName, classNameParameters, parametersValues); return checkInvokeMethodReturn(response); } catch (final UndeclaredThrowableException e) { throw new ServerWrappedException(e); } catch (final Throwable e) { final StackTraceElement[] stackTrace = new Exception().getStackTrace(); StackTraceTransformer.addStackTo(e, stackTrace); throw new ServerWrappedException(e.getMessage() + " / response: " + response, e); } }
static ServerAPI getServerAPI() throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException { try { final ApiAccessType apiType = APITypeManager.getAPIType(); Map<String, String> parameters; switch (apiType) { case LOCAL: return LocalServerAPIFactory.getServerAPI(); case EJB3: parameters = APITypeManager.getAPITypeParameters(); return new EJB3ServerAPI(parameters); case HTTP: parameters = APITypeManager.getAPITypeParameters(); return new HTTPServerAPI(parameters); case TCP: parameters = APITypeManager.getAPITypeParameters(); return new TCPServerAPI(parameters); default: throw new UnknownAPITypeException("Unsupported API Type: " + apiType); } } catch (IOException e) { throw new ServerAPIException(e); } }
String executeHttpPost(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws IOException { final HttpPost httpost = createHttpPost(options, apiInterfaceName, methodName, classNameParameters, parametersValues); try { return httpclient.execute(httpost, RESPONSE_HANDLER); } catch (final ClientProtocolException e) { String httpCodeMessage = ""; // required as the http code is not included in the exception message if (e instanceof HttpResponseException) { final int statusCode = ((HttpResponseException) e).getStatusCode(); httpCodeMessage = format(" (http code: %s)", statusCode); } throw new IOException("Error while executing POST request" + httpCodeMessage + " <" + httpost + ">", e); } }
private final HttpPost createHttpPost(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws IOException { final HttpEntity httpEntity = buildEntity(options, classNameParameters, parametersValues); final StringBuilder sBuilder = new StringBuilder(serverUrl); sBuilder.append(SLASH).append(applicationName).append(SERVER_API).append(apiInterfaceName).append(SLASH).append(methodName); final HttpPost httpPost = new HttpPost(sBuilder.toString()); httpPost.setEntity(httpEntity); // Basic authentication if (basicAuthenticationActive) { final StringBuilder credentials = new StringBuilder(); credentials.append(basicAuthenticationUserName).append(":").append(basicAuthenticationPassword); final Base64 encoder = new Base64(); final String encodedCredentials = encoder.encodeAsString(credentials.toString().getBytes("UTF-8")); httpPost.setHeader("Authorization", "Basic " + encodedCredentials); } return httpPost; }
static ServerAPI getServerAPI() throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException { try { final ApiAccessType apiType = APITypeManager.getAPIType(); Map<String, String> parameters; switch (apiType) { case LOCAL: return LocalServerAPIFactory.getServerAPI(); case EJB3: parameters = APITypeManager.getAPITypeParameters(); return new EJB3ServerAPI(parameters); case HTTP: parameters = APITypeManager.getAPITypeParameters(); return new HTTPServerAPI(parameters); case TCP: parameters = APITypeManager.getAPITypeParameters(); return new TCPServerAPI(parameters); default: throw new UnknownAPITypeException("Unsupported API Type: " + apiType); } } catch (IOException e) { throw new ServerAPIException(e); } }