Spring MVC + Hibernate + JSP - java

I'm new using these tools so you'll probably find this very stupid.
I'm getting this error, when trying to access my webapp (where I'm supposed to show every user in my database "User" table.
HTTP ERROR 500
Problem accessing /maven-archetype-webapp/index. Reason:
Neither BindingResult nor plain target object for bean name 'contact' available as request attribute
Caused by:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'contact' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:130)
at org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:120)
at org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:90)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.jsp.usuario_jsp._jspx_meth_form_label_0(org.apache.jsp.WEB_002dINF.jsp.usuario_jsp:299)
at org.apache.jsp.WEB_002dINF.jsp.usuario_jsp._jspx_meth_form_form_1(org.apache.jsp.WEB_002dINF.jsp.usuario_jsp:222)
at org.apache.jsp.WEB_002dINF.jsp.usuario_jsp._jspService(org.apache.jsp.WEB_002dINF.jsp.usuario_jsp:106)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:266)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
So I'm gonna send you my Controller, my JSP and my Service implementation.
UsuarioController.java
package org.maven.archetypes.Project.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.maven.archetypes.Project.form.Usuario;
import org.maven.archetypes.Project.service.UsuarioService;
#Controller
public class UsuarioController {
#Autowired
private UsuarioService usuarioService;
#RequestMapping("/index")
public String listUsers(Map<String, Object> map) {
map.put("usuario", new Usuario());
map.put("usuarioList", usuarioService.listUsuario());
return "usuario";
}
#RequestMapping(value = "/add", method = RequestMethod.POST)
public String addUsuario(#ModelAttribute("user")
Usuario user, BindingResult result) {
usuarioService.addUsuario(user);
return "redirect:/index";
}
#RequestMapping("/delete/{email}")
public String deleteUsuario(#PathVariable("email")
String email) {
usuarioService.removeUsuario(email);
return "redirect:/index";
}
}
Usuario.jsp
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Spring 3 MVC Series - Contact Manager</title>
</head>
<body>
<!--
<h3>Usuarios</h3>
<c:if test="${!empty usuarioList}">
<table class="data">
<tr>
<th><spring:message code="label.firstname"/></th>
<th><spring:message code="label.email"/></th>
<th> </th>
</tr>
<c:forEach items="${usuarioList}" var="usuario">
<tr>
<td>${usuario.lastname}, ${usuario.firstname} </td>
<td>${usuario.email}</td>
<td>Eliminar</td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>
UsuarioServiceImpl.java (implementation of the interface UsuarioService.java)
#Service
public class UsuarioServiceImpl implements UsuarioService {
#Autowired
private UsuarioDAO UsuarioDAO;
#Transactional
public void addUsuario(Usuario user) {
UsuarioDAO.addUsuario(user);
}
#Transactional
public List<Usuario> listUsuario() {
return UsuarioDAO.listUsuario();
}
#Transactional
public void removeUsuario(String email) {
UsuarioDAO.removeUsuario(email);
}
}
I don't know if it's necessary to keep going with the DAOs ... the problem is that the error names a "Contact" and I don't even use that name in anything at all (I use "Usuario"). And yes, before you ask, I did replace some internet code which did have the word "contact" but I replaced them all to my code. So maybe this caused a mess but I'm really lost now. Hope you can help me. If there's something you don't understand don't hesitate to ask.
Thank you a lot!

You are only putting your object into a map. You need to put your objects in http request. Spring has model objects Model and ModelAndView that do this as shown below:-
<code>
#RequestMapping("/index")
public String listUsers(Model model) {
model.addAttribute("usuario", new Usuario());
model.addAttribute("usuarioList", usuarioService.listUsuario());
return "usuario";
}
</code>
OR
<code>
#RequestMapping("/index")
public ModelAndView listUsers() {
ModelAndView mav = new ModelAndView("usuario");
mav.addObject("usuario", new Usuario());
mav.addObject("usuarioList", usuarioService.listUsuario());
return mav;
}
</code>

What I can suggest you here is delete the target folder where the build is prepared and recreate the build and war and then run, if problem persists then let us know with the necessary files. Thanks

Related

How to print 2d array created using java in HTML

I'm trying to print a 2d array on HTML. I'm trying to learn "Spring Boot Framework" and I'm stuck here. Is anybody know the solution? Posting my codes below, please help me.
MatrixApplication.java
package com.example.matrix;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class MatrixApplication {
public static void main(String[] args) {
SpringApplication.run(MatrixApplication.class, args);
}
}
IndexController.java
package com.example.matrix.controller;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import com.example.matrix.model.Matrix;
#Controller
public class IndexController {
#GetMapping("/")
public String index() {
return "index";
}
#PostMapping("/generate")
public String matrixRegistration(#ModelAttribute Matrix matrix, Model model) {
matrix.fillArrayList();
model.addAttribute("matrix", matrix);
return "redirect:/";
}
}
Matrix.java
package com.example.matrix.model;
import java.util.Arrays;
import java.util.Random;
public class Matrix {
public String xValue;
public String yValue;
public String matrixList[][];
public Matrix() {
fillArrayList();
}
public void setMatrixList(String[][] matrixList) {
this.matrixList = matrixList;
}
public void printMatrixList() {
for(int i=0; i < Integer.parseInt(this.xValue); i++){
for(int j=0; j < Integer.parseInt(this.yValue); j++){
System.out.print(this.matrixList[i][j] + " ");
}
System.out.println("");
}
}
#Override
public String toString() {
return "Matrix [matrixList=" + Arrays.toString(matrixList) + "]";
}
public void fillArrayList() {
int xValue = Integer.parseInt(this.xValue);
int yValue = Integer.parseInt(this.yValue);
this.matrixList = new String[xValue][yValue];
Random rand = new Random();
for(int i=0; i < xValue; i++){
for(int j=0; j < yValue; j++){
this.matrixList[i][j] = String.valueOf(rand.nextInt(100));
}
}
}
}
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="generate" method="post">
<label for="x">X</label>
<input type="text" name="xValue"/><br />
<label for="y">Y</label>
<input type="text" name="yValue"/> <br />
<button type="submit">Generate</button>
</form>
<table border="1" cellpadding="10">
<table border="1" cellpadding="10">
<tbody>
<tr th:each="matrix : ${matrix}">
<td th:text="${matrix.xValue}"></td>
<td th:text="${matrix.yValue}"></td>
</tr>
</table>
</table>
</body>
</html>
Part of the error I got. I cut it in half because it was too long.
java.lang.NumberFormatException: Cannot parse null string
at java.base/java.lang.Integer.parseInt(Integer.java:630) ~[na:na]
at java.base/java.lang.Integer.parseInt(Integer.java:786) ~[na:na]
at com.example.matrix.model.Matrix.fillArrayList(Matrix.java:38) ~[classes/:na]
at com.example.matrix.model.Matrix.<init>(Matrix.java:15) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.constructAttribute(ModelAttributeMethodProcessor.java:247) ~[spring-web-5.3.23.jar:5.3.23]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:220) ~[spring-web-5.3.23.jar:5.3.23]
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:85) ~[spring-webmvc-5.3.23.jar:5.3.23]
2022-10-17 20:27:10.540 ERROR 39459 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.matrix.model.Matrix]: Constructor threw exception; nested exception is java.lang.NumberFormatException: Cannot parse null string] with root cause
java.lang.NumberFormatException: Cannot parse null string
at java.base/java.lang.Integer.parseInt(Integer.java:630) ~[na:na]
at java.base/java.lang.Integer.parseInt(Integer.java:786) ~[na:na]
at com.example.matrix.model.Matrix.fillArrayList(Matrix.java:38) ~[classes/:na]
at com.example.matrix.model.Matrix.<init>(Matrix.java:15) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.constructAttribute(ModelAttributeMethodProcessor.java:247) ~[spring-web-5.3.23.jar:5.3.23]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:220) ~[spring-web-5.3.23.jar:5.3.23]
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:85) ~[spring-webmvc-5.3.23.jar:5.3.23]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:147) ~[spring-web-5.3.23.jar:5.3.23]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122) ~[spring-web-5.3.23.jar:5.3.23]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-5.3.23.jar:5.3.23]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-5.3.23.jar:5.3.23]
Thank you for your attention.
Good deeds.
Based on the assumption that you've filled in valid data in the form you'r submitting to the post. You will need standard setter (and maybe getter for view) methods for spring to be able to fill your model entity.
Also <tr th:each="matrix : ${matrix}"> is problematic as you'r defining the same variable name twice this way.
To prevent errors like these it's good practice to add bean validation with #NotNull on your y and x variables and modify controller as such
#PostMapping("/generate")
public String matrixRegistration(#Valid Matrix matrix, Model model, BindingResult bindingresult)
{
if (bindingResult.hasErrors())
{
//handle errors
}
matrix.fillArrayList();
model.addAttribute("matrix", matrix);
return "redirect:/";
}
see https://zetcode.com/spring/bindingresult/ for more details
I solved my own problem myself.
<table>
<tr th:each="values :${matrixArray}">
<th:block th:each="val :${values}">
<td th:text="*{val}"></td>
</th:block>
</tr>
</table>
Thans for suggestions. Its help a lot.

Error 500 while trying to load a xml file in java

I have this uni project going on, and I'm stuck on this error and can't find the solution.
First there's the JSP file that loads a list
<%#page import="Controllers.RestClient"%>
<%#page import="java.util.List"%>
<%#page import="Model.Stationss"%>
<%#page import="javax.xml.bind.JAXBException"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<label for="Origin">Embark Station:</label>
<select name ="StartStation" id="stations">
<%
List<Stationss> listS = RestClient.getStations();
for (int i = 0; i < listS.size(); i++) {
out.print("<option value = " + i + ">" + listS.get(i).getName() + "</option>");
}
%>
</select><br>
</body>
</html>
There's also the ReST client access
package Controllers;
import java.util.List;
import Model.Stationss;
import java.util.ArrayList;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;
public class RestClient {
public static List<Stationss> getStations() {
System.out.print("test");
String link = "http://localhost:8080";
String path = "/Service/webresources/pkg.service.stations";
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target(link).path(path);
Invocation.Builder invocation = target.request(MediaType.APPLICATION_XML);
System.out.print(link);
System.out.print(path);
Response response = invocation.get(Response.class);
System.out.print(response);
List<Stationss> list = response.readEntity(new GenericType<List<Stationss>>() {
});
System.out.print(list);
return list;
}
};
and after I have the model
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Model;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class Stationss {
private int id;
private String name;
private int zone;
Gate gates = new Gate(zone);
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getZone() {
return zone;
}
public void setZone(int zone) {
this.zone = zone;
}
public Gate getGates() {
return gates;
}
public void setGates(Gate gates) {
this.gates = gates;
}
public Stationss() {
}
public Stationss(int id, String name, int zone) {
this.id = id;
this.name = name;
this.zone = zone;
}
#Transient
public CheckTicket enter(String xml) {
return gates.enter(xml);
}
#Transient
public boolean exit(String xml) {
return gates.exit(xml);
}
}
and at last, the huge error screen
HTTP Status 500 – Internal Server Error
Type Exception Report
Message An exception occurred processing [/newjsp.jsp] at line [23]
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: An exception occurred processing [/newjsp.jsp] at line [23]
20: <label for="Origin">Embark Station:</label>
21: <select name ="StartStation" id="stations">
22: <%
23: List<Stationss> listS = RestClient.getStations();
24: for (int i = 0; i < listS.size(); i++) {
25: out.print("<option value = " + i + ">" + listS.get(i).getName() + "</option>");
26: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:610)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:499)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:359)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:269)
javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getStoredJaxbContext(AbstractJaxbProvider.java:288)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getJAXBContext(AbstractJaxbProvider.java:273)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:189)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:164)
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:289)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1444)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1252)
javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:267)
javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getStoredJaxbContext(AbstractJaxbProvider.java:288)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getJAXBContext(AbstractJaxbProvider.java:273)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:189)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:164)
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:289)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/10.0.16
It's my first time learning java and I'm completely at loss on what I'm doing wrong.
I know the link the xml list is working fine.
You have missing dependencies on your classpath
See the stack trace
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
This answer might be helpful

How to respond List<> from a RESTful Service using #GET

This is how far i have come trying to respond with a List<> of Users to a Client . Every time i get Error 500 so i tried to respond with just a String and it worked so there is not a problem with the server/client communication. I searched the Internet and i found some examples that they returned Lists<> without error but i can't get mine to work.
User Class
package org.cs131111.user;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "user")
public class User implements Serializable{
private String studentID;
private String Fname;
private String Lname;
private int semester;
public User(){}
public User(String sID,String fname,String lname,int sem){
this.studentID=sID;
this.Fname=fname;
this.Lname=lname;
this.semester = sem;
}
public String getId() {
return studentID;
}
#XmlElement
public void setId(String id) {
this.studentID = id;
}
public String getName() {
return Fname+"_"+Lname;
}
#XmlElement
public void setFName(String name) {
this.Fname = name;
}
#XmlElement
public void setLName(String name) {
this.Lname = name;
}
public int getSemester() {
return semester;
}
#XmlElement
public void setSemester(int semester) {
this.semester = semester;
}
}
UserList class
package org.cs131111.user;
import org.cs131111.db.DatabaseConnection;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class UserList {
public List<User> list = null;
public List<User> getAllUsers(){
User stud = null;
DatabaseConnection newc = null;
newc = new DatabaseConnection();
list = new ArrayList<User>();
try {
newc.results=newc.query.executeQuery("select * from `students`");
while(newc.results.next()){
stud = new User(newc.results.getString("studentid"),newc.results.getString("fname"),newc.results.getString("lname"),newc.results.getInt("semester"));
list.add(stud);
System.out.println(stud.getId()+" "+stud.getName());
}
} catch (SQLException ex) {
Logger.getLogger(UserList.class.getName()).log(Level.SEVERE, null, ex);
}
newc.close();
return list;
}
}
UserService class
package org.cs131111.user;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/UserService")
public class UserService {
UserList userOb = new UserList();
#GET
#Path("/users")
#Produces(MediaType.APPLICATION_XML)
public List<User> getUsers(){
final List<User> users = userOb.getAllUsers();
return users;
}
}
The Client
<%#page import="java.util.List"%>
<%#page import="User.User"%>
<%#page import="java.io.IOException"%>
<%#page import="java.net.MalformedURLException"%>
<%#page import="java.io.InputStreamReader"%>
<%#page import="java.io.BufferedReader"%>
<%#page import="java.net.HttpURLConnection"%>
<%#page import="java.net.URL"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%
try {
URL url = new URL("http://localhost:11118/EclassServer/webresources/UserService/users");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
List<User> u= (List<User>)conn.getContent();
out.println("Output from Server .... \n");
String test=u.get(1).getId();
out.println(test);
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
%>
</body>
</html>
Server's stack trace
Warning: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.RuntimeException: Failed : HTTP error code : 500
at org.apache.jsp.clientGet_jsp._jspService(clientGet_jsp.java:80)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
I can't post this as a comment so here it is. You can't really expect HttpUrlConnection.getContent to return a List of User instances. From the Javadoc
This method first determines the content type of the object by calling
the getContentType method. If this is the first time that the
application has seen that specific content type, a content handler for
that content type is created:
If the application has set up a content handler factory instance using
the setContentHandlerFactory method, the createContentHandler method
of that instance is called with the content type as an argument; the
result is a content handler for that content type. If no content
handler factory has yet been set up, or if the factory's
createContentHandler method returns null, then the application loads
the class named:
The usual way to get the content (when using HttpUrlConnection) is by using BufferedReader in combination with InputStreamReader something like
if(resCode==200){
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
stringBuilder = new StringBuilder();
String line=null;
while((line = reader.readLine()) != null){
stringBuilder.append(line + "\n");
}
}
But even now you will only get your User list as one large string (formatted as XML) and you should use an object mapper to convert the content/entity string to a List of User instances.
If, on the other hand, you used a Jersey client, it would be able to do the conversion automatically for you (it uses JAXB under the hood). Your Jersey client code might look something like (not tested)
WebTarget target = client.target(UriBuilder.fromUri("http://localhost:11118/EclassServer/webresources/UserService/users").build());
GenericType<List<User>> genType = new GenericType<List<User>>();
List<User> userList =(String) target.request().accept(MediaType.XML_APPLICATION).get(genType);
You don't have a correct root element. You've added the #XmlRootElement annotation to the User class, but it's not the root element as you're returning a list of users not a single user.
I recommend to specify a XSD and generate the JAXB classes rather than writing them yourself.

HTTP Status 404 - Servlet mvc-dispatcher is not available jars already added in user library being used

Getting an error even after adding all jars in user library HTTP Status 404 - Servlet mvc-dispatcher is not available jars already added in user library being used. Tried all sorts not able to resolve Can't post screenshots as i don't have 10 points
Servlet mapping code in web.xml is below:
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet.class</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>*.spring</url-pattern>
</servlet-mapping>
My Jsp is below
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Login.spring" method = "post">
<input type = "text" name = "userName" id = "userName">
<input type = "password" name = "password" id = "password">
<input type = "submit">
</form>
</body>
</html>
My Controller is below
package com.lnt.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.lnt.services.AuthenticateServices;
#Controller
#RequestMapping("/Login.spring")
public class LoginController {
//#Autowired
AuthenticateServices authenticateService = new AuthenticateServices();
#RequestMapping(method=RequestMethod.POST)
public ModelAndView processCredentials(HttpServletRequest req, HttpServletResponse res)
{
String userName =req.getParameter("userName") ;
String password = req.getParameter("password");
System.out.println("into login controller");
String message = "Invalid credentials";
List<String> userdetails = new ArrayList<String>();
userdetails = authenticateService.verifyUserNameAndPassword(userName, password);
if((userdetails)!=null)
{
message = "welcome" + userName ;
}
return new ModelAndView("results", "message", message) ;
}
}
Here is the stack trace :
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet.class
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Your configuration is wrong
<servlet-class>org.springframework.web.servlet.DispatcherServlet.class</servlet-class>
The <servlet-class> element expects the name of a class. There is no such class called
org.springframework.web.servlet.DispatcherServlet.class
You probably meant
org.springframework.web.servlet.DispatcherServlet

GWT & GDATA: given a single use token, trying to retrieve a list of documents

I'm following this guide:
http://code.google.com/intl/it-IT/apis/documents/docs/2.0/developers_guide_java.html
I just need to retrieve a token and use it to get a list of documents, so i used AuthSub to get a single use token, and this seems to work: i get a string like this
1/BM14a4NnfKf........
Now i'm trying to do this: http://code.google.com/intl/it-IT/apis/documents/docs/2.0/developers_guide_java.html#Versioning
1) Specifying a version
2) Retrieving a list of documents
I'm managing these functions in a class called TokenServiceImpl:
package mui.server.services;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import mui.client.services.TokenService;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gdata.client.docs.DocsService;
import com.google.gdata.client.http.AuthSubUtil;
import com.google.gdata.data.docs.DocumentListEntry;
import com.google.gdata.data.docs.DocumentListFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class TokenServiceImpl extends RemoteServiceServlet implements
TokenService {
private static final long serialVersionUID = 1L;
String nextUrl = "";
String scope = "https://docs.google.com/feeds/";
boolean secure = false; // set secure=true to request secure AuthSub tokens
boolean session = true;
String authSubUrl = "";
#Override
public String getToken(String requestUri) {
nextUrl = requestUri;
authSubUrl = AuthSubUtil.getRequestUrl(nextUrl, scope, secure, session);
return ", clicca <a href='" + authSubUrl
+ "'>qui</a> per regalarmi un token! (esempio Google Docs)";
}
#Override
public String getDocsInfo(String token) {
String elenco=", grazie del token, eccolo qui:<br> " + token + "<br>";
DocsService client = new DocsService("yourCo-yourAppName-v1");
client.setProtocolVersion(DocsService.Versions.V2);
try {
URL feedUri = new URL(
"https://docs.google.com/feeds/documents/private/full/");
DocumentListFeed feed = client.getFeed(feedUri, DocumentListFeed.class);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return elenco;
}
}
But in the method getDocsInfo (which get the string "token", the token previously retrieved) the only row
DocumentListFeed feed = client.getFeed(feedUri, DocumentListFeed.class);
gives me errors:
22-gen-2012 11.14.19 com.google.appengine.repackaged.org.apache.http.impl.client.DefaultRequestDirector handleResponse
AVVERTENZA: Authentication error: Unable to respond to any of these challenges: {googlelogin=WWW-Authenticate: GoogleLogin realm="http://www.google.com/accounts"}
com.google.gdata.util.AuthenticationException: OK
<HTML>
<HEAD>
<TITLE>Authorization required</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Authorization required</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:998)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
at mui.server.services.TokenServiceImpl.getDocsInfo(TokenServiceImpl.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:78)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:362)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
What am I missing? I'm really confused... I'm at the beginning with all this, maybe it's something stupid... but is't it just what's exactly written in the guide?
And here in this example
http://code.google.com/intl/it-IT/apis/documents/docs/2.0/developers_guide_java.html#ListDocs
where do I need to use the token i retrieved?
Two steps more were required:
1) change the token to "sessionToken":
String sessionToken = AuthSubUtil.exchangeForSessionToken(token, null);
2) associate the token to the client:
DocsService client = new DocsService("yourCo-yourAppName-v1");
client.setAuthSubToken(sessionToken);

Categories