Search in sources :

Example 16 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class MarshallingRoundTripCustomClassListTest method testJSON.

@Test
public void testJSON() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader());
    verifyMarshallingRoundTrip(marshaller, createTestObject());
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) Test(org.junit.Test)

Example 17 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class MarshallingRoundTripNestedClassesTest method testXStream.

@Test
public void testXStream() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(getCustomClasses(), MarshallingFormat.XSTREAM, getClass().getClassLoader());
    verifyMarshallingRoundTrip(marshaller, createTestObject());
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) Test(org.junit.Test)

Example 18 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class MarshallingRoundTripNestedClassesTest method testJSON.

@Test
public void testJSON() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader());
    verifyMarshallingRoundTrip(marshaller, createTestObject());
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) Test(org.junit.Test)

Example 19 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class KieContainerInstanceImplTest method testUpdatingOfReleaseId.

@Test
public void testUpdatingOfReleaseId() {
    createEmptyKjar(GROUP_ID, ARTIFACT_ID, VERSION_100);
    createEmptyKjar(GROUP_ID, ARTIFACT_ID, VERSION_101);
    KieServices ks = KieServices.Factory.get();
    InternalKieContainer kieContainer = (InternalKieContainer) ks.newKieContainer(CONTAINER_ID, RELEASE_ID_100);
    KieContainerInstanceImpl containerInstance = new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.STARTED, kieContainer);
    Marshaller marshaller = containerInstance.getMarshaller(MarshallingFormat.JAXB);
    // Call getResource() and verify release id
    KieContainerResource containerResource = containerInstance.getResource();
    Assertions.assertThat(containerResource).isNotNull();
    verifyReleaseId(containerResource.getReleaseId(), RELEASE_ID_100);
    verifyReleaseId(containerResource.getResolvedReleaseId(), RELEASE_ID_100);
    // Marshaller is same - no change in release id
    Marshaller updatedMarshaller = containerInstance.getMarshaller(MarshallingFormat.JAXB);
    Assertions.assertThat(updatedMarshaller).isEqualTo(marshaller);
    // Setting kie container with version change
    containerInstance.getKieContainer().updateToVersion(RELEASE_ID_101);
    // Call getResource() and verify release id
    containerResource = containerInstance.getResource();
    Assertions.assertThat(containerResource).isNotNull();
    verifyReleaseId(containerResource.getReleaseId(), RELEASE_ID_101);
    verifyReleaseId(containerResource.getResolvedReleaseId(), RELEASE_ID_101);
    // Marshaller is different - release id was updated
    updatedMarshaller = containerInstance.getMarshaller(MarshallingFormat.JAXB);
    Assertions.assertThat(updatedMarshaller).isNotEqualTo(marshaller);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) KieServices(org.kie.api.KieServices) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainerResource(org.kie.server.api.model.KieContainerResource) Test(org.junit.Test)

Example 20 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class KieContainerCommandServiceImpl method callContainer.

protected ServiceResponse<ExecutionResults> callContainer(String containerId, String payload, MarshallingFormat marshallingFormat, String classType, boolean marshallResponse) {
    if (payload == null) {
        return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Error calling container " + containerId + ". Empty payload. ");
    }
    try {
        KieContainerInstanceImpl kci = (KieContainerInstanceImpl) context.getContainer(containerId, ContainerLocatorProvider.get().getLocator());
        // call do dispose() is executed.
        if (kci != null && kci.getKieContainer() != null) {
            String sessionId = null;
            // this is a weak way of finding the lookup, but it is the same used in kie-camel. Will keep it for now.
            Matcher m = LOOKUP.matcher(payload);
            if (m.find()) {
                sessionId = m.group(1);
            }
            // find the session
            CommandExecutor ks = null;
            if (sessionId != null) {
                ks = context.getKieSessionLookupManager().lookup(sessionId, kci, context);
            } else {
                // if no session ID is defined, then use default stateful/stateless ksession.
                ks = KieServerUtils.getDefaultKieSession(kci);
            }
            context.getKieSessionLookupManager().postLookup(sessionId, kci, ks, context);
            if (ks != null) {
                Class<? extends Command> type = BatchExecutionCommandImpl.class;
                if (classType != null && !classType.isEmpty()) {
                    type = (Class<? extends Command>) kci.getKieContainer().getClassLoader().loadClass(classType);
                }
                Command<?> cmd = kci.getMarshaller(marshallingFormat).unmarshall(payload, type);
                if (cmd == null) {
                    return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Body of in message not of the expected type '" + Command.class.getName() + "'");
                }
                if (!(cmd instanceof BatchExecutionCommandImpl)) {
                    cmd = new BatchExecutionCommandImpl(Arrays.asList(new ExecutableCommand<?>[] { (ExecutableCommand<?>) cmd }));
                }
                ExecutionResults results = ks.execute((BatchExecutionCommandImpl) cmd);
                if (marshallResponse) {
                    Marshaller marshaller = kci.getMarshaller(marshallingFormat);
                    String result = marshaller.marshall(results);
                    return new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully called.", result);
                } else {
                    return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully called.", results);
                }
            } else {
                return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Session '" + sessionId + "' not found on container '" + containerId + "'.");
            }
        } else {
            return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Container " + containerId + " is not instantiated.");
        }
    } catch (Exception e) {
        logger.error("Error calling container '" + containerId + "'", e);
        return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Error calling container " + containerId + ": " + e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) Matcher(java.util.regex.Matcher) ExecutionResults(org.kie.api.runtime.ExecutionResults) CommandExecutor(org.kie.api.runtime.CommandExecutor) ServiceResponse(org.kie.server.api.model.ServiceResponse) BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) UpdateReleaseIdCommand(org.kie.server.api.commands.UpdateReleaseIdCommand) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) ExecutableCommand(org.kie.api.command.ExecutableCommand) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) GetScannerInfoCommand(org.kie.server.api.commands.GetScannerInfoCommand) ActivateContainerCommand(org.kie.server.api.commands.ActivateContainerCommand) CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) Command(org.kie.api.command.Command) GetReleaseIdCommand(org.kie.server.api.commands.GetReleaseIdCommand) ListContainersCommand(org.kie.server.api.commands.ListContainersCommand) KieServerCommand(org.kie.server.api.model.KieServerCommand) DeactivateContainerCommand(org.kie.server.api.commands.DeactivateContainerCommand) GetServerInfoCommand(org.kie.server.api.commands.GetServerInfoCommand) GetServerStateCommand(org.kie.server.api.commands.GetServerStateCommand) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) GetContainerInfoCommand(org.kie.server.api.commands.GetContainerInfoCommand)

Aggregations

Marshaller (org.kie.server.api.marshalling.Marshaller)65 Test (org.junit.Test)48 HashMap (java.util.HashMap)12 WebTarget (javax.ws.rs.client.WebTarget)11 BeforeClass (org.junit.BeforeClass)10 ArrayList (java.util.ArrayList)9 MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)9 Response (javax.ws.rs.core.Response)8 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)8 Command (org.kie.api.command.Command)8 ExecutionResults (org.kie.api.runtime.ExecutionResults)8 HashSet (java.util.HashSet)7 JaxbLong (org.kie.server.api.model.type.JaxbLong)6 KieContainerInstance (org.kie.server.services.api.KieContainerInstance)4 CallContainerCommand (org.kie.server.api.commands.CallContainerCommand)3 KieContainerResource (org.kie.server.api.model.KieContainerResource)3 KieServerCommand (org.kie.server.api.model.KieServerCommand)3 ServiceResponse (org.kie.server.api.model.ServiceResponse)3 Date (java.util.Date)2 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)2