Element 'springService' is not defined in the Mule Registry [Mule 4] - spring

I have a problem with beans in mule 4.
There is an error when trying to invoke java:
Element 'springService' is not defined in the Mule Registry
Error occures in run time.
I have created configuration.xml and declared spring config:
<spring:config name="springConfig" doc:name="springConfig" files="beans.xml" />
Then created beans.xml in /src/main/resources:
<beans ...>
<context:component-scan base-package="com.services" />
</beans>
com.services is an external service that has a class:
#Service
public class SpringService {
...
}
EDIT1:
The way I am trying to invoke java method:
<java:invoke doc:name="Get data" doc:id="id" class="com.services.SpringService" method="#[getData(String)]" instance="springService">
<java:args><![CDATA[#[{name: vars.name}]]]></java:args>
</java:invoke>
Stack trace:
Message : Element 'springService' is not defined in the
Mule Registry
Element : test-flow/processors/2 #
test-service:test.xml:14 (Get Data)
Element DSL : <java:invoke doc:name="Get data" doc:id="id"
class="com.services.SpringService" method="#[getData(String)]"
instance="springService">
java:args#[{name: vars.name}]</java:args>
</java:invoke> Error type : MULE:UNKNOWN
FlowStack : at test-flow(test-flow/processors/2 #
test-service:test.xml:14 (Get Data))
at get:\getData(name):test-api-config(get:\getData(name):test-api-config/processors/0
# test-service:test-api.xml:125 (Get Data))
at test-api-main(test-api-main/processors/0 # test-service:test-api.xml:15)

The documentation of the Java Module doesn't say it can invoke a Spring bean instance. The examples always mention using the new operation of the module to create instances.At the least if possiblle it is not documented how. Probably unsupported by the current version of the Java module.

Related

Problem with Protostream and UUID in Infinispan 13.0.0.Final

I'm using Infinispan 13.0.0.final with the default marshaller (protobuf). When I try to use UUID fields in my datatypes
data class CounterState(
#get:ProtoField(number = 1) var index: Long? = null,
#get:ProtoField(number = 2) var uuid: UUID? = null
)
I get the following error at build time:
.../gradle-kotlin-protobuf/build/tmp/kapt3/stubs/main/io/radiosphere/ProtoSchema.java:8: error: org.infinispan.protostream.annotations.ProtoSchemaBuilderException: The class java.util.UUID must be instantiable using an accessible no-argument constructor.
public abstract interface ProtoSchema extends org.infinispan.protostream.GeneratedSchema {
It seems like I'm not allowed to use UUID in my types unless I generate a protoschema for it, but since UUID is a class outside of my control I can't do this.
Previous questions on the topic have gotten the suggestion to use the JavaSerializationMarshaller, but I want to solve this while still using the Protostream Marshaller. It has also been suggested that this would be fixed in version 12.0.0 here.
An example of this not working can be found here. Note that this project will not build because of the annotation processing failing as mentioned above. If it would build the proof that it is working would be shown by running the main project (ie. not the tests).
The question becomes: What do I need to do to configure UUID to be usable in my protobuf marshalled classes in Infinispan 13? Both for embedded and for a program using the hotrod client?
EDIT:
Based on a given answer I have also tried doing the following:
#AutoProtoSchemaBuilder(
includeClasses = [UUIDAdapter::class, CounterState::class],
schemaPackageName = "tutorial")
interface ProtoSchema : GeneratedSchema {
}
This makes the build work, but when starting Quarkus I get the following error:
Caused by: org.infinispan.protostream.DescriptorParserException: Duplicate type id 1005 for type org.infinispan.protostream.commons.UUID. Already used by tutorial.UUID
at org.infinispan.protostream.descriptors.ResolutionContext.checkUniqueTypeId(ResolutionContext.java:151)
at org.infinispan.protostream.descriptors.ResolutionContext.addGenericDescriptor(ResolutionContext.java:97)
at org.infinispan.protostream.descriptors.FileDescriptor.collectDescriptors(FileDescriptor.java:313)
at org.infinispan.protostream.descriptors.FileDescriptor.resolveDependencies(FileDescriptor.java:245)
at org.infinispan.protostream.descriptors.FileDescriptor.resolveDependencies(FileDescriptor.java:210)
at org.infinispan.protostream.descriptors.ResolutionContext.resolve(ResolutionContext.java:57)
at org.infinispan.protostream.impl.SerializationContextImpl.registerProtoFiles(SerializationContextImpl.java:127)
at org.infinispan.protostream.types.java.CommonTypesSchema.registerSchema(CommonTypesSchema.java:49)
at org.infinispan.client.hotrod.RemoteCacheManager.registerSerializationContextInitializer(RemoteCacheManager.java:422)
at org.infinispan.client.hotrod.RemoteCacheManager.registerDefaultSchemas(RemoteCacheManager.java:437)
at org.infinispan.client.hotrod.RemoteCacheManager.initializeProtoStreamMarshaller(RemoteCacheManager.java:409)
at org.infinispan.client.hotrod.RemoteCacheManager.actualStart(RemoteCacheManager.java:365)
at org.infinispan.client.hotrod.RemoteCacheManager.start(RemoteCacheManager.java:334)
at org.infinispan.client.hotrod.RemoteCacheManager.<init>(RemoteCacheManager.java:192)
at org.infinispan.client.hotrod.RemoteCacheManager.<init>(RemoteCacheManager.java:149)
at io.quarkus.infinispan.client.runtime.InfinispanClientProducer.initialize(InfinispanClientProducer.java:68)
If I instead change to use dependsOn like this:
#AutoProtoSchemaBuilder(
includeClasses = [CounterState::class],
dependsOn = [org.infinispan.protostream.types.java.CommonTypes::class, org.infinispan.protostream.types.java.CommonContainerTypes::class],
schemaPackageName = "tutorial")
I'm back to the build failing with:
error: org.infinispan.protostream.annotations.ProtoSchemaBuilderException: The class java.util.UUID must be instantiable using an accessible no-argument constructor.
public abstract interface ProtoSchema extends org.infinispan.protostream.GeneratedSchema {
It seems to be like Quarkus and the Annotation processor are getting in each others way here when it comes to having a simple working solution for UUID marshalling.
You have to include the org.infinispan.protostream.types.java.util.UUIDAdapter class in your annotation:
#AutoProtoSchemaBuilder(includeClasses = [CounterState::class, UUIDAdapter::class] , schemaPackageName = "tutorial")
For more info, check the documentation page.

Spring Cloud Contract - NullPointerException in resolvedDestination

I am trying to create Spring cloud contract for Spring cloud stream. I have source, processor and sink. The source uses SourcePollingChannelAdapte. The contract groovy file looks like this:
package contracts.messaging
import org.springframework.cloud.contract.spec.Contract
Contract.make {
description("""
Sends a non XhubJobState in Message
""")
// Label by means of which the output message can be triggered
label 'accpetable_message'
// input to the contract
input {
// the contract will be triggered by a method
triggeredBy('verifyValidXhubJobState()')
}
// output message of the contract
outputMessage {
// destination to which the output message will be sent
sentTo 'verifications'
// the body of the output message
body([
jobName:"Invalid_Destinations"
])
}
}
When try to do maven install I get the exception:
"Exception took place while trying to resolve the destination. Will assume the name [verifications]
java.lang.NullPointerException: null
at org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.resolvedDestination(StreamStubMessages.java:89)......."
I have defined following propery set in application.properties file
"spring.cloud.stream.bindings.output.destination= verifications"
Am I missing something in the configuration?
I haven't seen your code but I can only guess that in your base class you're missing these annotations - https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/producer/src/test/java/com/example/BeerMessagingBase.java#L14-L19 . Your context wasn't started so the fields weren't injected, that's why you get NPE.

Cannot find Region in cache GemFireCache

Caused by: org.springframework.beans.factory.BeanInitializationException: Cannot find region [record] in cache GemFireCache[id = 20255495;
isClosing = false; isShutDownAll = false;
closingGatewayHubsByShutdownAll = false; created = Mon Jan 23 11:45:10 EST 2017; server = false; copyOnRead = false; lockLease = 120; lockTimeout = 60]
at org.springframework.data.gemfire.RegionLookupFactoryBean.lookupFallback(RegionLookupFactoryBean.java:72)
at org.springframework.data.gemfire.RegionLookupFactoryBean.afterPropertiesSet(RegionLookupFactoryBean.java:59)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 13 more
My XML File is :
<beans>
....
<context:component-scan base-package="spring.gemfire.repository.deptemp"/>
<gfe:client-cache id="gemfireCache" pool-name="gfPool"/>
<!--Region for being used by the Record Bean -->
<gfe:replicated-region id="record" cache-ref="gemfireCache"/>
<bean id="record" class="spring.gemfire.repository.deptemp.beans.Record"/>
<gfe:pool id="gfPool" max-connections="10" subscription-enabled="true" >
<gfe:locator host="localhost" port="10334"/>
</gfe:pool>
<gfe:lookup-region id="record" />
<gfe-data:repositories base-package="spring.gemfire.repository.deptemp.repos"/>
</beans>
Abhisekh-
Why do you have both this...
<gfe:replicated-region id="record" cache-ref="gemfireCache"/>
And this...
<gfe:lookup-region id="record" />
Also, you have defined this...
<bean id="record" class="spring.gemfire.repository.deptemp.beans.Record"/>
Which (most definitely) overrode your REPLICATE Region bean definition (also with id="record") based on the "order" of your bean definitions in your XML defined above.
While Spring first and foremost adheres to dependency order between bean definitions, it will generally follow the declared order when no dependencies (explicit or implicit) exist.
Since <bean id="record" .../> comes after <gfe:replicated-region id="record" ../>, then <bean id=record../> overrides the <gfe:replicated-region id="record"/> bean definition.
Additionally, the <gfe:lookup-region> is not needed since you are not using GemFire/Geode's native configuration (e.g. cache.xml) or Cluster Configuration Service.
Furthermore, you are declaring a ClientCache, so technically probably want a <gfe:client-region> to match the GemFire/Geode Server Region, yes?!
While you can create REPLICATE Regions (and even PARTITION Regions) on a client, you typically do not do this since those Regions are NOT part of any distributed system, or cluster of GemFire "Server" nodes.
A client Region (which can be a PROXY, or even a CACHING_PROXY) will distribute data operations to the Server. Additionally, if you have data that only a particular client needs, then you ought to create local Regions, using <gfe:local-region>.
I would definitely read this, first...
http://gemfire.docs.pivotal.io/geode/basic_config/book_intro.html
Followed by this next...
http://gemfire.docs.pivotal.io/geode/topologies_and_comm/book_intro.html
Then this...
http://gemfire.docs.pivotal.io/geode/developing/book_intro.html
And lastly...
http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#bootstrap
-John

FacesContextUtils.getWebApplicationContext() returns null

I would like to get the spring context from within a class that gets loaded at server startup time:
WebApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
In Tomcat, this returns what I want, but in Weblogic this returns null. looking further, it seems that
getApplicationMap().get(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
// "org.springframework.web.context.WebApplicationContext.ROOT"
doesn't yet have that property in the map at the time of my class being loaded.
My class is constructed/loaded via roughtly this stack trace:
MyRenderKitImpl()
Class.newInstance()
RenderKitConfigProcessor.process()
ConverterConfigProcessor.process()
ApplicationConfigProcessor.process();
FactoryConfigProcessor.process();
StandardContext.listenerStart()
Is there a trick to ensure the right sequence?

Camel type converter fails: InvalidPayloadException: No body available of type

The application is based on OSGI.
I have a custom annotated converter:
package com.domain.bundle1.web.camel.converters;
import ...;
#Converter
public class FooTransferObjectConverter {
public FooTransferObjectConverter() {
}
#Converter
public static FooTransferObject toFooTransferObject(Foo foo, Exchange exchange) throws Exception {
// some magic
return fooTransferObject;
}
}
Also i declared package where it plased in TypeConverter file:
http://i.stack.imgur.com/U3QQH.png
which contains:
com.domain.bundle1.web.camel.converters
And camel-context file contains next code:
<log loggingLevel="INFO" message="Converting to FooTransferObject" />
<convertBodyTo type="com.domain.bundle2.model.FooTransferObject" />
<log loggingLevel="INFO" message="Converted!" />
Before converting, body of message is a Foo object.
But when process reaches converting, then throws an exception:
Failed delivery for (MessageId: ID-EPUALVIW0567-55536-1401106375216-26-5 on ExchangeId: ID-EPUALVIW0567-55536-1401106375216-26-6).
Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: com.domain.bundle2.model.FooTransferObject but has value: Foo{97, Wall, null, null} of type: com.domain.bundle3.model.Foo on: Message: Foo{97, Wall, null, null}.
Caused by: Error during type conversion from type: com.domain.bundle3.model.Foo to the required type: com.domain.bundle2.model.FooTransferObject with value Foo{97, Wall, null, null} due 6 counts of IllegalAnnotationExceptions. Exchange[Message: Foo{97, Wall, null, null}]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: Foo{97, Wall, null, null} to the required type: com.domain.bundle2.model.FooTransferObjec with value....
then exception cached by custom handler,
and then I found this:
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: freebaseball SpeedKick -> fr????f????tb??ll Sp????dK??ck -> free
football SpeedKick ]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:311)[:1.7.0_40]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)[:1.7.0_40]
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
at org.apache.camel.converter.jaxb.FallbackTypeConverter.marshall(FallbackTypeConverter.java:238)
at org.apache.camel.converter.jaxb.FallbackTypeConverter.convertTo(FallbackTypeConverter.java:95)
... 163 more
Caused by: com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: freebaseball SpeedKick -> fr????f????tb??ll Sp????dK??c
k -> freebaseball SpeedKick
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:237)[:1.7.0_40]
How do You think what's a problem? How can I see loaded converters in TypeConverterRegistry?
I have already solved my problem. FallbackTypeConverter started work, because camel didn't load my custom regular type converter.
I checked the map of converters in TypeConverterRegister in debug mode, and didn't find my FooTransferObjectConverter.
The problem was in file TypeConverter. I just added name of converter class to path and after that it loaded to registry.
com.domain.bundle1.web.camel.converters.FooTransferObjectConverter
Camel version in application - 2.11.1. In camel docs written next:
In Camel 2.8 we improved the type converter loader to support
specifying the FQN class name of the converter classes. This has the
advantage of avoiding having to scan packages for #Converter classes.
Instead it loads the #Converter class directly. This is a highly
recommend approach to use going forward.
But i tryed run the application from chapter 3 (from 'Camel in action' book) with custom converter. And file TypeConverter contained only from package path.

Resources