Getting "StatusCodeException" when trying to execute action - gwt-rpc

i am using GWT/GWTP (2.6.0/1.2.1). I am trying to execute an Action. The action itself is just a signal (no logic or data elements). The result is supposed to carry an ArrayList of DTOs.
When i use the exact same setup with another action (containing a string) it works fine.
I get this error:
[ERROR] com.google.gwt.user.client.rpc.StatusCodeException: 500 Server
Error The call failed on the server; see server log for details
[ERROR] at
com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209)
[ERROR] at
com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:259)
[ERROR] at
com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) [ERROR] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[ERROR] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:606) [ERROR]
at
com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
[ERROR] at
com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
[ERROR] at
com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
[ERROR] at
com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
[ERROR] at
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
[ERROR] at
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
[ERROR] at
com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
[ERROR] at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
[ERROR] at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
[ERROR] at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
[ERROR] at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:347)
[ERROR] at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown
Source) [ERROR] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:606) [ERROR]
at
com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
[ERROR] at
com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
[ERROR] at
com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
[ERROR] at
com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
[ERROR] at
com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
[ERROR] at
com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
[ERROR] at java.lang.Thread.run(Thread.java:744)
What do i miss?
My Action looks like this:
package testproject.shared.dispatch;
import com.gwtplatform.dispatch.rpc.shared.UnsecuredActionImpl;
public class FetchDevicesAction extends UnsecuredActionImpl<FetchDevicesResult> {
public FetchDevicesAction() {
}
}
My Result like this (is this where the problem lies?):
package testproject.shared.dispatch;
import java.util.List;
//import org.apache.log4j.xml.DOMConfigurator;
import testproject.shared.dto.DeviceDto;
import com.allen_sauer.gwt.log.client.Log;
import com.gwtplatform.dispatch.rpc.shared.Result;
public class FetchDevicesResult implements Result {
/**
*
*/
private static final long serialVersionUID = -6478205044537244983L;
private List<DeviceDto> deviceDtos;
public FetchDevicesResult(List<DeviceDto> deviceDtos) {
this.deviceDtos = deviceDtos;
}
public List<DeviceDto> getDeviceDtos() {
return deviceDtos;
}
}
Here is part of my presenter:
public class DevicesPresenter extends
Presenter<DevicesPresenter.MyView, DevicesPresenter.MyProxy> implements
DevicesUiHandlers {
Logger logger = Logger.getLogger("RootLogger");
List<Device> devices = null;
List<DeviceDto> deviceDtos = null;
/**
* {#link DevicesPresenter}'s proxy.
*/
#ProxyCodeSplit
#NameToken(NameTokens.devicesPage)
#TabInfo(container = ApplicationPresenter.class, label = "Devices", priority = 1)
// The third tab in the main page
public interface MyProxy extends TabContentProxyPlace<DevicesPresenter> {
}
/**
* {#link DevicesPresenter}'s view.
*/
public interface MyView extends View, HasUiHandlers<DevicesUiHandlers> {
CellTable<Device> getCellTable();
}
private DispatchAsync dispatcher;
#Inject
DevicesPresenter(EventBus eventBus, MyView view, MyProxy proxy,
final DispatchAsync dispatcher) {
super(eventBus, view, proxy, ApplicationPresenter.SLOT_SetTabContent);
this.dispatcher = dispatcher;
view.setUiHandlers(this);
}
public void fetchDevicesTask() {
FetchDevicesAction action = new FetchDevicesAction();
Log.debug("Executing FetchDevices");
dispatcher.execute(action, new AsyncCallbackImpl<FetchDevicesResult>() {
#Override
public void onSuccess(FetchDevicesResult result) {
Log.debug("onSuccess");
deviceDtos = result.getDeviceDtos();
}
});
}
The shared libraries are part of my gwt.xml.
My DeviceDto:
package testproject.shared.dto;
import java.io.Serializable;
public class DeviceDto implements Serializable {
private static final long serialVersionUID = 3434148714982575460L;
protected Long DeviceId;
protected String Image;
protected String FirmwareVersion;
public DeviceDto() {
this.DeviceId = -1L;
}
public DeviceDto(Long DeviceId) {
this.DeviceId = DeviceId;
}
public DeviceDto(Long DeviceId, String Image, String FirmwareVersion) {
this.DeviceId = DeviceId;
this.Image = Image;
this.FirmwareVersion = FirmwareVersion;
}
public Long getDeviceId() {
return DeviceId;
}
public void setDeviceId(Long DeviceId) {
this.DeviceId = DeviceId;
}
public String getImage() {
return Image;
}
public void setImage(String Image) {
this.Image = Image;
}
public String getFirmwareVersion() {
return FirmwareVersion;
}
public void setFirmwareVersion(String FirmwareVersion) {
this.FirmwareVersion = FirmwareVersion;
}
My Handler (even though i think it does not get this far):
package testproject.server.dispatch;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.xml.DOMConfigurator;
import testproject.server.dao.DeviceDao;
import testproject.shared.dispatch.FetchDevicesAction;
import testproject.shared.dispatch.FetchDevicesResult;
import testproject.shared.domain.Device;
import testproject.shared.dto.DeviceDto;
import com.allen_sauer.gwt.log.client.Log;
import com.google.inject.Inject;
import com.gwtplatform.dispatch.rpc.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;
public class FetchDevicesHandler extends AbstractAction<FetchDevicesAction, FetchDevicesResult> {
#Inject
FetchDevicesHandler() {
super(FetchDevicesAction.class);
DOMConfigurator.configure("log4j.xml");
}
#Override
public FetchDevicesResult execute(FetchDevicesAction action, ExecutionContext context) throws ActionException {
FetchDevicesResult result = null;
DeviceDao deviceDao = new DeviceDao();
Log.debug("Retrieve Devices");
try {
List<Device> devices = deviceDao.retrieveDevices();
if (devices != null) {
List<DeviceDto> deviceDtos = new ArrayList<DeviceDto>(devices.size());
for (Device device : devices) {
Log.debug("Adding Device to dto list: " + device.getDeviceId().toString());
deviceDtos.add(createDeviceDto(device));
}
result = new FetchDevicesResult(deviceDtos);
}
}
catch (Exception e) {
Log.warn("Unable to retrieve Accounts - ", e);
throw new ActionException(e);
}
return result;
}
private DeviceDto createDeviceDto(Device device) {
return new DeviceDto(device.getDeviceId(), device.getImage(), device.getFirmwareVersion());
}
}
I googled and searched stackoverflow, but this error message seems not to happen anywhere else.
Thank you for your help :)
}

Related

Error org.picocontainer.PicoCompositionException: Duplicate Keys not allowed. Duplicate

I was trying to achieve, Cucumber feature level parallel execution using pico Container.
When I am using a shared Driver in a context Class as below, I get org.picocontainer.PicoCompositionException: Duplicate Keys not allowed. Duplicate
public class Context{
private ThreadLocal<WebDriver> drivers = new ThreadLocal<>();
public void setDriver(WebDriver wd) {
drivers.set(wd);
}
public WebDriver getDriver() {
return drivers.get();
}
//Runner Class
import java.net.MalformedURLException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.CucumberFeatureWrapper;
import cucumber.api.testng.TestNGCucumberRunner;
import net.thumbtack.cucumber.picocontainer.example.step.SharedDriver;
import cucumber.api.testng.*;
#CucumberOptions (glue = {"net.thumbtack.cucumber.picocontainer.example.step"},
features = "src/main/resources/"
,tags = {"#Scenario2,#Scenario3"})
public class TestRunner {
public TestRunner() throws MalformedURLException {
super();
// TODO Auto-generated constructor stub
}
private TestNGCucumberRunner testNGCucumberRunner;
#BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
System.setProperty("ExecEnv","Docker");
}
// #Test(dataProvider = "features")
// public void feature(PickleEventWrapper eventwrapper,CucumberFeatureWrapper cucumberFeature) throws Throwable {
#Test(groups="cucumber", description="Runs CucumberFeature",dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature){
testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
// testNGCucumberRunner.runScenario(eventwrapper.getPickleEvent());
}
#DataProvider(parallel=true)
public Object[][] features() {
return testNGCucumberRunner.provideFeatures();
// return testNGCucumberRunner.provideScenarios();
}
#AfterClass(alwaysRun = true)
public void tearDownClass() throws Exception {
testNGCucumberRunner.finish();
}
}

A cycle is detected in the object graph. This will cause an infinite loop

People,
Looking for a little guidance. I am using Jersey 2.11 and generating JAXB definitions from XSD.
I have a periodic exception that seems to be timing based. If I change the timing of the message sent in anyway the error does not occur. The other issue is that the cycle reported in the error changes sometimes, however, the cycles reported can not occur based on the XSD definition. I have also dumped the message before sending and it definitely does not contain the cycle reported.
In this specific scenario, I am sending a message of NotificationType which contains a list of DocumentType, however, DocumentType can never contain NotificationType so the following cycle is not possible:
net.es.nsi.pce.discovery.jaxb.DocumentType#5a0eb1fc -> net.es.nsi.pce.discovery.jaxb.NotificationType#454b147c -> net.es.nsi.pce.discovery.jaxb.DocumentType#5a0eb1fc
I am wondering if there could be a different reason for receiving the following exception?
Thank you for the help.
[ERROR] [08/22/2014 13:11:45.126]
[NSI-DISCOVERY-akka.actor.default-dispatcher-5]
[akka://NSI-DISCOVERY/user/discovery-notificationRouter/$b] HTTP 500
Internal Server Error javax.ws.rs.ProcessingException: HTTP 500
Internal Server Error at
org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
at
org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:667)
at
org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:664)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at
org.glassfish.jersey.internal.Errors.process(Errors.java:297) at
org.glassfish.jersey.internal.Errors.process(Errors.java:228) at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
at
org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:664)
at
org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:424)
at
org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:333)
at
net.es.nsi.pce.discovery.actors.NotificationActor.onReceive(NotificationActor.java:100)
at
akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167)
at akka.actor.Actor$class.aroundReceive(Actor.scala:465) at
akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97) at
akka.actor.ActorCell.receiveMessage(ActorCell.scala:516) at
akka.actor.ActorCell.invoke(ActorCell.scala:487) at
akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238) at
akka.dispatch.Mailbox.run(Mailbox.scala:220) at
akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393)
at
scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at
scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at
scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at
scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: javax.ws.rs.InternalServerErrorException: HTTP 500 Internal
Server Error at
org.glassfish.jersey.message.internal.AbstractJaxbElementProvider.writeTo(AbstractJaxbElementProvider.java:152)
at
org.glassfish.jersey.message.internal.AbstractJaxbElementProvider.writeTo(AbstractJaxbElementProvider.java:85)
at
org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
at
org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
at
org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at
org.glassfish.jersey.filter.LoggingFilter.aroundWriteTo(LoggingFilter.java:293)
at
org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at
org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1154)
at
org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:503)
at
org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:315)
at
org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227)
at
org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
... 22 more Caused by: javax.xml.bind.MarshalException
- with linked exception: [Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b):
org.eclipse.persistence.exceptions.XMLMarshalException Exception
Description: An error occurred marshalling the object Internal
Exception: Exception [EclipseLink-25037] (Eclipse Persistence Services
- 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.XMLMarshalException Exception
Description: A cycle is detected in the object graph. This will cause
an infinite loop: net.es.nsi.pce.discovery.jaxb.DocumentType#5a0eb1fc
-> net.es.nsi.pce.discovery.jaxb.NotificationType#454b147c -> net.es.nsi.pce.discovery.jaxb.DocumentType#5a0eb1fc] at
org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:403)
at
org.glassfish.jersey.message.internal.XmlJaxbElementProvider.writeTo(XmlJaxbElementProvider.java:139)
at
org.glassfish.jersey.message.internal.AbstractJaxbElementProvider.writeTo(AbstractJaxbElementProvider.java:150)
... 33 more Caused by: Exception [EclipseLink-25003] (Eclipse
Persistence Services - 2.5.0.v20130507-3faac2b):
org.eclipse.persistence.exceptions.XMLMarshalException Exception
Description: An error occurred marshalling the object Internal
Exception: Exception [EclipseLink-25037] (Eclipse Persistence Services
- 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.XMLMarshalException Exception
Description: A cycle is detected in the object graph. This will cause
an infinite loop: net.es.nsi.pce.discovery.jaxb.DocumentType#5a0eb1fc
-> net.es.nsi.pce.discovery.jaxb.NotificationType#454b147c -> net.es.nsi.pce.discovery.jaxb.DocumentType#5a0eb1fc at
org.eclipse.persistence.exceptions.XMLMarshalException.marshalException(XMLMarshalException.java:97)
at
org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:911)
at
org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:848)
at
org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:401)
... 35 more Caused by: Exception [EclipseLink-25037] (Eclipse
Persistence Services - 2.5.0.v20130507-3faac2b):
org.eclipse.persistence.exceptions.XMLMarshalException Exception
Description: A cycle is detected in the object graph. This will cause
an infinite loop: net.es.nsi.pce.discovery.jaxb.DocumentType#5a0eb1fc
-> net.es.nsi.pce.discovery.jaxb.NotificationType#454b147c -> net.es.nsi.pce.discovery.jaxb.DocumentType#5a0eb1fc at
org.eclipse.persistence.exceptions.XMLMarshalException.objectCycleDetected(XMLMarshalException.java:400)
at
org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:207)
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.XMLCompositeObjectMappingNodeValue.marshalSingleValue(XMLCompositeObjectMappingNodeValue.java:237)
at
org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshal(XMLCompositeObjectMappingNodeValue.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:393)
at
org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:238)
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.XMLCompositeCollectionMappingNodeValue.marshalSingleValue(XMLCompositeCollectionMappingNodeValue.java:321)
at
org.eclipse.persistence.internal.oxm.XMLCompositeCollectionMappingNodeValue.marshal(XMLCompositeCollectionMappingNodeValue.java:104)
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:393)
at
org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:238)
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:743)
at
org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:901)
... 37 more
Notification.java
package net.es.nsi.pce.discovery.jaxb;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import org.w3c.dom.Element;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "NotificationType", namespace = "http://schemas.ogf.org/nsi/2014/02/discovery/types", propOrder = {
"discovered",
"event",
"document",
"any"
})
public class NotificationType {
#XmlElement(required = true)
#XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar discovered;
#XmlElement(required = true)
protected DocumentEventType event;
#XmlElement(required = true)
protected DocumentType document;
#XmlAnyElement(lax = true)
protected List<Object> any;
#XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
public XMLGregorianCalendar getDiscovered() {
return discovered;
}
public void setDiscovered(XMLGregorianCalendar value) {
this.discovered = value;
}
public DocumentEventType getEvent() {
return event;
}
public void setEvent(DocumentEventType value) {
this.event = value;
}
public DocumentType getDocument() {
return document;
}
public void setDocument(DocumentType value) {
this.document = value;
}
public List<Object> getAny() {
if (any == null) {
any = new ArrayList<Object>();
}
return this.any;
}
public Map<QName, String> getOtherAttributes() {
return otherAttributes;
}
}
DocumentType.java
package net.es.nsi.pce.discovery.jaxb;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import org.w3c.dom.Element;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "DocumentType", namespace = "http://schemas.ogf.org/nsi/2014/02/discovery/types", propOrder = {
"nsa",
"type",
"signature",
"content",
"any"
})
public class DocumentType {
#XmlElement(required = true)
#XmlSchemaType(name = "anyURI")
protected String nsa;
#XmlElement(required = true)
protected String type;
protected AnyType signature;
protected AnyType content;
#XmlAnyElement(lax = true)
protected List<Object> any;
#XmlAttribute(name = "id", required = true)
protected String id;
#XmlAttribute(name = "href")
#XmlSchemaType(name = "anyURI")
protected String href;
#XmlAttribute(name = "version", required = true)
#XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar version;
#XmlAttribute(name = "expires", required = true)
#XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar expires;
#XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
public String getNsa() {
return nsa;
}
public void setNsa(String value) {
this.nsa = value;
}
public String getType() {
return type;
}
public void setType(String value) {
this.type = value;
}
public AnyType getSignature() {
return signature;
}
public void setSignature(AnyType value) {
this.signature = value;
}
public AnyType getContent() {
return content;
}
public void setContent(AnyType value) {
this.content = value;
}
public List<Object> getAny() {
if (any == null) {
any = new ArrayList<Object>();
}
return this.any;
}
public String getId() {
return id;
}
public void setId(String value) {
this.id = value;
}
public String getHref() {
return href;
}
public void setHref(String value) {
this.href = value;
}
public XMLGregorianCalendar getVersion() {
return version;
}
public void setVersion(XMLGregorianCalendar value) {
this.version = value;
}
public XMLGregorianCalendar getExpires() {
return expires;
}
public void setExpires(XMLGregorianCalendar value) {
this.expires = value;
}
public Map<QName, String> getOtherAttributes() {
return otherAttributes;
}
}

I am getting a NullPointerException when trying to use the Service class

I am getting a NullPointerException which is as follows:
java.lang.NullPointerException
file:/K:/Learner/JavaFx2/ProductApplication/dist/run166129449/ProductApplication.jar!/com/product/app/view/viewsingle.fxml
at com.product.app.controller.ViewSingleController.initialize(ViewSingleController.java:70)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
And my ViewSingleController is as follows:
package com.product.app.controller;
import com.product.app.model.Product;
import com.product.app.service.ViewProductsService;
import com.product.app.util.JSONParser;
import com.product.app.util.TagConstants;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import javax.swing.JOptionPane;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* FXML Controller class
*
* #author Arun Joseph
*/
public class ViewSingleController implements Initializable {
private static String action = "";
#FXML
private TextField txtID;
#FXML
private TextField txtName;
#FXML
private TextField txtPrice;
#FXML
private TextArea txtDesc;
#FXML
private Region veil;
#FXML
private ProgressIndicator p;
private ViewProductsService service = new ViewProductsService();
private JSONObject product = null;
private JSONParser parser = new JSONParser();
private int pid = 1;
public void setPid(int pid) {
this.pid = pid;
}
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
p.setMaxSize(150, 150);
p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(service.runningProperty());
p.visibleProperty().bind(service.runningProperty());
Product product = new Product();
service.start();
ObservableList<Product> products = service.valueProperty().get();
products.get(pid);
txtID.textProperty().set(String.valueOf(products.get(pid).getPid()));
//product = service.valueProperty().get().get(pid);
//txtID.setText(String.valueOf(product.getPid()));
txtName.textProperty().set(product.getName());
txtPrice.textProperty().set(String.valueOf(product.getPrize()));
txtDesc.textProperty().set(product.getDescription());
}
private SomeService someService = new SomeService();
#FXML
private void handleUpdateButtonClick(ActionEvent event) {
action = "update";
someService.start();
p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(service.runningProperty());
p.visibleProperty().bind(service.runningProperty());
}
#FXML
private void handleDeleteButtonClick(ActionEvent event) {
action = "delete";
someService.start();
p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(service.runningProperty());
p.visibleProperty().bind(service.runningProperty());
}
#FXML
private void handleCancelButtonClick(ActionEvent event) {
closeStage();
}
private void closeStage() {
ViewSingleController.stage.close();
}
private static Stage stage = null;
public static void setStage(Stage stage) {
ViewSingleController.stage = stage;
}
private class SomeService extends Service<String> {
#Override
protected Task<String> createTask() {
return new SomeTask();
}
private class SomeTask extends Task<String> {
#Override
protected String call() throws Exception {
String result = "";
int success = 0;
List<NameValuePair> params = new ArrayList<NameValuePair>();
switch (action) {
case "update":
params.add(new BasicNameValuePair("pid", txtID.getText()));
params.add(new BasicNameValuePair("name", txtName.getText()));
params.add(new BasicNameValuePair("price", txtPrice.getText()));
params.add(new BasicNameValuePair("description", txtDesc.getText()));
product = parser.makeHttpRequest(TagConstants.url_update_product_with_id, "POST", params);
success = product.getInt(TagConstants.TAG_SUCCESS);
if (success == 1) {
result = "Successfully Updated the product";
JOptionPane.showMessageDialog(null, result);
closeStage();
}
break;
case "delete":
params.add(new BasicNameValuePair("pid", txtID.getText()));
product = parser.makeHttpRequest(TagConstants.url_delete_product_with_id, "POST", params);
success = product.getInt(TagConstants.TAG_SUCCESS);
if (success == 1) {
result = "Successfully Deleted the product";
JOptionPane.showMessageDialog(null, result);
closeStage();
}
break;
}
return result;
}
}
}
}
Please help me on how to fix this null pointer problem really help required. Thank you in advance
Inspect the line ViewSingleController.java:70. Put a breakpoint there. Run the program in a debugger and see what variables/fields are null.
The Exception happens on line 70, as you can see from the StackTrace.
On line 70, you call:
txtPrice.textProperty().set(String.valueOf(product.getPrize()));
The NullPointerException means that you are trying to access a method of an object that does not exist. Here, this might be txtPrice, textProperty, product or getPrize.
Skimming over your code, I'd guess it might be txtPrice, because you only set it as a member variable via
private TextField txtPrice;
but you never initialize it. Thus, txtPrice is null and txtPrice.textProperty().set will probably throw the NullPointer.

JAXB issue-- unexpected element

My JAXB parser suddenly stopped working today. It was working for several weeks. I get the following message. I haven't changed this code for several weeks. Wondering if this set up is good.
EDIT 2: Please could somebody help me! I can't figure this out.
EDIT 1:
My acceptance tests running the same code below are working fine. I believe this is a
classloading issue. I am using the JAXB and StAX in the JDK. However, when I deploy to jboss 5.1, I get the error below. Using 1.6.0_26 (locally) and 1.6.0_30 (dev server). Still puzzling over a solution.
unexpected element (uri:"", local:"lineEquipmentRecord"). Expected
elements are
<{}switchType>,<{}leSwitchId>,<{}nodeAddress>,<{}leId>,<{}telephoneSuffix>,<{}leFormatCode>,<{}groupIdentifier>,<{}telephoneNpa>,<{}telephoneLine>,<{}telephoneNxx>
Here is my unmarshalling class:
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
public class PartialUnmarshaller<T> {
XMLStreamReader reader;
Class<T> clazz;
Unmarshaller unmarshaller;
public PartialUnmarshaller(InputStream stream, Class<T> clazz) throws XMLStreamException, FactoryConfigurationError, JAXBException {
this.clazz = clazz;
this.unmarshaller = JAXBContext.newInstance(clazz).createUnmarshaller();
unmarshaller.setEventHandler(new ValidationEventHandler() {
#Override
public boolean handleEvent(ValidationEvent event) {
System.out.println(event.getMessage());
return true;
}
});
this.reader = XMLInputFactory.newInstance().createXMLStreamReader(stream);
/* ignore headers */
skipElements(XMLStreamConstants.START_DOCUMENT);
/* ignore root element */
reader.nextTag();
/* if there's no tag, ignore root element's end */
skipElements(XMLStreamConstants.END_ELEMENT);
}
public T next() throws XMLStreamException, JAXBException {
if (!hasNext())
throw new NoSuchElementException();
T value = unmarshaller.unmarshal(reader, clazz).getValue();
skipElements(XMLStreamConstants.CHARACTERS, XMLStreamConstants.END_ELEMENT);
return value;
}
public boolean hasNext() throws XMLStreamException {
return reader.hasNext();
}
public void close() throws XMLStreamException {
reader.close();
}
private void skipElements(Integer... elements) throws XMLStreamException {
int eventType = reader.getEventType();
List<Integer> types = new ArrayList<Integer>(Arrays.asList(elements));
while (types.contains(eventType))
eventType = reader.next();
}
}
This class is used as follows:
List<MyClass> lenList = new ArrayList<MyClass>();
PartialUnmarshaller<MyClass> pu = new PartialUnmarshaller<MyClass>(
is, MyClass.class);
while (pu.hasNext()) {
lenList.add(pu.next());
}
The XML being unmarshalled:
<?xml version="1.0" encoding="UTF-8"?>
<lineEquipment>
<lineEquipmentRecord>
<telephoneNpa>333</telephoneNpa>
<telephoneNxx>333</telephoneNxx>
<telephoneLine>4444</telephoneLine>
<telephoneSuffix>1</telephoneSuffix>
<nodeAddress>xxxx</nodeAddress>
<groupIdentifier>LEN</groupIdentifier>
</lineEquipmentRecord>
<lineEquipmentRecord>
<telephoneNpa>111</telephoneNpa>
<telephoneNxx>111</telephoneNxx>
<telephoneLine>2222</telephoneLine>
<telephoneSuffix>0</telephoneSuffix>
<nodeAddress>xxxx</nodeAddress>
<groupIdentifier>LEN</groupIdentifier>
</lineEquipmentRecord>
</lineEquipment>
Finally, here is MyClass:
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* This class is used as an envelope to hold Martens
* line equipment information.
* #author spgezf
*
*/
#XmlRootElement(name="lineEquipmentRecord")
public class MyClass {
private String telephoneNpa;
private String telephoneNxx;
private String telephoneLine;
private String telephoneSuffix;
private String nodeAddress;
private String groupIdentifier;
public MyClass(){
}
// Getters and Setters.
#XmlElement(name="telephoneNpa")
public String getTelephoneNpa() {
return telephoneNpa;
}
public void setTelephoneNpa(String telephoneNpa) {
this.telephoneNpa = telephoneNpa;
}
#XmlElement(name="telephoneNxx")
public String getTelephoneNxx() {
return telephoneNxx;
}
public void setTelephoneNxx(String telephoneNxx) {
this.telephoneNxx = telephoneNxx;
}
#XmlElement(name="telephoneLine")
public String getTelephoneLine() {
return telephoneLine;
}
public void setTelephoneLine(String telephoneLine) {
this.telephoneLine = telephoneLine;
}
#XmlElement(name="telephoneSuffix")
public String getTelephoneSuffix() {
return telephoneSuffix;
}
public void setTelephoneSuffix(String telephoneSuffix) {
this.telephoneSuffix = telephoneSuffix;
}
#XmlElement(name="nodeAddress")
public String getNodeAddress() {
return nodeAddress;
}
public void setNodeAddress(String nodeAddress) {
this.nodeAddress = nodeAddress;
}
#XmlElement(name="groupIdentifier")
public String getGroupIdentifier() {
return groupIdentifier;
}
public void setGroupIdentifier(String groupIdentifier) {
this.groupIdentifier = groupIdentifier;
}
}
Thanks, this is classloading issue I couldn't overcome so I abandoned JAXB.
Your PartialUnmarshaller code worked for me. Below is an alternate version that changes the skipElements method that may work better.
import java.io.InputStream;
import java.util.NoSuchElementException;
import javax.xml.bind.*;
import javax.xml.stream.*;
public class PartialUnmarshaller<T> {
XMLStreamReader reader;
Class<T> clazz;
Unmarshaller unmarshaller;
public PartialUnmarshaller(InputStream stream, Class<T> clazz) throws XMLStreamException, FactoryConfigurationError, JAXBException {
this.clazz = clazz;
this.unmarshaller = JAXBContext.newInstance(clazz).createUnmarshaller();
unmarshaller.setEventHandler(new ValidationEventHandler() {
#Override
public boolean handleEvent(ValidationEvent event) {
System.out.println(event.getMessage());
return true;
}
});
this.reader = XMLInputFactory.newInstance().createXMLStreamReader(stream);
/* ignore headers */
skipElements();
/* ignore root element */
reader.nextTag();
/* if there's no tag, ignore root element's end */
skipElements();
}
public T next() throws XMLStreamException, JAXBException {
if (!hasNext())
throw new NoSuchElementException();
T value = unmarshaller.unmarshal(reader, clazz).getValue();
skipElements();
return value;
}
public boolean hasNext() throws XMLStreamException {
return reader.hasNext();
}
public void close() throws XMLStreamException {
reader.close();
}
private void skipElements() throws XMLStreamException {
while(reader.hasNext() && !reader.isStartElement()) {
reader.next();
}
}
}

How to transfer an array list of objects over the wire through GWTP action

I am trying to create an action in which the server needs to response an array list of objects over the wire to the client through GWTP Action.
Category class
package com.business.share;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
public class Category implements Serializable{
Long id;
protected String name;
protected String description;
protected boolean status;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean getStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
}
GetCategories class
package com.business.client.action;
import java.util.ArrayList;
import com.gwtplatform.dispatch.shared.ActionImpl;
import com.business.client.action.GetCategoriesResult;
import com.business.share.Category;
public class GetCategories extends ActionImpl<GetCategoriesResult> {
private ArrayList<Category> categories;
#SuppressWarnings("unused")
public GetCategories() {
// For serialization only
}
public GetCategories(ArrayList<Category> categories) {
this.categories = categories;
}
public ArrayList<Category> getCategories() {
return categories;
}
}
GetCategoriesResult class
package com.business.client.action;
import java.util.ArrayList;
import com.gwtplatform.dispatch.shared.Result;
import com.business.share.Category;
public class GetCategoriesResult implements Result {
private ArrayList<Category> categories;
#SuppressWarnings("unused")
private GetCategoriesResult() {
// For serialization only
}
public GetCategoriesResult(ArrayList<Category> categories) {
this.categories = categories;
}
public ArrayList<Category> getCategories() {
return categories;
}
}
GetCategoriesActionHandler class
package com.business.server.handler;
import java.util.ArrayList;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.business.client.action.GetCategories;
import com.business.client.action.GetCategoriesResult;
import com.business.share.Category;
import com.google.inject.Inject;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;
public class GetCategoriesActionHandler implements
ActionHandler<GetCategories, GetCategoriesResult> {
#Inject
public GetCategoriesActionHandler() {
}
#Override
public GetCategoriesResult execute(GetCategories action,
ExecutionContext context) throws ActionException {
ArrayList<Category> categories = new ArrayList<Category>();
// dummy data
Category cat1 = new Category();
cat1.setName("cat1");
cat1.setDescription("cat1 desc");
cat1.setStatus(true);
Category cat2 = new Category();
cat1.setName("cat2");
cat1.setDescription("cat2 desc");
cat1.setStatus(false);
categories.add(cat1);
categories.add(cat2);
return new GetCategoriesResult(categories);
}
#Override
public void undo(GetCategories action, GetCategoriesResult result,
ExecutionContext context) throws ActionException {
}
#Override
public Class<GetCategories> getActionType() {
return GetCategories.class;
}
}
And this is a piece of code in CategoryPresenter, which sends async to server.
#Override
protected void onReset() {
super.onReset();
GetCategories getCategoriesAction = new GetCategories();
dispatchAsync.execute(getCategoriesAction, getCategoriesCallback);
}
private final AsyncCallback<GetCategoriesResult> getCategoriesCallback =
new AsyncCallback<GetCategoriesResult>() {
#Override
public void onFailure(Throwable caught) {
}
#Override
public void onSuccess(GetCategoriesResult result) {
getView().getCategoryListBox().clear();
ArrayList<Category> categories = result.getCategories();
for(Category category : categories) {
getView().getCategoryListBox().addItem(category.getName());
}
}
};
I don't know what wrong with this piece of code, but GWT compiler always gives error like this.
Compiling module com.business.Business
Validating newly compiled units
Ignored 3 units with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
Finding entry point classes
[ERROR] Errors in 'file:/.blah..blah..blah../businessapp/src/com/business/client/presenter/CategoryPresenter.java'
[ERROR] Line 75: No source code is available for type com.business.share.Category; did you forget to inherit a required module?
[ERROR] Errors in 'file:/.blah..blah..blah../businessapp/src/com/business/client/action/GetCategoriesResult.java'
[ERROR] Line 11: No source code is available for type com.business.share.Category; did you forget to inherit a required module?
[ERROR] Unable to find type 'com.business.client.Business'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Following this error message, it means, com.business.share.Category is not found, but this file is physically stored in that package already. I don't understand why GWT could not find it. I noticed anywhere that I make call Category class, it brings this error always.
Somebody's got an idea on what's going on?
[EDIT]
The problem is solved.
In my Business.gwt.xml, I have
<source path='shared'/>
But my share package is com.business.share (without d)
I just rename the package name from share to shared.
Try to add an empty constructor to the Category class.

Resources