IllegalStateException in primefaces dropdown - java

I have a datatable which contains a dropdown, when I change the value in dropdown I am getting an exception saying IllegalStateException.
The datatable code is shared below.
<p:column width="180">
<f:facet name="header">
<h:outputText value="Data Type" />
</f:facet>
<p:selectOneMenu value="#{column.dataTypeConfigNameWithId}"
rendered="#{column.editHeaderDetails}"
valueChangeListener="#{returnHeaderBean.dataTypeChangeAction}"
style="width:280px">
<f:selectItems value="#{returnHeaderBean.dataTypes}"
var="dataType" itemLabel="#{dataTypestandardDataTypeDisplayName}"
itemDescription="#{dataType.dataTypeDescription}"
itemValue="#{dataType.standardDataTypeDisplayName}: #{dataType.id}" />
<p:ajax event="valueChange" process="cdHTable"
partialSubmit="true" update="#this" />
</p:selectOneMenu>
</p:column>
The Error which i am getting is
SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default
task-36) java.lang.IllegalStateException at
javax.faces.component.UIComponentBase.queueEvent(UIComponentBase.java:1052)
at
javax.faces.component.UIComponentBase.queueEvent(UIComponentBase.java:1054)
at javax.faces.component.UIInput.validate(UIInput.java:991) at
javax.faces.component.UIInput.executeValidate(UIInput.java:1248) at
javax.faces.component.UIInput.processValidators(UIInput.java:712) at
org.primefaces.component.api.UIData.process(UIData.java:339) at
org.primefaces.component.api.UIData.processChildren(UIData.java:323)
at org.primefaces.component.api.UIData.processPhase(UIData.java:285)
at
org.primefaces.component.api.UIData.processValidators(UIData.java:259)
at
org.primefaces.component.datatable.DataTable.processValidators(DataTable.java:622)
at
com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:575)
at
com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:692) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIForm.visitTree(UIForm.java:371) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
at
com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266)
at
org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1193)
at
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
at
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
at
io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
at
io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
at
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
at
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
at
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
at
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
at
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
at
io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
at
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
at
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
at
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
at
io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
at
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Bean Method called
public void dataTypeChangeAction(ValueChangeEvent vEvent) {
LOGGER.info("Inside dataTypeNameChange()");
try {
String typeNameWithId = (String) vEvent.getNewValue();
if (typeNameWithId != null) {
String[] dataTypeArray = typeNameWithId.split(":");
ReturnHeader column = (ReturnHeader) bindHdrElementsTable.getRowData();
column.getDataTypeConfig().setStandardDataTypeDisplayName(dataTypeArray[0]);
column.getDataTypeConfig().setId(Integer.parseInt(dataTypeArray[1]));
column.setDataTypeConfigId(Integer.parseInt(dataTypeArray[1]));
}
} catch (Exception e) {
LOGGER.error(e);
}
}

Related

ClosedChannelException on FluentProducerTemplate with Apache Camel

I'm facing ClosedChannelException with my app, when I'm testing Apache Camel route.
rest().post("/{{camel.rest.version}}/ufx")
.type(MyMsg.class)
.consumes(MediaType.APPLICATION_XML_VALUE)
.produces(MediaType.APPLICATION_XML_VALUE)
.responseMessage().code(HttpStatus.SC_OK).responseModel(MyMsg.class).endResponseMessage()
.responseMessage().code(HttpStatus.SC_BAD_REQUEST).responseModel(MyMsg.class).endResponseMessage()
.route().routeId("rst_myrest")
.to("direct:route_myroute")
.endRest();
onException(ValidationException.class).
handled(true).
log(LoggingLevel.ERROR, LoggingConst.ERROR +" Validation exception: ${body}").
onExceptionOccurred(validationExceptionProcessor).
marshal().jaxb(MyMsg.class.getPackage().getName()).
log(LoggingLevel.INFO, "Error response ${body}").
end();
from("direct:route_myroute").routeId("rt_ufx")
.unmarshal().jaxb(MyMsg.class.getPackage().getName())
.process("myvalidator")
//some other lines
.marshal().jaxb(MyMsg.class.getPackage().getName())
.end();
In my test, invalid data is passed, so ValidationExceptionProcessor is invoked.
public class ValidationExceptionProcessor implements Processor {
#Override
public void process(Exchange exchange) throws Exception {
ValidationException request = exchange.getException(ValidationException.class);
MyMsg msg = new MyMsg();
//preparing some pretty object
exchange.getOut().setBody(msg);
exchange.getOut().setHeader("CamelHttpResponseCode", HttpStatus.BAD_REQUEST);
}
}
It works fine when I'm invoking my app directly (from Postman, for example). Correct MyMsg object is logged and returned to user.
Junit-test FluentProducerTemplate is used to check the result:
#RunWith(CamelSpringBootRunner.class)
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
#DirtiesContext
#Slf4j
#UseAdviceWith
public class myTest {
#Produce(uri = "undertow:myaddress")
FluentProducerTemplate holdProducer;
#Test
public void invalidDataException() throws IOException, InterruptedException {
Exchange send = holdProducer.withHeader(Exchange.HTTP_METHOD, HttpMethod.POST)
.withHeader(Exchange.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE)
.withBody(Files.readAllBytes(Paths.get("src/test/resources/Request.xml")))
.send();
Exception exception = send.getException(); //here I get java.nio.channels.ClosedChannelException
}
}
Logs:
{"timestamp":"2018-10-30T15:04:12.779+00:00","level":"WARN","logger_name":"org.apache.camel.util.IOHelper","stack_trace":"java.nio.channels.ClosedChannelException: null
at io.undertow.server.protocol.http.HttpResponseConduit.processWrite(HttpResponseConduit.java:122)
at io.undertow.server.protocol.http.HttpResponseConduit.write(HttpResponseConduit.java:596)
at io.undertow.conduits.ChunkedStreamSinkConduit.flush(ChunkedStreamSinkConduit.java:267)
at org.xnio.conduits.ConduitStreamSinkChannel.flush(ConduitStreamSinkChannel.java:162)
at io.undertow.channels.DetachableStreamSinkChannel.flush(DetachableStreamSinkChannel.java:119)
at org.xnio.channels.Channels.flushBlocking(Channels.java:63)
at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputStreamImpl.java:612)
at org.apache.camel.util.IOHelper.close(IOHelper.java:342)
at org.apache.camel.util.IOHelper.close(IOHelper.java:406)
at org.apache.camel.util.IOHelper.close(IOHelper.java:416)
at org.apache.camel.http.common.DefaultHttpBinding.copyStream(DefaultHttpBinding.java:434)
at org.apache.camel.http.common.DefaultHttpBinding.doWriteDirectResponse(DefaultHttpBinding.java:496)
at org.apache.camel.http.common.DefaultHttpBinding.doWriteResponse(DefaultHttpBinding.java:395)
at org.apache.camel.http.common.DefaultHttpBinding.writeResponse(DefaultHttpBinding.java:322)
at org.apache.camel.http.common.CamelServlet.doService(CamelServlet.java:209)
at org.apache.camel.http.common.CamelServlet.service(CamelServlet.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:208)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilte rInternal(HiddenHttpMethodFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:211)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:809)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
","message":"Cannot close. Reason: null","camel.exchangeId":"ID-VRN26-1540911805592-0-3","camel.contextId":"","camel.breadcrumbId":"ID-VRN26-1540911805592-0-1","camel.messageId":"ID-VRN26-1540911805592-0-4"}
What is the difference between invoking from Fluent and a running app directly? How can it be fixed?
P.S.Changing message output to In() doesn't help
I found a solution, but not in the place I was looking for. Here is my Http code set:
exchange.getOut().setHeader("CamelHttpResponseCode", HttpStatus.BAD_REQUEST);
HttpStatus.BAD_REQUEST is a Spring enum entry. And the result is a enum value:
BAD_REQUEST(400, "Bad Request"),
When my app was run inside Spring container, Spring did the enum-value unmarshal and I received a correct body with Http-400 code.
However with FluentProducerTemplate (with belongs to camel-libraries), no unmarshalling was done, and fluent crashes somewhere. (I do wonder where and why exactly. And why the error is so weird).
Switching to Camel header solved my problem
exchange.getOut().setHeader("CamelHttpResponseCode", HttpStatus.SC_BAD_REQUEST);
because Camel httpHeaders are not a enum, but a public-static-final field
public static final int SC_BAD_REQUEST = 400;
it also works fine if you call .value() for Spring enum
exchange.getOut().setHeader("CamelHttpResponseCode", HttpStatus.BAD_REQUEST.value());

How to download a .jar file from a URL

I have to download a .jar file from a remote kie maven repository which requires authentication using my java code.
The code is as follows.
String url = "http://localhost:18080/kiewb/maven2/group/artifact/version/file.jar";
UrlResource urlResource = (UrlResource) resources.newUrlResource(url);
urlResource.setUsername("username");
urlResource.setPassword("password");
urlResource.setBasicAuthentication("enabled");
InputStream is = urlResource.getInputStream();
But, its throwing
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL:http://localhost:18080/kiewb/maven2/group/artifact/version/file.jar
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
at url.main(url.java:47)
And in the server in which the maven repo is, I am getting the following error.
My server is Wildfly10.
ERROR [io.undertow.request] (default task-58) UT005023: Exception handling request to /kiewb/maven2/group/artifact/version/file.jar: java.lang.ArrayIndexOutOfBoundsException: 1
at org.uberfire.ext.security.server.BasicAuthSecurityFilter.authenticate(BasicAuthSecurityFilter.java:112)
at org.uberfire.ext.security.server.BasicAuthSecurityFilter.doFilter(BasicAuthSecurityFilter.java:69)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.uberfire.ext.security.server.SecureHeadersFilter.doFilter(SecureHeadersFilter.java:69)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.uberfire.ext.security.server.SecurityIntegrationFilter.doFilter(SecurityIntegrationFilter.java:57)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:59)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
And the same jar I am able to download it by directly hitting the URL in the browser.
Try another way to download. Note that it should be Java 8
public void downloadFile(String fromUrl, String localFileName) throws IOException {
File localFile = new File(localFileName);
if (localFile.exists()) {
localFile.delete();
}
localFile.createNewFile();
URL url = new URL(fromUrl);
OutputStream out = new BufferedOutputStream(new FileOutputStream(localFileName));
URLConnection conn = url.openConnection();
String encoded = Base64.getEncoder().encodeToString(("username"+":"+"password").getBytes(StandardCharsets.UTF_8)); //Java 8
conn.setRequestProperty("Authorization", "Basic "+ encoded);
InputStream in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
}
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
Simply rename the newest file to file name that is in your application and then download it. The example above is very good for launchers, because it delete the old file.

Java transactions don't work when multiple entity managers are used

I have been working a couple of weeks on a requirement that requires modifing some methods that are using transactions, the code between the transaccion can read/update/delete/etc elements in the database(PostgreSQL) through the application. At this moment, the application is using a peristence unit (pointing to a wildfly datasource) and an entity manager to access the database:
For example:
#PersistenceContext( unitName="name", type = PersistenceContextType.TRANSACTION )
protected EntityManager em;
public String updateReadRead()
{
try
{
TransactionUtil.begin( this.utx );
Query nativeQuery = this.em.createNativeQuery("update schema.company_info set service_manager_phone_ext = '1004';");
int i = nativeQuery.executeUpdate();
this.searchCriteriaApplication.trimVo();
this.searchCriteriaCustomer.trimVo();
this.searchResults = this.applicationSearchService.searchApplications( this.searchCriteriaApplication, this.searchCriteriaCustomer, this.em, false, true );
this.showAccountsForCustomer = false;
this.applicationSearchService.searchApplications( this.searchCriteriaApplication, this.searchCriteriaCustomer, this.em, false, true );
TransactionUtil.commit(this.utx);
}
catch ( Exception e )
{
}
return null;
}
But now, we want to use two entity managers,one in charge of the write operations (pointing to a transaccional Data Base) and the other one for read operations (pointing to a replica Data Base (ReadOnly DataBase)), for example:
#PersistenceContext( unitName="readonly", type = PersistenceContextType.TRANSACTION )
protected EntityManager readOnlyEM;
#PersistenceContext( unitName="readwrite", type = PersistenceContextType.TRANSACTION )
protected EntityManager readWriteEM;
public String updateReadRead()
{
try
{
TransactionUtil.begin( this.utx );
Query nativeQuery = this.readWriteEM.createNativeQuery("update schema.company_info set service_manager_phone_ext = '1004';");
int i = nativeQuery.executeUpdate();
this.searchCriteriaApplication.trimVo();
this.searchCriteriaCustomer.trimVo();
this.searchResults = this.applicationSearchService.searchApplications( this.searchCriteriaApplication, this.searchCriteriaCustomer, this.readOnlyEM, false, true );
this.showAccountsForCustomer = false;
this.applicationSearchService.searchApplications( this.searchCriteriaApplication, this.searchCriteriaCustomer, this.readOnlyEM, false, true );
TransactionUtil.commit(this.utx);
}
catch ( Exception e )
{
}
return null;
}
I have tried two approaches:
Create a new entityManager pointing to the readonly database. It fails when we use the readonly entityManager and then, change to the write entityManager or vice versa (All ot this in the same transaction).
If we use two transactions, one for read operatios and the other one for write operations, it works.
(Please check error stacktrace below):
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:995)
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:920)
at org.hibernate.internal.SessionImpl.remove(SessionImpl.java:3341)
at org.jboss.as.jpa.container.AbstractEntityManager.remove(AbstractEntityManager.java:655)
at com.snap.web.bean.SmartEntityManager.remove(SmartEntityManager.java:68)
at com.snap.event.EventService.delete(EventService.java:221)
at com.snap.accountmanager.AccountManagerService.deletePriorityNote(AccountManagerService.java:3877)
at com.snap.api.AccountManagementResource.deletePriorityNote_aroundBody38(AccountManagementResource.java:1878)
at com.snap.api.AccountManagementResource$AjcClosure39.run(AccountManagementResource.java:1)
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)
at com.snap.common.log.MethodLogger.around(MethodLogger.java:62)
at com.snap.api.AccountManagementResource.deletePriorityNote(AccountManagementResource.java:1863)
at com.snap.api.AccountManagementResource$Proxy$_$$_WeldClientProxy.deletePriorityNote(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:209)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:130)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:162)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:201)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:178)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at
Use distributed transactions. I configured two new XA Data Sources and two new pesistence units associated to those datasources. I changed the entityManagers to point those new persistence units but the transaction fails when it tries to commit. I already set the max_prepared_transactions with the same value as maxSession property in both databases as the documentation suggests.
See stacktrace below:
javax.transaction.HeuristicMixedException
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1208)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:89)
at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:178)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:433)
at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:42)
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
at org.jboss.weldx.transaction.UserTransaction$112420245$Proxy$_$$_Weld$Proxy$.commit(Unknown Source)
at com.snap.common.utils.TransactionUtil.commit(TransactionUtil.java:71)
at com.snap.web.bean.application.SearchApplicationTransactionTests.smart_aroundBody4(SearchApplicationTransactionTests.java:339)
at com.snap.web.bean.application.SearchApplicationTransactionTests$AjcClosure5.run(SearchApplicationTransactionTests.java:1)
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)
at com.snap.common.log.MethodLogger.around(MethodLogger.java:62)
at com.snap.web.bean.application.SearchApplicationTransactionTests.smart(SearchApplicationTransactionTests.java:287)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:130)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:162)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:201)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:178)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:59)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Suppressed: org.postgresql.xa.PGXAException: Error preparing transaction
at org.postgresql.xa.PGXAConnection.prepare(PGXAConnection.java:323)
at org.jboss.jca.adapters.jdbc.xa.XAManagedConnection.prepare(XAManagedConnection.java:330)
at com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord.topLevelPrepare(XAResourceRecord.java:218)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2662)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2612)
at com.arjuna.ats.arjuna.coordinator.BasicAction.prepare(BasicAction.java:2155)
at com.arjuna.ats.arjuna.coordinator.BasicAction.End(BasicAction.java:1501)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:96)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1200)
... 97 more
Caused by: org.postgresql.util.PSQLException: ERROR: cannot execute PREPARE TRANSACTION during recovery
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:244)
at org.postgresql.xa.PGXAConnection.prepare(PGXAConnection.java:315)
... 106 more
Suppressed: org.postgresql.xa.PGXAException: Error rolling back prepared transaction
at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:415)
at org.jboss.jca.adapters.jdbc.xa.XAManagedConnection.rollback(XAManagedConnection.java:346)
at com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord.topLevelAbort(XAResourceRecord.java:369)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doAbort(BasicAction.java:3017)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doAbort(BasicAction.java:2996)
at com.arjuna.ats.arjuna.coordinator.BasicAction.phase2Abort(BasicAction.java:1979)
at com.arjuna.ats.arjuna.coordinator.BasicAction.End(BasicAction.java:1517)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:96)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1200)
... 97 more
Caused by: org.postgresql.util.PSQLException: ERROR: cannot execute ROLLBACK PREPARED during recovery
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:244)
at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:405)
... 106 more
Is any of these approches correct? in order to continue testing or is there a better solution to achieve the requeriment?
I will appreciate any suggestion.
Thanks.

How to get global variables from jbpm-process within WorkItem

I can successfully retrieve global variables (such as NodeInstance, ProcessInstance and so on) from within the process with help of Script-Task and kcontext-instance; But what if I need retrieve those global variables within WorkItem? I could of course put Script-Task before my WorkItem within Process and then assign a global variable to one of Variable Definitions, in order to use it within WorkItem with getParameter()-method;
But we do understand, that it is double made work, doesn't we?
So how could I get global variables within WorkItem without additional Script-Task? I thought firstly, that I could use the same name of the session within WorkItem, such we define by registering WorkItem in KieWorkBench, that's why I created a ProcessContext within my WI as follows:
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-process");
ProcessContext context = new ProcessContext(kSession);
Map<String, Object> params = new HashMap<>();
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
params.put("lane", context.getNodeInstance().getNode().getMetaData().get("Lane").toString());
manager.completeWorkItem(workItem.getId(), params);
}
With this code snippet within executeWorkItem(), but rather with kcontext in Script-Task I can retrieve successfuly the name of the Lane and assign it to variable, but when I execute the process with this WorkItem I get an Error - WorkItem -- null not by deploying, rather by starting the process; Of course I also registry the same ksession - name as within WorkItem (namely "ksession-process") in KieWorkBench, but apparently I cannot use the context this way, as I thought.
So I really appreciate your help! It doesn't really bother, but to make a code resp. BProcess a little bit concisely and without any redundant variables, it pays to ask.
jBPM 6.4, wildfly 8.2
UPDATE:
as user livthomas has suggested, instead of WorkItemHandler interface I've tried to extend my class to AbstractWorkiItemHandler as follows:
public class WI extends AbstractWorkItemHandler {
public WI(StatefulKnowledgeSession ksession) {
super(ksession);
}
KieSession kSession = getSession();
ProcessContext context = new ProcessContext(kSession);
Map<String, Object> params = new HashMap<>();
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
params.put("lane", context.getNodeInstance().getNode().getMetaData().get("Lane"));
manager.completeWorkItem(workItem.getId(), params);
}
...
And then register it in Project's descriptor.xml as new my_package.WI(ksession);
Unfortunately I get the RuntimeException: cannot instance WorkItem...
UPDATE2: STACK TRACE
2016-09-13 11:49:59,355 ERROR [org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl] (default task-24) Deployment of unit testing:testing-work-item-handler:1.0 failed: java.lang.RuntimeException: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI: org.jbpm.console.ng.bd.exception.DeploymentException: java.lang.RuntimeException: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl.deploy(DeploymentManagerEntryPointImpl.java:203) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl.deploy(DeploymentManagerEntryPointImpl.java:158) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl.process(DeploymentManagerEntryPointImpl.java:517) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl$Proxy$_$$_WeldClientProxy.process(Unknown Source) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
at org.kie.workbench.common.services.backend.builder.BuildServiceImpl.doBuildAndDeploy(BuildServiceImpl.java:178) [kie-wb-common-services-backend-6.4.0.Final.jar:6.4.0.Final]
at org.kie.workbench.common.services.backend.builder.BuildServiceImpl.buildAndDeploy(BuildServiceImpl.java:134) [kie-wb-common-services-backend-6.4.0.Final.jar:6.4.0.Final]
at org.kie.workbench.common.services.backend.builder.BuildServiceImpl$Proxy$_$$_WeldClientProxy.buildAndDeploy(Unknown Source) [kie-wb-common-services-backend-6.4.0.Final.jar:6.4.0.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_72]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_72]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_72]
at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_72]
at org.jboss.errai.bus.server.io.AbstractRPCMethodCallback.invokeMethodFromMessage(AbstractRPCMethodCallback.java:48) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.io.ValueReplyRPCEndpointCallback.callback(ValueReplyRPCEndpointCallback.java:22) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.io.RemoteServiceCallback.callback(RemoteServiceCallback.java:54) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.cdi.server.CDIExtensionPoints$2.callback(CDIExtensionPoints.java:410) [errai-weld-integration-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.DeliveryPlan.deliver(DeliveryPlan.java:47) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.ServerMessageBusImpl.sendGlobal(ServerMessageBusImpl.java:296) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.SimpleDispatcher.dispatchGlobal(SimpleDispatcher.java:46) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.service.ErraiServiceImpl.store(ErraiServiceImpl.java:97) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.service.ErraiServiceImpl.store(ErraiServiceImpl.java:114) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.servlet.DefaultBlockingServlet.doPost(DefaultBlockingServlet.java:142) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at org.uberfire.ext.security.server.SecureHeadersFilter.doFilter(SecureHeadersFilter.java:69) [uberfire-servlet-security-0.8.0.Final.jar:0.8.0.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at org.uberfire.ext.security.server.SecurityIntegrationFilter.doFilter(SecurityIntegrationFilter.java:61) [uberfire-servlet-security-0.8.0.Final.jar:0.8.0.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:248) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:77) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:167) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:761) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_72]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_72]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_72]
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI
at org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:201) [jbpm-kie-services-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.services.cdi.impl.DeploymentServiceCDIImpl$Proxy$_$$_WeldClientProxy.deploy(Unknown Source) [jbpm-services-cdi-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl.deploy(DeploymentManagerEntryPointImpl.java:194) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
... 59 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI
at org.jbpm.kie.services.impl.AbstractDeploymentService.commonDeploy(AbstractDeploymentService.java:161) [jbpm-kie-services-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:196) [jbpm-kie-services-6.4.0.Final.jar:6.4.0.Final]
... 61 more
Caused by: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI
You need to either extend AbstractWorkItemHandler or implement your work item handler in a similar way. Then just pass ksession instance as a parameter of its constructor when you register it. Once you have a reference to KIE session, you can get global variables calling its getGlobals() method.

nested exception is org.hibernate.exception.SQLGrammarException: could not execute query

This is the error I am getting. I have been stuck for 2 hours but could not resolve it.My code for hibernate is as follows:-
Session session1=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory().openSession();
org.hibernate.cfg.Configuration cfg=new org.hibernate.cfg.Configuration();
cfg.configure("hibernate.cfg.xml");
//creating seession factory object
SessionFactory factory=cfg.buildSessionFactory();
//creating session object
Session session=factory.openSession();
String hql = "SELECT E.id FROM User E where firstName=:name";
SQLQuery query = session1.createSQLQuery(hql);
query.setParameter("name", name);
List results = query.list();
Iterator itr=results.iterator();
String id="";
while(itr.hasNext()){ id=String.valueOf(itr.next());}
//creating transaction object
Transaction t=session.beginTransaction();
User employee =
(User)session.get(User.class, 2);
employee.setMessage(chat);
session.update(employee);
//template.save(e1);
//session.persist(user);//persisting the object
t.commit();//transaction is committed
session.close();
return "hello";
Any help would be appreciated..thanx in advance.
My full stack trace is as follows:-
Stack Trace
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:943)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)
javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:74
5)
Try this
String hql = "SELECT u.id FROM User u where u.firstName = :name";
Query query = session1.createQuery(hql);
query.setParameter("name", name);
List results = query.getResultList();
Iterator itr=results.iterator();
String id="";
while(itr.hasNext()){ id=String.valueOf(itr.next());}

Categories

Resources