Which version of Velocity Template will support map creation - java

Am sending map and accessing in velocity template version 1.2 but I tried to create map in vm I couldn't create and getting exception.Please give you guidance.
#set($buyerActionStat = {
"0":"New",
"5":"Response-Acknowledged",
"6":"Response-Accepted",
"7":"Response-Rejected"
})
Exception :
org.apache.velocity.exception.ParseErrorException: Lexical error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 5, column 25. Encountered: "{" (123), after : ""
at org.apache.velocity.Template.process(Template.java:181)
at org.apache.velocity.runtime.resource.ResourceManager.getResource(ResourceManager.java:327)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:736)
at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:355)
at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:533)
at ecnet.rd.core.template.TemplateResolver.<init>(TemplateResolver.java:45)
at ecnet.rd.core.template.TemplateResolver.getInstance(TemplateResolver.java:34)
at ecnet.rd.helper.AMECPOHelper.mergePOTemplate(AMECPOHelper.java:71)

the expcetion is caused by velocity versions only.
Use apache velocity version 1.6.2 or later versions.
Maven dependency
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.6.2</version>
</dependency>

Related

Dynamic Reports - ".toPdf(<<filepath>>)" function is not working in Java

I am using Java 8 and Dynamic reports version is 6.0.0.
In pom.xml, I have added this dependency :
<dependency>
<groupId>net.sourceforge.dynamicreports</groupId>
<artifactId>dynamicreports-core</artifactId>
<version>6.0.0</version>
</dependency>
This code is to generate the report parameters:
JasperReportBuilder report = new JasperReportBuilder();
report.setPageMargin(DynamicReports.margin().setLeft(30).setRight(30).setTop(10).setBottom(10));
report.setPageFormat(PageType.A4, PageOrientation.PORTRAIT);
report.title(cmp.subreport(subReport1));
Here, the variable subreport1 contains all the report data. They are verified to be correct.
After generating all the report data, this is the code I execute to write the report details into a file:
FileOutputStream st = new FileOutputStream("<<DUMMY_FILE_PATH>>");
report.toPdf(st);
At this line where .toPdf is present, the following exception is being thrown:
Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.<init>(SimpleFontExtensionHelper.java:149)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.getInstance(SimpleFontExtensionHelper.java:131)
at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.ensureFontExtensions(FontExtensionsRegistry.java:80)
at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:57)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:130)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.getExtensions(DefaultJasperReportsContext.java:277)
at net.sf.jasperreports.engine.fonts.FontUtil.getFontInfo(FontUtil.java:191)
at net.sf.jasperreports.engine.fonts.FontUtil.getFontInfo(FontUtil.java:291)
at net.sf.jasperreports.engine.fonts.FontUtil.getAwtFontFromBundles(FontUtil.java:476)
at net.sf.jasperreports.engine.fonts.FontUtil.getAwtFontFromBundles(FontUtil.java:466)
at net.sf.dynamicreports.design.transformation.StyleResolver.getFont(StyleResolver.java:122)
at net.sf.dynamicreports.design.transformation.StyleResolver.getFont(StyleResolver.java:100)
at net.sf.dynamicreports.design.transformation.StyleResolver.getFontHeight(StyleResolver.java:69)
at net.sf.dynamicreports.design.transformation.TemplateTransform.getTextFieldHeight(TemplateTransform.java:1391)
at net.sf.dynamicreports.design.transformation.ComponentTransform.textField(ComponentTransform.java:395)
at net.sf.dynamicreports.design.transformation.ComponentTransform.component(ComponentTransform.java:155)
at net.sf.dynamicreports.design.transformation.ComponentTransform.list(ComponentTransform.java:303)
at net.sf.dynamicreports.design.transformation.BandTransform.band(BandTransform.java:231)
at net.sf.dynamicreports.design.transformation.BandTransform.transform(BandTransform.java:86)
at net.sf.dynamicreports.design.base.DRDesignReport.transform(DRDesignReport.java:155)
at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:127)
at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:111)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperReportDesign(JasperReportBuilder.java:299)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.getJasperParameters(JasperReportBuilder.java:346)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrint(JasperReportBuilder.java:363)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.export(JasperReportBuilder.java:896)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toPdf(JasperReportBuilder.java:735)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toPdf(JasperReportBuilder.java:724)
Please let me know the solution for this error.
I found the actual solution. There was a version mismatch between xerces jar and dynamic reports jar. It was resolved by adding the following dependency :
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>

Azure - NoSuchMethodExist error in ApplicationTokenCredential while trying to get key from keyVault

I am trying to get key in this way:
private static String getPolicyKey(String secretName, String keyVaultUrl, String applicationId, String applicationSecret) {
KeyVaultClient keyVaultClient = new KeyVaultClient(new ApplicationTokenCredentials(
applicationId, // Application ID
"myDomain.com", // Azure Active Directory Domain
applicationSecret, // Application Key Value
AzureEnvironment.AZURE
));
return keyVaultClient.getSecret(
keyVaultUrl, // KeyValut URL
secretName // Secret Name
).value();
}
But I am getting an Exception:
java.lang.NoSuchMethodError: com.microsoft.azure.credentials.ApplicationTokenCredentials.proxy()Ljava/net/Proxy;
at com.microsoft.azure.credentials.ApplicationTokenCredentials.acquireAccessToken(ApplicationTokenCredentials.java:137)
at com.microsoft.azure.credentials.ApplicationTokenCredentials.getToken(ApplicationTokenCredentials.java:127)
at com.microsoft.azure.credentials.AzureTokenCredentials.getToken(AzureTokenCredentials.java:39)
at com.microsoft.azure.credentials.AzureTokenCredentialsInterceptor.intercept(AzureTokenCredentialsInterceptor.java:36)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:190)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
at okhttp3.RealCall.execute(RealCall.java:57)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
at rx.Observable.unsafeSubscribe(Observable.java:10142)
I am using the following dependencies:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.15.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-keyvault</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.1.0</version>
</dependency>
Note: I tried with azure-eventhubs version 1.0.1 but even that gave same error.
This is my first time dealing with azure-eventhubs, any kind of direction on this will be extremely helpful.
In Maven, when you have a transitive dependency shared between multiple direct dependencies at the same distance (or depth), the one that will end up in your dependency tree will be one coming from the first direct dependency in order of appearance.
Since com.microsoft.azure:azure-keyvault:1.0.0 appears first in your POM, the project will end up with version 1.0.0 of com.microsoft.azure:azure-client-runtime, which is where the class that would contain the proxy() method resides. The problem is that this method was introduced until version 1.1.0
What you can do here is swapping the order in which the Azure Key Vault and Azure Client Authentication dependencies appear. Another thing you can do is directly declare which version of azure-client-runtime you want to use in your POM:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.1.0</version>
</dependency>

Error using Byte Buddy on Android

I'm trying to use Byte Buddy library in Android but I get an error:
java.lang.IllegalStateException: This JVM's version string does not
seem to be valid: 0
I have coded nothing yet, just:
ByteBuddy test = new ByteBuddy();
in my App.java
I have imported:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>0.7.7</version>
</dependency>
but it didn't work, to I tried with:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-android</artifactId>
<version>0.7.7</version>
</dependency>
but I still get same error.
EDIT
I have put this line before initialize ByteBuddy:
System.setProperty("java.version", "1.7.0_51");
But now I get this another error:
Caused by: java.lang.UnsupportedOperationException: can't load this
type of class file.
for this code:
Class<?> dynamicType = new ByteBuddy(ClassFileVersion.JAVA_V6)
.subclass(Object.class)
.method(ElementMatchers.named("toString"))
.intercept(FixedValue.value("Hello World!"))
.make()
.load(getClass().getClassLoader(), AndroidClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
The error is because java.version returns 0 in Android (See section System Properties here - Comparison of Java and Android API)
Also, if you observe ByteBuddy ClassFileVersion
forCurrentJavaVersion() : This method checks for versionString which should return any valid Java/JDK version else it
throws IllegalStateException("This JVM's version string does not seem to be valid: " + versionString);
& since java.version is returning 0, it's throwing IllegalStateException.
Try to log this value:
String versionString = System.getProperty(JAVA_VERSION_PROPERTY);
Log.d(TAG, versionString);//retruns 0 here
hence workaround for this issue is to add
System.setProperty(JAVA_VERSION_PROPERTY, "1.7.0_79");//add your jdk version here
before calling
ByteBuddy test = new ByteBuddy();
where JAVA_VERSION_PROPERTY is declared as:
private static final String JAVA_VERSION_PROPERTY = "java.version";
Also dependency to use is:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>0.7.7</version>
</dependency>
Else if you are using studio, you can add
compile 'net.bytebuddy:byte-buddy:0.7.7'
to your app build.gradle.
Hope this will help solve your issue.

Why Jongo 1.0 removed support for private properties

Recently I migrated from Jongo 0.4 to Jongo 1.0, and suddenly I started to receive this exception:
! java.lang.IllegalArgumentException: Unable to set objectid on class: class *Myclass*
! at org.jongo.ReflectiveObjectIdUpdater.updateField(ReflectiveObjectIdUpdater.java:72) ~[jongo-1.0.jar:na]
! at org.jongo.ReflectiveObjectIdUpdater.setObjectId(ReflectiveObjectIdUpdater.java:60) ~[jongo-1.0.jar:na]
! at org.jongo.Insert.preparePojo(Insert.java:71) ~[jongo-1.0.jar:na]
! at org.jongo.Insert.insert(Insert.java:56) ~[jongo-1.0.jar:na]
! at org.jongo.MongoCollection.insert(MongoCollection.java:140) ~[jongo-1.0.jar:na]
! at org.jongo.MongoCollection.insert(MongoCollection.java:132) ~[jongo-1.0.jar:na]
...
That means that Jongo now has problems setting a private field, which in 0.4 wasn't a problem.
Is there some reason for this limitation?
Jongo stills 'support' private properties in v1.0
Nevertheless due to a regression it was unable to handle private id field.
This has been fixed in v1.1 : https://github.com/bguerout/jongo/issues/198
If you have a Maven pom.xml, just update it with :
<dependencies>
<dependency>
<groupId>org.jongo</groupId>
<artifactId>jongo</artifactId>
<version>1.1</version>
</dependency>
...
</dependencies>

XPath can't find an engine

I inherited some code that is using XPath for which I am a novice. I have it now so that it loads the document, but when the document.selectPath(queryPath) it always fails with the following error:
java.lang.RuntimeException: Trying XBeans path engine... Trying XQRL... Trying delegated path engine... FAILED on //
at org.apache.xmlbeans.impl.store.Path.getCompiledPath(Path.java:173)
at org.apache.xmlbeans.impl.store.Path.getCompiledPath(Path.java:130)
at org.apache.xmlbeans.impl.store.Cursor._selectPath(Cursor.java:902)
at org.apache.xmlbeans.impl.store.Cursor.selectPath(Cursor.java:2634)
at org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:462)
at org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:446)
Thank you jor for the post. I was confused as earlier commands to xml beans were successful.
Without saxon, this still works:
MapDocument doc;
...
String cityQuery = "$this//City";
XmlObject[] cities = doc.selectPath(cityQuery);
However saxon is required for explicit selection of fields within tags:
String aveQuery= "$this//Street[Kind='Avenue']";
XmlObject[] avenues = doc.selectPath(aveQuery); // RuntimeException without saxon on path
java.lang.RuntimeException:
Trying XBeans path engine... Trying XQRL... Trying delegated path engine... FAILED on $this//Street[Kind='Avenue']
I hope this might be of use to others that encounter a similar issue.
You need an XPath engine in your classpath, which one bepends on the XMLBeans version, see
http://wiki.apache.org/xmlbeans/XmlBeansFaq#whatJars
The movement if you have [] in your xpath, it is searching for the external xpath enginer.. you have to download saxonb9-0-0-4j & xmlbeans-xpath-2.4.0.jar and add to the classpath
worked for me:
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>10.6</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.3</version>
</dependency>

Categories