Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

getting java.lang.OutOfMemoryError: Compressedclass space. Safe usage of ObjectMapper in Java callouts?

Not applicable

Hi,

We have a custom Java callout we use to validate an inbound call to a Swagger spec before going anywhere near the backend service. recently we've started seeing a lot of compressed class space errors on our message processors.

The code looks like this:

    public ValidationCallout() {
        this.objectMapper = new ObjectMapper();
        ResourceMapper resourceMapper = ValidationCallout.class.getClassLoader().getResource(LINK_RELATION_MAPPING_LOCATION) == null ?
                DefaultResourceMapper.empty() : DefaultResourceMapper.fromFile(LINK_RELATION_MAPPING_LOCATION);
        this.validator = new DefaultSwaggerValidator(new SwaggerParserYamlImpl().parse(CONTRACT_LOCATION),
                resourceMapper);
    }


    @Override
    public ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) {
        if (!executionContext.isErrorFlow()) {
            if (executionContext.isRequestFlow()) {
                return handleRequest(messageContext, executionContext);
            } else {
                return handleResponse(messageContext, executionContext);
            }
        }
        return ExecutionResult.SUCCESS;
    }

Apigee is erroring at the part it tries to validate the request. If the policy is disabled, the call makes it to the backend and back.

We're running some additional class trace options now to see if ObjectMapper is the culprit, but does the usage of ObjectMapper look suspicious here? Will a new instance of the enclosing class be created each request?

Many thanks

0 2 1,162
2 REPLIES 2