Bug 1119560

Summary: Execution Server: RestOperationException thrown on pInstance variable of type Long
Product: [Retired] JBoss BPMS Platform 6 Reporter: jbride <jbride>
Component: Business CentralAssignee: Marco Rietveld <mrietvel>
Status: CLOSED EOL QA Contact: Ivo Bek <ibek>
Severity: medium Docs Contact:
Priority: high    
Version: 6.0.2CC: jbride, kverlaen, mbaluch
Target Milestone: ER5   
Target Release: 6.1.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-27 20:01:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description jbride@redhat.com 2014-07-15 04:26:01 UTC
Hi.
  In 6.0.2, the following stacktrace is thrown when invoking the execution server for a pInstance variable of type of Long:

[org.kie.remote.services.rest.exception.DescriptiveExceptionHandler] (http-a2a046610049/172.17.0.2:8080-8) Exception thrown when processing request [/runtime/com.redhat.gpe.refarch.bpm_signalling:processTier:1.0/process/instance/10/variable/sProcessId]; responding with status 500: org.kie.remote.services.rest.exception.RestOperationException: Unable to serialize java.lang.Long instance because it is missing a javax.xml.bind.annotation.XmlRootElement annotation with a name value.
	at org.kie.remote.services.rest.exception.RestOperationException.internalServerError(RestOperationException.java:124) [kie-services-remote-6.0.3-redhat-4.jar:6.0.3-redhat-4]
	at org.kie.remote.services.rest.RuntimeResource.getRootElementName(RuntimeResource.java:450) [kie-services-remote-6.0.3-redhat-4.jar:6.0.3-redhat-4]
	at org.kie.remote.services.rest.RuntimeResource.process_instance_procInstId_variable_varName(RuntimeResource.java:161) [kie-services-remote-6.0.3-redhat-4.jar:6.0.3-redhat-4]


Querying the 'history' resource of the execution server for the same pInstance variable does return without issue.

jeff

Comment 2 Marco Rietveld 2014-07-15 16:11:39 UTC
Hi Jeff, 

Sorry to be such a stickler, but could you provide the following information? 

- Expected results:

Thanks!

Comment 3 Kris Verlaenen 2015-01-21 16:21:25 UTC
A similar feature was fixed for String, however I know get a different exception for Long:
Could not find MessageBodyWriter for response object of type: java.lang.Long of media type: application/xml

Comment 4 Maciej Swiderski 2015-01-28 14:24:53 UTC
fix provided to wrap primitives and their wrappers with custom JAXBElement - JaxbVarElement. Reason for creating custom JAXBElement was to provide consistent support for both XML and JSON representation types. So for all process variables taken from runtime (not history) all will be wrapped and will look like following:

XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><value>100</value>

JSON:
{
value: 100
}

in addition a optional support for wrapping String types was provided as well to produce valid xml and json response and can be enabled with system property: org.kie.remote.wrap.string=true

that way response for String variables will be as follows:
XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><value>john</value>

JSON:
{
value: "john"
}

by default that spring wrapper is disabled and will produce following response:
XML:
john

JSON:
john

which in general is invalid format for both xml and json, though can be interpreted directly thus I left it as it for backward compatibility.

in addition in case one would like to use RestEasy client API following could be used to get hold of variable values:

ClientRequest restRequest = createRequest(new URL("url to rest resource")); //regular RestEasy client api request
ClientResponse responseObj = restRequest.get();

JAXBElement<Long> res = (JAXBElement<Long>) responseObj.getEntity(new GenericType<JAXBElement<Long>>(){});

Long variableValue = res.getValue();


droolsjbpm-integration
master:
https://github.com/droolsjbpm/droolsjbpm-integration/commit/d7337aef5402ba933c162502d7523fb547a6686c

6.2.x:
https://github.com/droolsjbpm/droolsjbpm-integration/commit/25ea24f89e3827f4b782dc1ff5da2d0c6d029afa

Comment 5 Maciej Swiderski 2015-01-30 19:24:26 UTC
described solution does work completely, still working on this....

Comment 6 Maciej Swiderski 2015-01-31 14:16:17 UTC
please ignore comment number 4 when it comes to the solution, it has been changed as it proved to be not reliable and caused other issues with jab marshaling.

There are primitive wrapper jab classes provided and in case process variable is of primitive type or its wrapper then jab wrapper class for that type will be used. This has proven to work well for all types and for both XML and JSON content types.

XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><long-type><value>100</value></long-type>

JSON:
{
value: 100
}

as it can be seen for XML it has a root element that defines its type : <long-type> and it will have different depending on actual value e.g. <boolean-type> etc.

in addition an optional support for wrapping String types was provided as well to produce valid xml and json response and can be enabled with system property: org.kie.remote.wrap.string=true

that way response for String variables will be as follows:
XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><string-type><value>john</value></string-type>

JSON:
{
value: "john"
}

by default that string wrapper is disabled and will produce following response:
XML:
john

JSON:
john

which in general is invalid format for both xml and json, though can be interpreted directly thus I left it as it for backward compatibility.

in addition in case one would like to use RestEasy client API following could be used to get hold of variable values:

ClientRequest restRequest = createRequest(new URL("url to rest resource")); //regular RestEasy client api request
ClientResponse responseObj = restRequest.get();

JaxbLong res = (JaxbLong) responseObj.getEntity(JaxbLong.class);

Long variableValue = res.getValue();

droolsjbpm-integration
master:
https://github.com/droolsjbpm/droolsjbpm-integration/commit/d83f4ba384aa89a2438afa81ec625b568b82a9d5

6.2.x:
https://github.com/droolsjbpm/droolsjbpm-integration/commit/1b6209548f399d90e8541587c0040a6cd3c29030

Comment 7 Ivo Bek 2015-02-17 17:29:00 UTC
Verified in BPMS 6.1.0.ER5

Trying to get the primitive type produces:

org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type application/xml and type null

However, when we change it to JaxbInteger it works as expected.