Jackson blob exception - java

I am trying to save image to database, but I get error:
org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.sql.Blob, problem: abstract types can only be instantiated with additional type information
at [Source: java.io.StringReader#e95dbd; line: 1, column: 27] (through reference chain: com.soul.seeker.models.Post["postImage"])
at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
at org.codehaus.jackson.map.deser.StdDeserializationContext.instantiationException(StdDeserializationContext.java:233)
at org.codehaus.jackson.map.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:60)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)
at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
at com.soul.seeker.serviceImpl.PostServiceImpl.createPostImage(PostServiceImpl.java:121)
at com.soul.seeker.Application.lambda$main$8(Application.java:142)
at spark.ResponseTransformerRouteImpl$1.handle(ResponseTransformerRouteImpl.java:47)
at spark.http.matching.Routes.execute(Routes.java:61)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:130)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
Pojo class:
public class Post{
private String post_id;
private String title;
private String details;
private String username;
private String userImage;
private String url;
private List categories;
private String created_at;
private Blob postImage; //BLOB TYPE
private String postImageName;
//getters setters
}
Implementation class:
#Override
public void createPostImage(Request request) {
try {
ObjectMapper mapper = new ObjectMapper();
Post createPostImage = mapper.readValue(request.body(), Post.class);
System.out.println("CREATE POST IMAGE" + createPostImage);
} catch (IOException ex) {
Logger.getLogger(PostServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
Looked online for similar posts but couldn't find any leads. How do I fix this? It says abstract types can only be instantiated with additional type information. What is the additional info I have to passed here?

I'm not sure about the method you're trying to upload a file, but I'm sure that's not the "recommended" method when working with Spark.
According to the documentation, you should read the file as a stream and use the request.raw() for that purpose, instead of the request.body().
Read about the recommended way here, and there's also a github example for that.

Related

HttpClientErrorException$BadRequest: 400 BAD REQUEST when service return []

I'm running a service and it works perfectly when it returns some entidade. But when it doesn't find any, I get the following error:
org.springframework.web.client.HttpClientErrorException$BadRequest: 400 BAD REQUEST: [{
"entidades": [],
"saida": "" rua bandeirantes, 1578 - bairro: cent... (19970 bytes)]
at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:101)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:186)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:125)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:818)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:710)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:467)
at br.mp.mpf.cened01.cargaIaRJ.RJServico.executarServico(RJServico.java:953)
at br.mp.mpf.cened01.cargaIaRJ.RJServico.executarServicoByPagina(RJServico.java:857)
at br.mp.mpf.cened01.cargaIaRJ.RJServico.executarComPaginacao(RJServico.java:752)
at br.mp.mpf.cened01.cargaIaRJ.RJApplication.lambda$0(RJApplication.java:52)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:788)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
at br.mp.mpf.cened01.cargaIaRJ.RJApplication.main(RJApplication.java:29)
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.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
private RetornoServicoDto executarServico(String sentenca)
throws Exception {
RetornoServicoDto retornoServico = new RetornoServicoDto();
final String sentencaOri = sentenca;
RestTemplate restTemplate = new RestTemplate();
final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator();
while (iterator.hasNext()) {
final HttpMessageConverter<?> converter = iterator.next();
if (converter instanceof StringHttpMessageConverter) {
iterator.remove();
}
}
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
try {
ResponseEntity<RetornoServicoDto> responseEntity =
restTemplate.postForEntity(Constantes.SERVICO_URL,
sentencaOri, RetornoServicoDto.class);
retornoServico = responseEntity.getBody();
} catch (Exception e) {
e.printStackTrace();
}
return retornoServico;
}
#Data
public class RetornoServicoDto {
private List<EntidadeDto> entidades;
private String saida;
private String status;
}
#Data
public class EntidadeDto {
private String entidade;
private int id;
private PosicaoDto posicao;
private String texto;
}
What to do to work even when the entities list returns []?
Based on what I see from your log, your response object starts with an "[{..." so probably your server side is returning an list of RetornoServicoDto, not a single object that what you are asking the request for, since your problem is a bad request, would be great to see the service side that process the request to understand better.

XDocReport: Issue by filling tables with Freemarker in ODT-file

I tried to rebuild the sample from the XDocReport documentation, but when i try to create tables or fill them. It always fails due to the follwing error. I cannot figure out what the issue is...
I have updated all the dependencies and tried different syntax in the .odt file.
ERROR:
Apr. 12, 2022 10:21:05 VORM. freemarker.log._JULLoggerFactory$JULLogger error
SEVERE: Error executing FreeMarker template
FreeMarker template error:
The following has evaluated to null or missing:
==> devs.name [in template "fr.opensagres.xdocreport.document.odt.ODTReport#57855c9a!content.xml" at line 5, column 11]
----
Tip: It's the step after the last dot that caused this error, not those before it.
----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use [#if myOptionalVar??]when-present[#else]when-missing[/#if]. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${devs.name} auto-escaped [in template "fr.opensagres.xdocreport.document.odt.ODTReport#57855c9a!content.xml" at line 5, column 9]
----
Java stack trace (for programmers):
----
freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:481)
at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:401)
at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:370)
at freemarker.core.BuiltInForLegacyEscaping._eval(BuiltInForLegacyEscaping.java:34)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.Expression.evalAndCoerceToStringOrUnsupportedMarkup(Expression.java:139)
at freemarker.core.BuiltInForString.getTargetString(BuiltInForString.java:34)
at freemarker.core.BuiltInForString._eval(BuiltInForString.java:29)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.MethodCall._eval(MethodCall.java:55)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.Expression.evalAndCoerceToStringOrUnsupportedMarkup(Expression.java:139)
at freemarker.core.BuiltInForString.getTargetString(BuiltInForString.java:34)
at freemarker.core.BuiltInForString._eval(BuiltInForString.java:29)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.MethodCall._eval(MethodCall.java:55)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.Expression.evalAndCoerceToStringOrUnsupportedMarkup(Expression.java:139)
at freemarker.core.BuiltInForString.getTargetString(BuiltInForString.java:34)
at freemarker.core.BuiltInForString._eval(BuiltInForString.java:29)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.MethodCall._eval(MethodCall.java:55)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:100)
at freemarker.core.DollarVariable.accept(DollarVariable.java:63)
at freemarker.core.Environment.visit(Environment.java:383)
at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:321)
at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271)
at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244)
at freemarker.core.Environment.visitIteratorBlock(Environment.java:657)
at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:347)
at freemarker.core.Environment.visit(Environment.java:353)
at freemarker.core.Environment.visit(Environment.java:353)
at freemarker.core.Environment.process(Environment.java:326)
at fr.opensagres.xdocreport.template.freemarker.FreemarkerTemplateEngine.process(FreemarkerTemplateEngine.java:163)
at fr.opensagres.xdocreport.template.freemarker.FreemarkerTemplateEngine.processNoCache(FreemarkerTemplateEngine.java:122)
at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:118)
at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:83)
at fr.opensagres.xdocreport.document.AbstractXDocReport.processTemplateEngine(AbstractXDocReport.java:772)
at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:518)
at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:484)
at report_creation.fillList.main(fillList.java:51)
I am currently using this code:
fillList.java
public class fillList {
public static void main(String[] args) {
try {
// 1) Load ODT file by filling Velocity template engine and cache
// it to the registry
InputStream in = fillList.class.getResourceAsStream("Test.odt");
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Freemarker);
// 2) Create fields metadata to manage lazy loop (#foreach velocity)
// for table row.
FieldsMetadata metadata = new FieldsMetadata();
metadata.addFieldAsList("developers.name");
metadata.addFieldAsList("developers.lastName");
metadata.addFieldAsList("developers.mail");
report.setFieldsMetadata(metadata);
// 3) Create context Java model
IContext context = report.createContext();
Project project = new Project("Create Dynamic Reports", 101);
context.put("project", project);
// Register developers list
List<Developer> developers = new ArrayList<>();
developers.add(new Developer("ZERR", "Angelo", "angelo.zerr#gmail.com"));
developers.add(new Developer("Leclercq", "Pascal", "pascal.leclercq#gmail.com"));
context.put("developers", developers);
// 4) Generate report by merging Java model with the ODT
OutputStream out = new FileOutputStream(new File("Test2_out.odt"));
report.process(context, out);
System.out.println("Report creation successfully completed!");
} catch (IOException e) {
System.err.println("[Debug Assistent]: No report created! >> IOException");
e.printStackTrace();
} catch (XDocReportException e) {
System.err.println("[Debug Assistent]: No report created! >> XDocReportException");
e.printStackTrace();
}
}
}
Project.java
public class Project {
private final String name;
private final Integer ID;
public Project(String name, Integer id) {
this.name = name;
this.ID = id;
}
public String getName() {
return name;
}
public Integer getID() {
return ID;
}
}
Developer.java
public class Developer {
private final String name;
private final String lastName;
private final String mail;
public Developer(String name, String lastName, String mail) {
this.name = name;
this.lastName = lastName;
this.mail = mail;
}
public String getFirstName() {
return name;
}
public String getLastName() {
return lastName;
}
public String getMail() {
return mail;
}
}
This is the .odt file i am using.
In the Developer class you have getFirstName instead of getName. Hence dev.name won't work.

Modify the Solr response using SolrJ

I'm using the SolrJ client to call the Solr service, is there any way to modify the response that I got from Solr like adding a new field in the response docs.
QueryResponse rsp = null;
if (server != null) {
try {
rsp = server.query(solrParams);
} catch (Exception e) {
e.getMessage();
}
}
If my response is something like below
{
"responseHeader":{
"status":400,
"QTime":15,
"params":{
"q":"*:*",
"indent":"true",
"wt":"json",
"group":"false"}},
"response":{"numFound":1,"start":0,"docs":[
{
"Name":"Shirt",
"inventory":"Nonn",
"launchYear":2004,
"Desc":"Men's Shirt",
"ilnNumbers":"25326,25338,25341,29617,39267",}
}}
I need to change this response to add a new field
{
"responseHeader":{
"status":400,
"QTime":15,
"params":{
"q":"*:*",
"indent":"true",
"wt":"json",
"group":"false"}},
"response":{"numFound":1,"start":0,"docs":[
{
"Name":"Shirt",
"inventory":"Nonn",
"launchYear":2004,
"myCustomField":"Test",
"Desc":"Men's Shirt",
"ilnNumbers":"25326,25338,25341,29617,39267",}
}}
Is this possible?
Define a POJO class for your schema along with getters and setters.
class POJO {
#Field
private String name;
#Field
private Integer inventory;
#Field
private Integer launchYear;
#Field
private String desc;
#Field
private String ilnNumbersl;
private String myCustomField;
public POJO(String name, Integer inventory, Integer launchYear, String desc, String ilnNumbersl) {
this.name = name;
this.inventory = inventory;
this.launchYear = launchYear;
this.desc = desc;
this.ilnNumbersl = ilnNumbersl;
}
//getters and setters for each instance member.
}
Now convert the solr response into List and add the required custom field to the each result returned by the query.
QueryResponse rsp = null;
if (server != null) {
try {
rsp = server.query(solrParams);
List<POJO> list = rsp.getBeans(POJO.class); // convert to list of POJO instance
// now add the custom field for each
} catch (Exception e) {
e.getMessage();
}
}
Try JsonResponceWriter from Solr Documentation.This will help you solve your problem.
<queryResponseWriter name="json" class="solr.JSONResponseWriter">
<!-- For the purposes of the tutorial, JSON response are written as
plain text so that it's easy to read in *any* browser.
If you are building applications that consume JSON, just remove
this override to get the default "application/json" mime type.
-->
<str name="content-type">text/plain</str>
</queryResponseWriter>
This will give you queryResponce in Text format. Modify That responce according to your use.

Getting a JSON object returned in Java

I'm trying to get a JSON object displayed via an API, but I get a error message along with it.
Here is the method that I've written:
public MarketDataListLevel1 getMarketDataTicker() {
try {
MarketDataListLevel1 md = CS.getMarketDataTicker();
log.info(md.toString());
return md;
}
catch ( Exception e) {
e.printStackTrace();
return null;
}
}
Where CS is an object that processes the JSON data from a URL..
For some reason, when I call that method, I'm getting the precise output that I want, but I also get these additional error messages that follow it, and I'm unsure why. Any help would be appreciated.
14:52:55.265 [default] [main] ERROR si.mazi.rescu.JSONUtils - Error unmarshalling from
json: {"Bid":{"Price":183.25,"Size":0.0,"ExchangeID":"SMART","timeStamp":0},"Ask":{"Price":185.0,"Size":0.0,"ExchangeID":"SMART","timeStamp":0},"Last":{"Price":182.44,"Size":4.0,"ExchangeID":"SMART","timeStamp":0}}
java.lang.RuntimeException: Problem getting JSON object
at (Skipped all these logs)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.xeiam.xchange.cs.dto.MarketData[] out of START_OBJECT token
at [Source: java.io.StringReader#5069bb01; line: 1, column: 2]
This is the format of the data what I want returned:
{"Bid":{"Price":204.08,"Size":1.0,"ExchangeID":"SMART","timeStamp":0},
"Ask":{"Price":203.2,"Size":0.0,"ExchangeID":"SMART","timeStamp":0},
"Last":{"Price":204.64,"Size":2.0,"ExchangeID":"SMART","timeStamp":0}}
And it seems to be fulfilling that.
MarketDataLevel1 is defined as:
public class MarketDataListLevel1 {
public MarketData[] MarketDataListLast;
public MarketData[] MarketDataListBid;
public MarketData[] MarketDataListAsk;
public MarketDataListLevel1(#JsonProperty("Bid") MarketData[] MarketDataListBid,#JsonProperty("Ask") MarketData[] MarketDataListAsk,#JsonProperty("Last") MarketData[] MarketDataListLast) {
this.MarketDataListBid = MarketDataListBid;
this.MarketDataListAsk = MarketDataListAsk;
this.MarketDataListLast = MarketDataListLast;
}
And MarketData as
public class MarketData {
public BigDecimal Price;
public BigDecimal Size;
public String ExchangeID;
public long timeStamp;
public MarketData(
#JsonProperty("Price") BigDecimal Price,
#JsonProperty("Size") BigDecimal Size,
#JsonProperty("ExchangeID") String ExchangeID,
#JsonProperty("timeStamp") long timeStamp) {
this.Price = Price;
this.Size = Size;
this.ExchangeID = ExchangeID;
this.timeStamp = timeStamp;
}
}

app engine req.getParameter with type float

I'm trying to do something very similar to the Guestbook which is in the App Engine tutorial (get started). However, I want to modified the types of the fields in the form. Eclipse doesn't show any error, but the server says:
Problem accessing /. Reason:
java.lang.NoSuchMethodError: prototipo2.Greeting.getDistance()Ljava/lang/Float;
Caused by:
javax.servlet.ServletException: java.lang.NoSuchMethodError: prototipo2.Greeting.getDistance() Ljava/lang/Float;
at org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:862)
at org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:791)
at org.apache.jsp.prototipo2_jsp._jspService(prototip o2_jsp.java:326)
at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:260)
at com.google.appengine.tools.development.PrivilegedJ spServlet.access$101 (PrivilegedJspServlet.java:23)
at com.google.appengine.tools.development.PrivilegedJ spServlet$2.run(PrivilegedJspServlet.java:59)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.appengine.tools.development.PrivilegedJ spServlet.service(PrivilegedJspServlet.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.BackendServ ersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(Se rvletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle( SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(Se ssionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(Co ntextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebA ppContext.java:418)
at com.google.appengine.tools.development.DevAppEngin eWebAppContext.handle(DevAppEngineWebAppContext.ja va:78)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispa tcher.java:327)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispa tcher.java:126)
at com.google.appengine.tools.development.StaticFileU tils.serveWelcomeFileAsForward(StaticFileUtils.jav a:80)
at com.google.appengine.tools.development.LocalResour ceFileServlet.maybeServeWelcomeFile(LocalResourceF ileServlet.java:254)
at com.google.appengine.tools.development.LocalResour ceFileServlet.doGet(LocalResourceFileServlet.java: 120)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerif icationFilter.doFilter(HeaderVerificationFilter.ja va:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFi lter.doFilter(ServeBlobFilter.java:60)
at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCle anupFilter.doFilter(TransactionCleanupFilter.java: 43)
at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileF ilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServ ersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(Se rvletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle( SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(Se ssionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(Co ntextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebA ppContext.java:418)
at com.google.appengine.tools.development.DevAppEngin eWebAppContext.handle(DevAppEngineWebAppContext.ja va:78)
at org.mortbay.jetty.handler.HandlerWrapper.handle(Ha ndlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContai nerService$ApiProxyHandler.handle(JettyContainerSe rvice.java:363)
at org.mortbay.jetty.handler.HandlerWrapper.handle(Ha ndlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(Htt pConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.he aderComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser. java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpPa rser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnec tion.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(Selec tChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run (QueuedThreadPool.java:582)
Caused by: java.lang.NoSuchMethodError: prototipo2.Greeting.getDistance()Ljava/lang/Float;
at org.apache.jsp.prototipo2_jsp._jspService(prototip o2_jsp.java:187)
... 56 more
My code is:
#Persistent
private Float distance;
public Greeting (User author, String content, Date date, String distance) {
this.author = author;
this.content = content;
this.date = date;
this.distance = Float.parseFloat(distance); }
}
public Float getDistance() {
return distance;
}
And Eclipse says everything is ok when I run the app, but when I open the file in my localhost domain, I see the error that I wrote you before.
However, if I change the code in something like this:
#Persistent
private String distance;
public Greeting (User author, String content, Date date, String distance) {
this.author = author;
this.content = content;
this.date = date;
this.distance = distance;
}
public String getDistance() {
return distance;
}
Thank you!
I think you have two problems:
Somewhere you have a Long field where data is a string and can not be converted to long.
Why are you converting distance parameter to Integer if you then assign it to a float field? Use Float.parseFloat(..) instead.
The error you're getting is when an already persisted entity is being read back from the datastore. It looks like you've already stored data which has a String property that you're now trying to read into an entity which has redefined that property as a Long - have you changed the type of the ID field at all?

Categories