use of com.axway.ats.agent.webapp.client.ArgumentWrapper in project ats-framework by Axway.
the class RemoteExecutor method executeAction.
@Override
public Object executeAction(ActionRequest actionRequest) throws AgentException {
String actionName = actionRequest.getActionName();
String componentName = actionRequest.getComponentName();
Object[] arguments = actionRequest.getArguments();
Object result = null;
List<ArgumentWrapper> wrappedArguments = new ArrayList<ArgumentWrapper>();
try {
//a byte stream
for (Object argument : arguments) {
ArgumentWrapper argWrapper = new ArgumentWrapper();
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
objectOutStream.writeObject(argument);
argWrapper.setArgumentValue(byteOutStream.toByteArray());
wrappedArguments.add(argWrapper);
}
} catch (IOException ioe) {
throw new AgentException("Could not serialize input arguments", ioe);
}
//get the client
AgentService agentServicePort = AgentServicePool.getInstance().getClient(atsAgent);
try {
//FIXME: swap with ActionWrapper
byte[] resultAsBytes = agentServicePort.executeAction(componentName, actionName, wrappedArguments);
//the result is returned as serialized stream
//so we need to deserialize it
ByteArrayInputStream byteInStream = new ByteArrayInputStream(resultAsBytes);
ObjectInputStream objectInStream = new ObjectInputStream(byteInStream);
result = objectInStream.readObject();
} catch (IOException ioe) {
throw new AgentException("Could not deserialize returned result from agent at " + atsAgent, ioe);
} catch (AgentException_Exception ae) {
throw new AgentException("Error while executing action on agent at " + atsAgent + ". Exception message: " + ae.getMessage());
} catch (InternalComponentException_Exception ice) {
//we need to get internal component exception info from the soap fault
InternalComponentException faultInfo = ice.getFaultInfo();
//then construct and throw a real InternalComponentException (not the JAXB mapping type above)
throw new com.axway.ats.agent.core.exceptions.InternalComponentException(faultInfo.getComponentName(), faultInfo.getActionName(), faultInfo.getExceptionMessage() + "\n[" + HostUtils.getLocalHostIP() + " stacktrace]", atsAgent);
} catch (Exception e) {
throw new AgentException(e.getMessage(), e);
}
return result;
}
use of com.axway.ats.agent.webapp.client.ArgumentWrapper in project ats-framework by Axway.
the class Test_RemoteExecutor method executeActionPositive.
@SuppressWarnings("unchecked")
@Test
public void executeActionPositive() throws Exception {
Object resultToReturn = new Integer(4);
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
objectOutStream.writeObject(resultToReturn);
expect(AgentServicePool.getInstance()).andReturn(mockAgentServicePool);
expect(mockAgentServicePool.getClient("10.1.1.3")).andReturn(mockAgentService);
expect(mockAgentService.executeAction(eq(TEST_COMPONENT_NAME), eq("action 1"), (List<ArgumentWrapper>) notNull())).andReturn(byteOutStream.toByteArray());
replayAll();
RemoteExecutor remoteExecutor = new RemoteExecutor("10.1.1.3");
Object actualResult = remoteExecutor.executeAction(new ActionRequest(TEST_COMPONENT_NAME, "action 1", new Object[] { 1 }));
verifyAll();
assertEquals(resultToReturn, actualResult);
}
use of com.axway.ats.agent.webapp.client.ArgumentWrapper in project ats-framework by Axway.
the class RemoteExecutor method wrapActionRequest.
/**
* Wrap the action request into an ActionWrapper so it is easily
* passed to the web service
*
* @param actionRequest the action request to wrap
* @return the action wrapper
* @throws AgentException on error
*/
protected final ActionWrapper wrapActionRequest(ActionRequest actionRequest) throws AgentException {
Object[] arguments = actionRequest.getArguments();
List<ArgumentWrapper> wrappedArguments = new ArrayList<ArgumentWrapper>();
try {
//a byte stream
for (Object argument : arguments) {
ArgumentWrapper argWrapper = new ArgumentWrapper();
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
objectOutStream.writeObject(argument);
argWrapper.setArgumentValue(byteOutStream.toByteArray());
wrappedArguments.add(argWrapper);
}
} catch (IOException ioe) {
throw new AgentException("Could not serialize input arguments", ioe);
}
//construct the action wrapper
ActionWrapper actionWrapper = new ActionWrapper();
actionWrapper.setComponentName(actionRequest.getComponentName());
actionWrapper.setActionName(actionRequest.getActionName());
actionWrapper.getArgs().addAll(wrappedArguments);
return actionWrapper;
}
Aggregations