use of com.hp.oo.sdk.content.plugin.SerializableSessionObject in project cs-actions by CloudSlang.
the class CookieStoreBuilderTest method buildCookieStoreWithoutCookies.
@Test
public void buildCookieStoreWithoutCookies() throws IOException {
BasicCookieStore basicCookieStore = new BasicCookieStore();
SerializableSessionObject sessionObjectHolder = new SerializableSessionObject();
sessionObjectHolder.setValue(CookieStoreBuilder.serialize(basicCookieStore));
BasicCookieStore cookieStore = (BasicCookieStore) cookieStoreBuilder.setUseCookies("false").buildCookieStore();
assertNull(cookieStore);
}
use of com.hp.oo.sdk.content.plugin.SerializableSessionObject in project cs-actions by CloudSlang.
the class CookieStoreBuilderTest method buildCookieStore.
@Test
public void buildCookieStore() {
SerializableSessionObject sessionObjectHolder = new SerializableSessionObject();
CookieStore cookieStore = cookieStoreBuilder.setCookieStoreSessionObject(sessionObjectHolder).buildCookieStore();
assertNotNull(cookieStore);
assertEquals(0, cookieStore.getCookies().size());
}
use of com.hp.oo.sdk.content.plugin.SerializableSessionObject in project cs-actions by CloudSlang.
the class HttpClientService method execute.
public static Map<String, String> execute(HttpClientInputs httpClientInputs) throws Exception {
URI uri = UriBuilder.getUri(httpClientInputs);
HttpUriRequestBase httpRequest = new HttpUriRequestBase(httpClientInputs.getMethod(), uri);
SSLConnectionSocketFactory socketFactory = CustomSSLSocketFactory.createSSLSocketFactory(httpClientInputs);
CustomConnectionManager customConnectionManager = new CustomConnectionManager();
GlobalSessionObject globalSessionObject = httpClientInputs.getConnectionPoolSessionObject();
if (globalSessionObject == null)
customConnectionManager.setConnectionPoolHolder(new GlobalSessionObject());
else
customConnectionManager.setConnectionPoolHolder(httpClientInputs.getConnectionPoolSessionObject());
String connectionKey = CustomConnectionManager.buildConnectionManagerMapKey(httpClientInputs.getTrustAllRoots(), httpClientInputs.getX509HostnameVerifier(), httpClientInputs.getKeystore(), httpClientInputs.getTrustKeystore());
customConnectionManager.setConnectionManagerMapKey(connectionKey);
SerializableSessionObject cookieStoreSessionObject = httpClientInputs.getCookieStoreSessionObject();
if (cookieStoreSessionObject == null) {
cookieStoreSessionObject = new SerializableSessionObject();
}
CookieStore cookieStore = CookieStoreBuilder.buildCookieStore(cookieStoreSessionObject, httpClientInputs.getUseCookies());
PoolingHttpClientConnectionManager connectionManager = customConnectionManager.getConnectionManager(httpClientInputs, socketFactory, uri);
CredentialsProvider credentialsProvider = CustomCredentialsProvider.getCredentialsProvider(httpClientInputs, uri);
RequestConfig requestConfig = CustomRequestConfig.getDefaultRequestConfig(httpClientInputs);
HttpClientContext context = CustomHttpClientContext.getHttpClientContext(httpClientInputs, credentialsProvider, uri);
HttpEntity httpEntity = CustomEntity.getHttpEntity(httpClientInputs);
httpRequest.setEntity(httpEntity);
HeaderBuilder.headerBuiler(httpRequest, httpClientInputs);
HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig);
if (cookieStore != null)
httpClientBuilder.setDefaultCookieStore(cookieStore);
CloseableHttpClient httpclient = httpClientBuilder.build();
Map<String, String> result = new HashMap<>();
if (httpClientInputs.getExecutionTimeout().equals(ZERO))
try (final CloseableHttpResponse response = httpclient.execute(httpRequest, context)) {
ResponseHandler.consume(result, response, httpClientInputs.getResponseCharacterSet(), httpClientInputs.getDestinationFile());
ResponseHandler.getResponseHeaders(result, response.getHeaders());
ResponseHandler.getStatusResponse(result, response);
ResponseHandler.getFinalLocationResponse(result, uri, context.getRedirectLocations().getAll());
}
else
ExecutionTimeout.runWithTimeout(new Runnable() {
@Override
public void run() {
try (final CloseableHttpResponse response = httpclient.execute(httpRequest, context)) {
ResponseHandler.consume(result, response, httpClientInputs.getResponseCharacterSet(), httpClientInputs.getDestinationFile());
ResponseHandler.getResponseHeaders(result, response.getHeaders());
ResponseHandler.getStatusResponse(result, response);
ResponseHandler.getFinalLocationResponse(result, uri, context.getRedirectLocations().getAll());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, Integer.parseInt(httpClientInputs.getExecutionTimeout()), TimeUnit.SECONDS);
if (cookieStore != null) {
try {
cookieStoreSessionObject.setValue(CookieStoreBuilder.serialize(cookieStore));
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
result.put(RETURN_CODE, SUCCESS);
return result;
}
use of com.hp.oo.sdk.content.plugin.SerializableSessionObject in project cloud-slang by CloudSlang.
the class ActionExecutionData method doAction.
public void doAction(@Param(EXECUTION_RUNTIME_SERVICES) ExecutionRuntimeServices executionRuntimeServices, @Param(ScoreLangConstants.RUN_ENV) RunEnvironment runEnv, @Param(ExecutionParametersConsts.NON_SERIALIZABLE_EXECUTION_DATA) Map<String, Map<String, Object>> nonSerializableExecutionData, @Param(ScoreLangConstants.NEXT_STEP_ID_KEY) Long nextStepId, @Param(ScoreLangConstants.ACTION_TYPE) ActionType actionType, @Param(ScoreLangConstants.JAVA_ACTION_CLASS_KEY) String className, @Param(ScoreLangConstants.JAVA_ACTION_METHOD_KEY) String methodName, @Param(ScoreLangConstants.JAVA_ACTION_GAV_KEY) String gav, @Param(ScoreLangConstants.PYTHON_ACTION_SCRIPT_KEY) String script, @Param(ScoreLangConstants.PYTHON_ACTION_USE_JYTHON_KEY) Boolean useJython, @Param(ScoreLangConstants.PYTHON_ACTION_DEPENDENCIES_KEY) Collection<String> dependencies, @Param(ScoreLangConstants.SEQ_STEPS_KEY) List<SeqStep> steps, @Param(ScoreLangConstants.SEQ_EXTERNAL_KEY) Boolean external, @Param(ExecutionParametersConsts.EXECUTION) Serializable execution) {
Map<String, Value> returnValue = new HashMap<>();
Map<String, Value> callArguments = runEnv.removeCallArguments();
Map<String, Value> callArgumentsDeepCopy = new HashMap<>();
for (Map.Entry<String, Value> entry : callArguments.entrySet()) {
callArgumentsDeepCopy.put(entry.getKey(), ValueFactory.create(entry.getValue()));
}
Map<String, SerializableSessionObject> serializableSessionData = runEnv.getSerializableDataMap();
fireEvent(executionRuntimeServices, ScoreLangConstants.EVENT_ACTION_START, "Preparing to run action " + actionType, runEnv.getExecutionPath().getParentPath(), LanguageEventData.StepType.ACTION, null, callArgumentsDeepCopy, Pair.of(LanguageEventData.CALL_ARGUMENTS, (Serializable) callArgumentsDeepCopy));
try {
switch(actionType) {
case JAVA:
returnValue = runJavaAction(serializableSessionData, callArguments, nonSerializableExecutionData, gav, className, methodName, executionRuntimeServices.getNodeNameWithDepth(), runEnv.getParentFlowStack().size());
break;
case PYTHON:
returnValue = prepareAndRunPythonAction(dependencies, script, callArguments, useJython);
break;
case SEQUENTIAL:
returnValue = runSequentialAction(callArguments, gav, steps, Boolean.TRUE.equals(external), execution, runEnv, nextStepId);
break;
default:
break;
}
if (stepDataConsumer != null) {
stepDataConsumer.consumeStepData(callArguments, returnValue);
}
} catch (RuntimeException ex) {
fireEvent(executionRuntimeServices, ScoreLangConstants.EVENT_ACTION_ERROR, ex.getMessage(), runEnv.getExecutionPath().getParentPath(), LanguageEventData.StepType.ACTION, null, callArgumentsDeepCopy, Pair.of(LanguageEventData.EXCEPTION, ex.getMessage()));
logger.error(ex);
throw (ex);
}
ReturnValues returnValues = new ReturnValues(returnValue, null);
runEnv.putReturnValues(returnValues);
fireEvent(executionRuntimeServices, ScoreLangConstants.EVENT_ACTION_END, "Action performed", runEnv.getExecutionPath().getParentPath(), LanguageEventData.StepType.ACTION, null, callArgumentsDeepCopy);
if (!SEQUENTIAL.equals(actionType.getValue())) {
/*
Due to the way Sequential Actions work, we have to pause the execution BEFORE the actual run.
Thus, we have to populate the run environment with the required data before pausing and persisting.
We let the sequential action handler do it, since here it would be too late.
*/
runEnv.putNextStepPosition(nextStepId);
}
}
use of com.hp.oo.sdk.content.plugin.SerializableSessionObject in project cloud-slang by CloudSlang.
the class ActionStepsTest method doJavaActionGetNonExistingKeyFromNonExistingSerializableSessionTest.
@Test(timeout = DEFAULT_TIMEOUT)
public void doJavaActionGetNonExistingKeyFromNonExistingSerializableSessionTest() {
// prepare doAction arguments
RunEnvironment runEnv = new RunEnvironment();
Map<String, Value> initialCallArguments = new HashMap<>();
runEnv.putCallArguments(initialCallArguments);
// invoke doAction
actionSteps.doAction(executionRuntimeServicesMock, runEnv, nonSerializableExecutionData, 2L, JAVA, ContentTestActions.class.getName(), "getNameFromSerializableSession", GAV_DEFAULT, null, true, DEPENDENCIES_DEFAULT, seqSteps, null, null);
Map<String, SerializableSessionObject> serializableSessionMap = runEnv.getSerializableDataMap();
Assert.assertTrue(serializableSessionMap.containsKey("name"));
}
Aggregations