Search in sources :

Example 1 with MarshallingFormat

use of org.kie.server.api.marshalling.MarshallingFormat in project rhpam-7-openshift-image by jboss-container-images.

the class HelloRulesClient method runRemote.

private void runRemote(HelloRulesCallback callback, KieServicesConfiguration config) {
    MarshallingFormat marshallingFormat = getMarshallingFormat();
    config.setMarshallingFormat(marshallingFormat);
    if (MarshallingFormat.JAXB.equals(marshallingFormat)) {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(Greeting.class);
        classes.add(Person.class);
        config.addExtraClasses(classes);
    }
    RuleServicesClient client = KieServicesFactory.newKieServicesClient(config).getServicesClient(RuleServicesClient.class);
    BatchExecutionCommand batch = createBatch();
    ServiceResponse<ExecutionResults> response = client.executeCommandsWithResults("rhpam-kieserver-decisions", batch);
    ExecutionResults execResults = response.getResult();
    handleResults(callback, execResults);
}
Also used : MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) ExecutionResults(org.kie.api.runtime.ExecutionResults) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) RuleServicesClient(org.kie.server.client.RuleServicesClient) HashSet(java.util.HashSet)

Example 2 with MarshallingFormat

use of org.kie.server.api.marshalling.MarshallingFormat in project rhpam-7-openshift-image by jboss-container-images.

the class LibraryClient method runRemote.

private void runRemote(PrintWriter out, KieServicesConfiguration kiecfg) throws Exception {
    appcfg.setKieSession(null);
    MarshallingFormat marshallingFormat = appcfg.getMarshallingFormat();
    out.println(String.format("Using %s MarshallingFormat.%s", marshallingFormat.getType(), marshallingFormat.name()));
    kiecfg.setMarshallingFormat(marshallingFormat);
    if (MarshallingFormat.JAXB.equals(marshallingFormat)) {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(Book.class);
        classes.add(Loan.class);
        classes.add(LoanRequest.class);
        classes.add(LoanResponse.class);
        classes.add(ReturnRequest.class);
        classes.add(ReturnResponse.class);
        classes.add(Suggestion.class);
        classes.add(SuggestionRequest.class);
        classes.add(SuggestionResponse.class);
        kiecfg.addExtraClasses(classes);
    }
    KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kiecfg);
    RuleServicesClient ruleServicesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
    ProcessServicesClient processServicesClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
    appcfg.setRuleServicesClient(ruleServicesClient);
    appcfg.setProcessServicesClient(processServicesClient);
    runApp(out);
}
Also used : MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) KieServicesClient(org.kie.server.client.KieServicesClient) RuleServicesClient(org.kie.server.client.RuleServicesClient) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) HashSet(java.util.HashSet)

Example 3 with MarshallingFormat

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

the class CommandResource method manageContainer.

@ApiOperation(value = "Executes one or more runtime commands")
@ApiResponses({ @ApiResponse(code = 200, message = "Successful execution", response = ServiceResponse.class), @ApiResponse(code = 500, message = "Unexpected error", response = ServiceResponse.class), @ApiResponse(code = 204, message = "Command execute successfully, but without response", response = ServiceResponse.class) })
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response manageContainer(@Context HttpHeaders headers, @ApiParam(value = "Container id where rules should be evaluated on", required = true) @PathParam(RestURI.CONTAINER_ID) String id, @ApiParam(value = "Commands to be executed on rule engine given as BatchExecutionCommand type", required = true) String cmdPayload) {
    Variant v = getVariant(headers);
    String contentType = getContentType(headers);
    String classType = getClassType(headers);
    MarshallingFormat format = MarshallingFormat.fromType(contentType);
    if (format == null) {
        format = MarshallingFormat.valueOf(contentType);
    }
    logger.debug("Received request with content '{}'", cmdPayload);
    Header conversationIdHeader = buildConversationIdHeader(id, registry, headers);
    @SuppressWarnings("squid:S3740") ServiceResponse<?> result = delegate.callContainer(id, cmdPayload, format, classType);
    Status status = result.getType() == FAILURE ? INTERNAL_SERVER_ERROR : OK;
    try {
        String response = marshallerHelper.marshal(id, format.getType(), result, ContainerLocatorProvider.get().getLocator());
        logger.debug("Returning {} response with content '{}'", status, response);
        return createResponse(response, v, status, conversationIdHeader);
    } catch (IllegalArgumentException e) {
        // in case marshalling failed return the call container response to keep backward compatibility
        String response = marshallerHelper.marshal(format.getType(), result);
        logger.debug("Returning {} response with content '{}'", status, response);
        return createResponse(response, v, status, conversationIdHeader);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Status(javax.ws.rs.core.Response.Status) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with MarshallingFormat

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

the class MarshallerHelper method marshal.

public String marshal(String marshallingFormat, Object entity) {
    MarshallingFormat format = getFormat(marshallingFormat);
    if (format == null) {
        throw new IllegalArgumentException("Unknown marshalling format " + marshallingFormat);
    }
    Marshaller marshaller = serverMarshallers.get(format);
    if (marshaller == null) {
        marshaller = MarshallerFactory.getMarshaller(getExtraClasses(registry), format, this.getClass().getClassLoader());
        serverMarshallers.put(format, marshaller);
    }
    return marshaller.marshall(entity, MarshallingFormat.buildParameters(marshallingFormat));
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat)

Example 5 with MarshallingFormat

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

the class MarshallerHelper method unmarshal.

public <T> T unmarshal(String containerId, String data, String marshallingFormat, Class<T> unmarshalType, ContainerLocator locator) {
    if (data == null || data.isEmpty()) {
        return null;
    }
    MarshallingFormat format = getFormat(marshallingFormat);
    KieContainerInstance containerInstance = registry.getContainer(containerId, locator);
    if (containerInstance == null || format == null) {
        throw new IllegalArgumentException("No container found for id " + containerId + " or unknown marshalling format " + marshallingFormat);
    }
    Marshaller marshaller = containerInstance.getMarshaller(format);
    if (marshaller == null) {
        throw new IllegalArgumentException("No marshaller found for format " + format);
    }
    Object instance = marshaller.unmarshall(data, unmarshalType, MarshallingFormat.buildParameters(marshallingFormat));
    if (instance instanceof Wrapped) {
        return (T) ((Wrapped) instance).unwrap();
    }
    return (T) instance;
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) Wrapped(org.kie.server.api.model.Wrapped) KieContainerInstance(org.kie.server.services.api.KieContainerInstance)

Aggregations

MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)17 Marshaller (org.kie.server.api.marshalling.Marshaller)9 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 Variant (javax.ws.rs.core.Variant)6 Path (javax.ws.rs.Path)5 KieContainerInstance (org.kie.server.services.api.KieContainerInstance)4 ArrayList (java.util.ArrayList)3 POST (javax.ws.rs.POST)3 Wrapped (org.kie.server.api.model.Wrapped)3 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)3 MarshallerHelper (org.kie.server.services.impl.marshal.MarshallerHelper)3 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)2 ExecutionResults (org.kie.api.runtime.ExecutionResults)2 RuleServicesClient (org.kie.server.client.RuleServicesClient)2 RESTUtils.getVariant (org.redhat.gss.extension.RESTUtils.getVariant)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ApiOperation (io.swagger.annotations.ApiOperation)1