When I output birthDate in a Thymeleaf template it prints the date/time:
1962-04-18 00:00:00.0
How can I output just the date?
This is what I've currently got:
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
Thymeleaf template:
<tbody>
<tr th:each="tempUser : ${users}">
<td th:text="${#temporals.format(tempUser.birthDate, 'yyyy-MM-dd')}" />
</tr>
</tbody>
Variable in User.java
#DateTimeFormat(pattern="yyyy-MM-dd")
#Column(name="birth_date")
private Date birthDate;
When I try to view the page I get:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Oct 12 16:31:36 BST 2020
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/users/list-users.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/users/list-users.html]")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362)
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "#temporals.format(tempUser.birthDate, 'yyyy-MM-dd')" (template: "users/list-users" - line 43, col 9)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
... 48 more
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#temporals.format(tempUser.birthDate, 'yyyy-MM-dd')" (template: "users/list-users" - line 43, col 9)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:290)
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166)
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138)
at org.thymeleaf.standard.processor.AbstractStandardExpressionAttributeTagProcessor.doProcess(AbstractStandardExpressionAttributeTagProcessor.java:144)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95)
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918)
at org.thymeleaf.engine.StandaloneElementTag.beHandled(StandaloneElementTag.java:228)
at org.thymeleaf.engine.Model.process(Model.java:282)
at org.thymeleaf.engine.Model.process(Model.java:290)
at org.thymeleaf.engine.IteratedGatheringModelProcessable.processIterationModel(IteratedGatheringModelProcessable.java:367)
at org.thymeleaf.engine.IteratedGatheringModelProcessable.process(IteratedGatheringModelProcessable.java:221)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleCloseElement(ProcessorTemplateHandler.java:1640)
at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleAutoCloseElementEnd(TemplateHandlerAdapterMarkupHandler.java:428)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleAutoCloseElementEnd(InlinedOutputExpressionMarkupHandler.java:344)
at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleAutoCloseElementEnd(OutputExpressionInlinePreProcessorHandler.java:237)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleAutoCloseElementEnd(InlinedOutputExpressionMarkupHandler.java:184)
at org.attoparser.HtmlElement.handleAutoCloseElementEnd(HtmlElement.java:199)
at org.attoparser.HtmlMarkupHandler.handleAutoCloseElementEnd(HtmlMarkupHandler.java:472)
at org.attoparser.MarkupEventProcessorHandler.checkStackForElement(MarkupEventProcessorHandler.java:763)
at org.attoparser.MarkupEventProcessorHandler.handleCloseElementStart(MarkupEventProcessorHandler.java:439)
at org.attoparser.ParsingElementMarkupUtil.parseCloseElement(ParsingElementMarkupUtil.java:197)
at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:725)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301)
... 50 more
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method format(java.sql.Timestamp,java.lang.String) cannot be found on type org.thymeleaf.extras.java8time.expression.Temporals
at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:226)
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:135)
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:55)
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:387)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:92)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:112)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:337)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263)
... 76 more
<p th:text="${#temporals.format(localDate, 'dd-MM-yyyy')}"></p>
The above code gives the following output:
12-10-2020
And of course, you must have the following dependencies added, in the pom.xml file.
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
The latest versions of thymeleaf and thymeleaf-spring5 can be found on Maven Central. Note that, for a Spring 4 project, the thymeleaf-spring4 library must be used instead of thymeleaf-spring5.
Moreover, in order to work with Java 8 Date classes, we will add the following dependency to the pom.xml:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
The thymeleaf extras is an optional module, that was created for compatibility with the Java 8 Time API. It adds a #temporals object to the Context as a utility object processor during expression evaluations. This means that it can be used to evaluate expressions in Object-Graph Navigation Language (OGNL) and Spring Expression Language (SpringEL).
The Time package is a date, time, and calendar API for the Java SE platform. The main difference between old legacy Date and is that the new API distinguishes between machine and human views of a timeline. The machine view reveals a sequence of integral values relative to the epoch, whereas view reveals a set of fields (e.g., year or day).
To work with the Time package, configure the template engine to use the Java8TimeDialect:
private ISpringTemplateEngine templateEngine(ITemplateResolver templateResolver) {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.addDialect(new Java8TimeDialect());
engine.setTemplateResolver(templateResolver);
return engine;
}
This will add the #temporals object similar to the ones in the Standard Dialect, allowing the formatting and creation of Temporal objects from Thymeleaf templates.
In order to test the processing of new and old classes, create the following variables and add them as model objects to the controller class:
model.addAttribute("standardDate", new Date());
model.addAttribute("localDateTime", LocalDateTime.now());
model.addAttribute("localDate", LocalDate.now());
model.addAttribute("timestamp", Instant.now());
Related
We are using Postgres 14.3, Springboot 2.6.1 and JDBC driver 'org.postgresql:postgresql:42.3.3'
We have a problem in a call to a SP. It's a legacy call to a Stored Procedure with many input parameters and 6 scalar type out parameters.
This is the call structure of the SP:
try (CallableStatement cStm = connection.prepareCall("{Call PERSIST(?,?,...?)")) {
cStm.setString(1, (persistOrderer ? "1" : "0"));
cStm.setString(2, (persistOrdererAditionals ? "1" : "0"));
cStm.setString(3, "1");
cStm.setString(4, (persistBeneficiary ? "1" : "0"));
....
cStm.registerOutParameter(84, java.sql.Types.NUMERIC);
cStm.registerOutParameter(85, java.sql.Types.NUMERIC);
cStm.registerOutParameter(86, java.sql.Types.NUMERIC);
cStm.registerOutParameter(87, java.sql.Types.VARCHAR);
cStm.registerOutParameter(88, java.sql.Types.VARCHAR);
cStm.registerOutParameter(89, java.sql.Types.DATE);
cStm.execute();
When the statement is no server side prepared (prepareThreshold is not reached) the SP call works perfectly.
On the other hand, if we reach the prepareThreshold, we have this exception invoking the SP:
java.lang.IllegalArgumentException: Can't change resolved type for param: 84 from 2278 to 1700
at org.postgresql.core.v3.SimpleParameterList.setResolvedType(SimpleParameterList.java:348)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2151)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:355)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:490)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:408)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:166)
at org.postgresql.jdbc.PgCallableStatement.executeWithFlags(PgCallableStatement.java:83)
at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:155)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at com.zaxxer.hikari.pool.HikariProxyCallableStatement.execute(HikariProxyCallableStatement.java)
....
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:170)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:660)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:524)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:474)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:476)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:434)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:408)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:69)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:492)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:249)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:60)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)
Debugging we saw that out parameters when the server side statement is enabled are treated as JavaObject in the metadata, and are numerics in the call and the SP code. When the exception comes, another connection is created and we have a few successful calls until we reach the threshold again.
Turning off server side statements with prepareThreshold=0 fixes the error but it is very inefficient in comparison. And this disables the server side statement for every statement in the app (we have hundreds per transaction), in the end it's not an option for us.
Why does the server side statement change the parameters metadata when it is activated?
It's a problem with scalars types only (number, varchar)?
There is a chance to disable the server side statement for this sp call only?
Any help is appreciated
Thanks in advance
We found a workaround, it’s based on using CallableStatement#setNull in every out parameter to correct metadata that will be used in server side prepared statements.
Here the correction using the previous example:
cStm.setNull(84, java.sql.Types.NUMERIC);
cStm.setNull(85, java.sql.Types.NUMERIC);
cStm.setNull(86, java.sql.Types.NUMERIC);
cStm.setNull(87, java.sql.Types.VARCHAR);
cStm.setNull(88, java.sql.Types.VARCHAR);
cStm.setNull(89, java.sql.Types.DATE);
cStm.registerOutParameter(84, java.sql.Types.NUMERIC);
cStm.registerOutParameter(85, java.sql.Types.NUMERIC);
cStm.registerOutParameter(86, java.sql.Types.NUMERIC);
cStm.registerOutParameter(87, java.sql.Types.VARCHAR);
cStm.registerOutParameter(88, java.sql.Types.VARCHAR);
cStm.registerOutParameter(89, java.sql.Types.DATE);
There is an example in the documentation using setNull
Thanks
I want to make a project with Faktor IPS which is both a model project and a product deffinition project. And I want to and a UI using Linkki. Here is my project structure:
Project structure (Stack overflow won't let me add images, I hope the link works)
In the src/main/java folder are the classes to make the linkki UI and the .model.hausrat is the package where faktor ips generated the code for the policy components.
The policy components and product components are in the faktorips-repository-toc.xml in the folder src/main/resources under rg/linkki_framework/fips/Hausrat_linkki_app/model/internal/faktorips-repository-toc.xml
And this is what it looks like:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<FaktorIps-TableOfContents productDataVersion="0.0.1" xmlversion="3.0">
<ProductComponent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.deckungen.Fahrraddiebstahl___2022__01" ipsObjectId="beispiel.Fahrraddiebstahl 2022-01" ipsObjectQualifiedName="deckungen.Fahrraddiebstahl 2022-01" kindId="beispiel.Fahrraddiebstahl" versionId="2022-01" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/deckungen/Fahrraddiebstahl 2022-01.xml"/>
<ProductComponent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratGrunddeckungstyp" ipsObjectId="beispiel.HRD-Kompakt 2022-01" ipsObjectQualifiedName="deckungen.HRD-Kompakt 2022-01" kindId="beispiel.HRD-Kompakt" versionId="2022-01" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/deckungen/HRD-Kompakt 2022-01.xml"/>
<ProductComponent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratGrunddeckungstyp" ipsObjectId="beispiel.HRD-Optimal 2022-01" ipsObjectQualifiedName="deckungen.HRD-Optimal 2022-01" kindId="beispiel.HRD-Optimal" versionId="2022-01" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/deckungen/HRD-Optimal 2022-01.xml"/>
<ProductComponent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.deckungen.Ueberspannung___2022__01" ipsObjectId="beispiel.Ueberspannung 2022-01" ipsObjectQualifiedName="deckungen.Ueberspannung 2022-01" kindId="beispiel.Ueberspannung" versionId="2022-01" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/deckungen/Ueberspannung 2022-01.xml"/>
<PolicyCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.Deckung" ipsObjectId="hasurat.Deckung" ipsObjectQualifiedName="hasurat.Deckung"/>
<ProductCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.Deckungstyp" ipsObjectId="hasurat.Deckungstyp" ipsObjectQualifiedName="hasurat.Deckungstyp"/>
<PolicyCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratGrunddeckung" ipsObjectId="hasurat.HausratGrunddeckung" ipsObjectQualifiedName="hasurat.HausratGrunddeckung"/>
<ProductCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratGrunddeckungstyp" ipsObjectId="hasurat.HausratGrunddeckungstyp" ipsObjectQualifiedName="hasurat.HausratGrunddeckungstyp"/>
<ProductCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratProdukt" ipsObjectId="hasurat.HausratProdukt" ipsObjectQualifiedName="hasurat.HausratProdukt"/>
<PolicyCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratVertrag" ipsObjectId="hasurat.HausratVertrag" ipsObjectQualifiedName="hasurat.HausratVertrag"/>
<PolicyCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratZusatzdekung" ipsObjectId="hasurat.HausratZusatzdekung" ipsObjectQualifiedName="hasurat.HausratZusatzdekung"/>
<ProductCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratZusatzdekungstyp" ipsObjectId="hasurat.HausratZusatzdekungstyp" ipsObjectQualifiedName="hasurat.HausratZusatzdekungstyp"/>
<ProductCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.Produkt" ipsObjectId="hasurat.Produkt" ipsObjectQualifiedName="hasurat.Produkt"/>
<PolicyCmptType implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.Vertrag" ipsObjectId="hasurat.Vertrag" ipsObjectQualifiedName="hasurat.Vertrag"/>
<EnumContent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.Zahlweise" ipsObjectId="modell.hasurat.Zahlweise" ipsObjectQualifiedName="hasurat.Zahlweise.Type"/>
<ProductComponent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratProdukt" ipsObjectId="beispiel.HR-Kompakt 2022-01" ipsObjectQualifiedName="produkt.HR-Kompakt 2022-01" kindId="beispiel.HR-Kompakt" versionId="2022-01" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/produkt/HR-Kompakt 2022-01.xml"/>
<ProductComponent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.HausratProdukt" ipsObjectId="beispiel.HR-Optimal 2022-01" ipsObjectQualifiedName="produkt.HR-Optimal 2022-01" kindId="beispiel.HR-Optimal" versionId="2022-01" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/produkt/HR-Optimal 2022-01.xml"/>
<TableContent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.Tariftabelle" ipsObjectId="tabellen.Tariftabelle Kompakt" ipsObjectQualifiedName="tabellen.Tariftabelle Kompakt" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/tabellen/Tariftabelle Kompakt.xml"/>
<TableContent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.Tariftabelle" ipsObjectId="tabellen.Tariftabelle Optimal" ipsObjectQualifiedName="tabellen.Tariftabelle Optimal" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/tabellen/Tariftabelle Optimal.xml"/>
<TableContent implementationClass="org.linkki_framework.fips.Hausrat_linkki_app.model.hasurat.Tarifzonentabelle" ipsObjectId="tabellen.Tarifzonentabelle" ipsObjectQualifiedName="tabellen.Tarifzonentabelle" xmlResource="org/linkki_framework/fips/Hausrat_linkki_app/model/tabellen/Tarifzonentabelle.xml"/>
</FaktorIps-TableOfContents>
At one point I try to get a list of all product components that are instances of the HausratProdukt. like this:
private final List<HausratProdukt> produkte;
private IRuntimeRepository repository;
this.repository = PolicyRuntimeRepositoryLookup.getInstance().getRuntimeRepository();
this.produkte = repository.getAllProductComponents(HausratProdukt.class);
The class PolicyRuntimeRepositoryLookup looks like this:
public class PolicyRuntimeRepositoryLookup implements IRuntimeRepositoryLookup {
private static final long serialVersionUID = 1L;
private static final PolicyRuntimeRepositoryLookup SINGLETON = new PolicyRuntimeRepositoryLookup();
private static final String TOC_PATH = "org/linkki_framework/fips/Hausrat_linkki_app/model/internal/faktorips-repository-toc.xml";
//"de/faktorzehn/ipm/core/model/internal/faktorips-repository-toc.xml";
private transient IRuntimeRepository runtimeRepository;
private PolicyRuntimeRepositoryLookup() {
runtimeRepository = ClassloaderRuntimeRepository.create(TOC_PATH);
}
public static PolicyRuntimeRepositoryLookup getInstance() {
return SINGLETON;
}
#Override
public IRuntimeRepository getRuntimeRepository() {
return runtimeRepository;
}
private Object readResolve() {
return SINGLETON;
}
}
It crashes at the line:
this.produkte = repository.getAllProductComponents(HausratProdukt.class);
With the following error:
java.lang.RuntimeException: Can't load class org.linkki_framework.fips.Hausrat_linkki_app.model.deckungen.Ueberspannung___2022__01
at org.faktorips.runtime.internal.AbstractTocBasedRuntimeRepository.getClass(AbstractTocBasedRuntimeRepository.java:272)
at org.faktorips.runtime.internal.AbstractClassLoadingRuntimeRepository.getAllProductComponentsInternal(AbstractClassLoadingRuntimeRepository.java:329)
at org.faktorips.runtime.internal.AbstractRuntimeRepository.getAllProductComponents(AbstractRuntimeRepository.java:265)
at org.linkki_framework.fips.Hausrat_linkki_app.pmo.AngebotSectionPmo.<init>(AngebotSectionPmo.java:44)
at org.linkki_framework.fips.Hausrat_linkki_app.page.AngebotPage.createContent(AngebotPage.java:37)
at org.linkki_framework.fips.Hausrat_linkki_app.view.AngebotView.enter(AngebotView.java:47)
at com.vaadin.navigator.Navigator.performNavigateTo(Navigator.java:778)
at com.vaadin.navigator.Navigator.lambda$navigateTo$9a874efd$1(Navigator.java:702)
at com.vaadin.navigator.ViewBeforeLeaveEvent.navigate(ViewBeforeLeaveEvent.java:54)
at com.vaadin.navigator.View.beforeLeave(View.java:79)
at com.vaadin.navigator.Navigator.runAfterLeaveConfirmation(Navigator.java:730)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:701)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:678)
at org.linkki_framework.fips.Hausrat_linkki_app.menu.AngebotMenuItem.lambda$0(AngebotMenuItem.java:27)
at com.vaadin.ui.MenuBar.changeVariables(MenuBar.java:210)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:616)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:468)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:411)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:275)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1637)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:464)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.ClassNotFoundException: org.linkki_framework.fips.Hausrat_linkki_app.model.deckungen.Ueberspannung___2022__01
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.faktorips.runtime.internal.AbstractTocBasedRuntimeRepository.getClass(AbstractTocBasedRuntimeRepository.java:269)
... 60 more
I noticed that the faktorips-repository-toc.xml saves product components with an implementationClass of whatever Policy class they are a an instance of.
For example beispiel.HRD-Kompakt 2022-1 has an implementationClass of ...hasurat.HausratGrunddeckungstyp, but those product components that are actually instances of Zusatzdeckungstyp are saved in the toc.xml file with their actual name in the implementationClass.
For example ...deckungen.Ueberspannung___2022__01 instead of ...hasurat.HausratZusatzdekungstyp, which I would actually expect.
I have no idea why it saves only these differently, or how to change it, since this is a built in component of faktor ips.
Maybe the builtin method repository.getAllProductComponents(...) searches for classes in the src/main/java folder (where all the other classes are) and doesn't find these specific ones, which are in the src/main/resources folder?
But this too is automatically generated and I don't know how to change it. Of course I could manually move the classes into the src/main/java folder, but that would kind of defeat the purpose of it being automatically generated. Can anyone help?
The reason for the specific implementation classes is that you use formulas in those products. When using formulas with Faktor-IPS, there are two options:
Generating and compiling Java code for them
Generating Java code inside their XML files and interpreting it with a Groovy formula evaluator at runtime
You can choose, which option you use in a project in the 'Faktor-IPS Code Generator Settings' (rightclick on the project -> properties -> 'Faktor-IPS Code Generator Settings' or in the XML of the .ipsproject file). The property 'Formula Compiling' can be set to 'Subclass' for the first or 'XML' for the second option. The default value 'Both' generates table-of-contents-entries and Java classes like the first option and additionally Java code in the XMLs like the second.
When using Maven for your project, you need to adapt to the variant you choose. With variant 1, you need to make sure that Java files in src/main/resources are also compiled as described in https://www.faktorzehn.org/dokumentation/verwendung-von-faktor-ips-projekten-als-maven-dependencies/ :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>${project.basedir}/derived</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
If you choose the second option, you need to add a dependency to https://mvnrepository.com/artifact/org.faktorips/faktorips-runtime-groovy and add the formula evaluator to your repository with
repository.setFormulaEvaluatorFactory(new GroovyFormulaEvaluatorFactory());
I'm a newbee using google text-to-speech. the API work fine with Java 1.8 but when i had Mysql connectore driver in my pom.xml file i got a warning and an error Just on executing the QuickStart demo. here is my eclipse console.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:/C:/Users/LOGISPORT/.m2/repository/com/google/protobuf/protobuf-java/3.6.1/protobuf-java-3.6.1.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "grpc-default-executor-0" java.lang.NoSuchMethodError: 'boolean com.google.protobuf.GeneratedMessageV3.isStringEmpty(java.lang.Object)'
at com.google.cloud.texttospeech.v1.VoiceSelectionParams.getSerializedSize(VoiceSelectionParams.java:328)
at com.google.protobuf.CodedOutputStream.computeMessageSizeNoTag(CodedOutputStream.java:916)
at com.google.protobuf.CodedOutputStream.computeMessageSize(CodedOutputStream.java:668)
at com.google.cloud.texttospeech.v1.SynthesizeSpeechRequest.getSerializedSize(SynthesizeSpeechRequest.java:352)
at io.grpc.protobuf.lite.ProtoInputStream.available(ProtoInputStream.java:108)
at io.grpc.internal.MessageFramer.getKnownLength(MessageFramer.java:205)
at io.grpc.internal.MessageFramer.writePayload(MessageFramer.java:137)
at io.grpc.internal.AbstractStream.writeMessage(AbstractStream.java:65)
at io.grpc.internal.ForwardingClientStream.writeMessage(ForwardingClientStream.java:37)
at io.grpc.internal.DelayedStream$6.run(DelayedStream.java:283)
at io.grpc.internal.DelayedStream.drainPendingCalls(DelayedStream.java:182)
at io.grpc.internal.DelayedStream.access$100(DelayedStream.java:44)
at io.grpc.internal.DelayedStream$4.run(DelayedStream.java:148)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)
Is there an incompatility beetween MySql connector and Google text-to-speech ?
Here is a brief view of my code:
public static void main(String... args ) throws Exception {
String jsonPath = "accueil-mamoudzou.json";
ConnectBase();
String num = String.valueOf(Integer.valueOf("00013"));
CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(ServiceAccountCredentials.fromStream(new FileInputStream(jsonPath)));
TextToSpeechSettings settings = TextToSpeechSettings.newBuilder().setCredentialsProvider( credentialsProvider).build();
System.out.println("Settings créer ... Lancement de la traduction.");
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create(settings)){
SynthesisInput input = SynthesisInput.newBuilder().setText("Le numéro "+num+" est demandé à la porte 45. Merci").build();
VoiceSelectionParams voice =
VoiceSelectionParams.newBuilder()
.setName("fr-FR-Wavenet-E")
.setLanguageCode("fr-FR")
.setSsmlGender(SsmlVoiceGender.FEMALE)
.build();
AudioConfig audioConfig =
AudioConfig.newBuilder().setAudioEncoding(AudioEncoding.LINEAR16).build();
SynthesizeSpeechResponse response =
textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);
ByteString audioContents = response.getAudioContent();
// Write the response to the output file.
try (OutputStream out = new FileOutputStream("output.wav")) {
out.write(audioContents.toByteArray());
System.out.println("Audio content written to file output.wav");
out.close();
}
playSound();
}
}
and my pom.xml
<dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-texttospeech</artifactId>
<version>2.1.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.auth/google-auth-library-appengine -->
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-appengine</artifactId>
<version>1.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-storage -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.4.5</version>
</dependency>
</dependencies>
Try adding this to your pom.xml
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>25.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
It's said to address errors such as NoSuchMethodException and references protobuf directly (Among other things)
Source: https://cloud.google.com/java/docs/bom
I am trying to create REST APIs using jax-rs and encountering the following exception when fetching a particular instance using path param case.
Exception
2019-03-17 04:45:17 [FATAL] [ 59][internal.exceptions.DebugMapper:19] - javax.ws.rs.WebApplicationException: HTTP 500 Internal Server Error
at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:959)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:266)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:251)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:109)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:85)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1135)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:662)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:395)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:385)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:280)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[java.lang.NullPointerException]
at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:500)
at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:957)
... 41 more
Caused by: java.lang.NullPointerException
at org.hibernate.collection.internal.AbstractPersistentCollection.openTemporarySessionForLoading(AbstractPersistentCollection.java:275)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:198)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:561)
at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:132)
at org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:163)
at org.eclipse.persistence.internal.queries.CollectionContainerPolicy.iteratorFor(CollectionContainerPolicy.java:171)
at org.eclipse.persistence.internal.oxm.XMLCompositeCollectionMappingNodeValue.marshal(XMLCompositeCollectionMappingNodeValue.java:92)
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:149)
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102)
at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59)
at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:443)
at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:243)
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118)
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1)
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:766)
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshalStreamOrWriter(XMLMarshaller.java:1147)
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:934)
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:877)
at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:496)
... 42 more
Following is the gradle artifact configuration :
compile 'org.glassfish.jersey.core:jersey-client:2.6'
compile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.26'
compile 'org.glassfish.jersey.inject:jersey-hk2:2.26'
compile 'org.glassfish.jersey.media:jersey-media-moxy:2.26'
compile 'org.testng:testng:6.9.10'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.5'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.5'
compile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.9.5'
compile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.9.5'
compile 'com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.5'
compile 'javax.ejb:javax.ejb-api:3.2.2'
//compile 'org.hibernate:hibernate-annotations:3.5.6-Final'
compile 'org.hibernate.common:hibernate-commons-annotations:4.0.5.Final'
compile 'org.hibernate:hibernate-core:4.3.8.Final'
compile 'org.hibernate:hibernate-validator:4.3.2.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.16.Final'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
compile 'org.hibernate.validator:hibernate-validator:6.0.9.Final'
compile 'org.javassist:javassist:3.22.0-GA'
compile 'mysql:mysql-connector-java:8.0.14'
compile 'org.apache.logging.log4j:log4j-api:2.10.0'
compile 'org.apache.logging.log4j:log4j-core:2.10.0'
compile 'org.apache.logging.log4j:log4j-web:2.10.0'
def tomcatVersion = '7.0.57'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
Could anyone please suggest any solution.
I have tried with 2.26, 2.27 and 2.28 versions of org.glassfish.jersey.media:jersey-media-moxy but still facing the same issue. With lower versions of moxy, I am running into some more compatibility issues.
Please note, I am using only the web.xml for configuring the application.
I am trying to read a csv (native) file from an S3 bucket using a locally running Spark - Scala. I am able to read the file using the http protocol but I intend to use the s3a protocol.
Below is the configuration setup before the call.
val awsId = System.getenv("AWS_ACCESS_KEY_ID")
val awsKey = System.getenv("AWS_SECRET_ACCESS_KEY")
sc.hadoopConfiguration.set("fs.s3a.access.key", awsId)
sc.hadoopConfiguration.set("fs.s3a.secret.key", awsKey)
sc.hadoopConfiguration.set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem")
sc.hadoopConfiguration.set("fs.s3a.aws.credentials.provider","org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider");
sc.hadoopConfiguration.set("com.amazonaws.services.s3.enableV4", "true")
sc.hadoopConfiguration.set("fs.s3a.endpoint", "us-east-1.amazonaws.com")
sc.hadoopConfiguration.set("fs.s3a.impl.disable.cache", "true")
here
Read the file and print the first 5 rows from the rdd/dataframe
val fileAPath = Files.s3aPath(Files.input);
println("reading file s3", fileAPath)
// s3a://bucket-name/dataSets/policyoutput.csv
val df = sc.textFile(fileAPath);
df.take(5).foreach(println);
I am getting the below exception
Exception in thread "main" com.amazonaws.services.s3.model.AmazonS3Exception: Status Code: 400, AWS Service: Amazon S3, AWS Request ID: FD92FDC175C64AA2, AWS Error Code: null, AWS Error Message: Bad Request, S3 Extended Request ID: IuloUEASgqnY4lrSMpbyJpwgFfCFbttxuxmJ9hGHMUgZTbO/UR/YyDgjix+3rBe0Y4MQHPzNvhA=
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:798)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:421)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:232)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3528)
at com.amazonaws.services.s3.AmazonS3Client.headBucket(AmazonS3Client.java:1031)
at com.amazonaws.services.s3.AmazonS3Client.doesBucketExist(AmazonS3Client.java:994)
at org.apache.hadoop.fs.s3a.S3AFileSystem.initialize(S3AFileSystem.java:154)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2669)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:370)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:295)
at org.apache.hadoop.mapred.FileInputFormat.singleThreadedListStatus(FileInputFormat.java:258)
at org.apache.hadoop.mapred.FileInputFormat.listStatus(FileInputFormat.java:229)
at org.apache.hadoop.mapred.FileInputFormat.getSplits(FileInputFormat.java:315)
at org.apache.spark.rdd.HadoopRDD.getPartitions(HadoopRDD.scala:194)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:252)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:250)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.rdd.RDD.partitions(RDD.scala:250)
at org.apache.spark.rdd.MapPartitionsRDD.getPartitions(MapPartitionsRDD.scala:35)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:252)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:250)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.rdd.RDD.partitions(RDD.scala:250)
at org.apache.spark.rdd.RDD$$anonfun$take$1.apply(RDD.scala:1333)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:112)
at org.apache.spark.rdd.RDD.withScope(RDD.scala:362)
at org.apache.spark.rdd.RDD.take(RDD.scala:1327)
Any help / direction for further investigation will be much appreciated.
Thanks
Anyone else struggling with this I had to update the version of hadoop-client
additionally the links below were quite helpful
https://hadoop.apache.org/docs/current/hadoop-aws/tools/hadoop-aws/index.html
https://disqus.com/by/cfeduke/?utm_source=reply&utm_medium=email&utm_content=comment_author
http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
pom details below
<properties>
<spark.version>2.2.0</spark.version>
<hadoop.version>2.8.0</hadoop.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.11 -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-aws</artifactId>
<version>${hadoop.version}</version>
</dependency>