Olá, estou tentando realizar o teste de impressão do xml e o mesmo trás lista vazia. poderia me auxiliar?O meio de comunicação sobre o livro pode ser este ou você indica outro?ESTE Servlet não exibe o xml populado:package com.rest.servlet.http;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.Collection;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.xml.bind.JAXBContext;import javax.xml.bind.JAXBException;import javax.xml.bind.Marshaller;import com.rest.servlet.http.xml.Automoveis;import com.rest.servlet.repository.Estoque;@WebServlet("/automoveisXml/*")public class AutomovelServletXml extends HttpServlet{ private static final long serialVersionUID = -638896147519496287L; private Estoque estoque = new Estoque(); private static JAXBContext context; static{ try { context = JAXBContext.newInstance(Automoveis.class); } catch (JAXBException e) { throw new RuntimeException(e); } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ try { Marshaller marshaller = context.createMarshaller(); response.setContentType("application/xml;charset=UTF-8"); PrintWriter out = response.getWriter(); Automoveis automoveis = new Automoveis(); automoveis.setAutomoviesXml(new ArrayList<>(estoque.listarAutomoveis())); marshaller.marshal(automoveis, out); } catch (Exception e) { response.sendError(500, e.getMessage()); } }}Resultado <automoveis><automovel/><automovel/><automovel/><automovel/><automovel/><automovel/></automoveis>***** Este funciona sem utilizar XMLpackage com.rest.servlet.http;import java.io.IOException;import java.io.PrintWriter;import java.util.Collection;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.rest.servlet.model.Automovel;import com.rest.servlet.repository.Estoque;@WebServlet("/automoveis/*")public class AutomovelServlet extends HttpServlet{ //http://localhost:8080/pjRESTfulServlet1/automoveis private static final long serialVersionUID = -638896147519496287L; private Estoque estoque = new Estoque(); public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ PrintWriter out = response.getWriter(); Collection<Automovel> automoveis = estoque.listarAutomoveis(); for(Automovel auto : automoveis){ out.print(auto); } }}Resultado Ka - FORDGol - WOLKSWAGEMEcoSport - FORD207 - PEUGEOTHB20 - HYUNDAICivic - HONDAESTOQUEpublic class Estoque { private Collection<Automovel> automoveis = new ArrayList<>(); public Collection<Automovel> getAutomoveis() { return automoveis; } public void setAutomoveis(Collection<Automovel> automoveis) { this.automoveis = automoveis; }public Estoque(){ Automovel automovel01 = new Automovel("Ka", "Compacto e economico", Categoria.HATCH, Marca.FORD); Automovel automovel02 = new Automovel("Gol", "Compacto e economico", Categoria.HATCH, Marca.WOLKSWAGEM); Automovel automovel03 = new Automovel("EcoSport", "Espaçoso e aventureiro", Categoria.SUV, Marca.FORD); Automovel automovel04 = new Automovel("207", "Compacto e completo", Categoria.HATCH, Marca.PEUGEOT); Automovel automovel05 = new Automovel("HB20", "Confortável e potente", Categoria.HATCH, Marca.HYUNDAI); Automovel automovel06 = new Automovel("Civic", "Luxuoso por completo", Categoria.SEDAN, Marca.HONDA); automoveis.add(automovel01); automoveis.add(automovel02); automoveis.add(automovel03); automoveis.add(automovel04); automoveis.add(automovel05); automoveis.add(automovel06); } public Collection<Automovel> listarAutomoveis(){ return new ArrayList<>(this.automoveis); } public void adicionarAutomovel(Automovel automovel){ this.automoveis.add(automovel); }}
DESDE JÀ AGRADEÇO!Att,Carl Edwin.https://carledwinj.wordpress.com/
--
Você está recebendo esta mensagem porque se inscreveu no grupo "SOA Aplicado" dos Grupos do Google.
Para cancelar a inscrição neste grupo e parar de receber seus e-mails, envie um e-mail para soa-aplicado...@googlegroups.com.
Para postar neste grupo, envie um e-mail para soa-ap...@googlegroups.com.
Visite este grupo em http://groups.google.com/group/soa-aplicado.
Para obter mais opções, acesse https://groups.google.com/d/optout.
Olá, Carl, tudo bem?Você. poderia POSTAR como classes Automovel e Automoveis? Disso de Além, térios Como Você. POSTAR ELAS com alguma Formatação? Da forma Como Você. postou essas Anteriores, eu enxergo como classes Todas Direto los UMA Única Linha = /[] 'S
Em 13 de março de 2014 20:45, Carl Edwin Antonio Nascimento < carl ... @ gmail.com > escreveu:
Olá, ESTOU tentando Realizar o teste de IMPRESSÃO fazer xml EO MESMO Trás Lista Vazia. poderia me auxiliar O Meio de Comunicação sobre o Livro PODE serviços Este UO Você. indica Outro ESTE Servlet Localidade: Não exibe o xml populado:? pacote com.rest.servlet.http; import java.io.IOException; java.io.PrintWriter importação; import java.util.ArrayList; java.util.Collection importação;. javax.servlet importação ServletException; javax.servlet.annotation importação. WebServlet; javax.servlet.http importação. HttpServlet; javax.servlet.http importação. HttpServletRequest; javax importação . servlet.http. HttpServletResponse; javax.xml.bind.JAXBContext importação; javax.xml.bind.JAXBException importação; javax.xml.bind.Marshaller importação; . com.rest.servlet.http.xml importação Automoveis; com importação. rest.servlet.repository. Estoque de; @ WebServlet ("/ automoveisXml / * ") public class AutomovelServletXml estende HttpServlet {private static final = serialVersionUID longa-638896147519496287L; Estoque de Estoque de private = new Estoque de (); contexto JAXBContext estática privado; static {try {context = JAXBContext.newInstance ( Automoveis.class);} catch (JAXBException e) {throw new RuntimeException (e);}} protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {try {Marshaller marshaller = contexto. createMarshaller (); response.setContentType (" application / xml; charset = UTF-8 " ); PrintWriter out = response.getWriter (); Automoveis automoveis = new Automoveis (); automoveis.setAutomoviesXml ( new ArrayList <> (estoque. listarAutomoveis ())); marshaller.marshal (automoveis, fora);} catch (Exception e) {response.sendError (500, e.getMessage ());}}} Resultado Este Funciona SEM utilizar XMLpackage com.rest.servlet.http; import java.io.IOException; java.io.PrintWriter importação; java.util.Collection importação;. Javax.servlet importação ServletException; javax.servlet.annotation importação. WebServlet; importar javax.servlet.http. HttpServlet; javax.servlet.http importação. HttpServletRequest; javax.servlet.http importação. HttpServletResponse;. com.rest.servlet.model importação Automovel;. com.rest.servlet.repository importação Estoque de; @ WebServlet ("/ automoveis / * ") public class AutomovelServlet estende HttpServlet {/ / http://localhost:8080/ pjRESTfulServlet1/automoveis private static serialVersionUID longo final =-638896147519496287L; Estoque de Estoque de private = new Estoque de (); public void doGet ( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {PrintWriter out = response.getWriter (); Coleção <Automovel> automoveis = estoque.listarAutomoveis (); for (Automovel auto: AUTOMOVEIS) {out.print (automático);}}} Resultado Ka - FORDGol - WOLKSWAGEMEcoSport - FORD207 - PEUGEOTHB20 - HYUNDAICivic - HONDAESTOQUEpublic classe Estoque de {private Coleção <Automovel> automoveis = new ArrayList <> (); Coleção público <Automovel> getAutomoveis () {return automoveis;} setAutomoveis public void (Collection < Automovel> AUTOMOVEIS) {this.automoveis = automoveis;} Estoque de público () {Automovel automovel01 = new Automovel ("Ka", "Compacto e economico", Categoria.HATCH, Marca.FORD); Automovel automovel02 = new Automovel ("Gol "," Compacto e economico ", Categoria.HATCH, Marca.WOLKSWAGEM); Automovel automovel03 = new Automovel (" EcoSport "," Espaçoso e aventureiro ", Categoria.SUV, Marca.FORD); Automovel automovel04 = new Automovel (" 207 "," Compacto e completo ", Categoria.HATCH, Marca.PEUGEOT); Automovel automovel05 = new Automovel (" HB20 "," Confortável e potente ", Categoria.HATCH, Marca.HYUNDAI); Automovel automovel06 = new Automovel (" Civic "," Luxuoso POR completo ", Categoria.SEDAN, Marca.HONDA); automoveis.add (automovel01); automoveis.add (automovel02); automoveis.add (automovel03); automoveis.add (automovel04); automoveis.add (automovel05 ); automoveis.add (automovel06);} Coleção público <Automovel> listarAutomoveis () {return new ArrayList <> (this.automoveis);} public void adicionarAutomovel (Automovel automovel) {this.automoveis.add ( automovel);}} DESDE JA AGRADEÇO Att, Carl Edwin!. https://carledwinj. wordpress.com / - . Voce esta recebendo ESTA MENSAGEM o Porque se inscreveu nenhum Grupo "SOA Aplicado" dos Grupos do Google fazer Pará Cancelar um INSCRIÇÃO Neste Grupo e Parar de receber SEUs e-mails, envie e-mail hum parágrafo soa-aplicado ... @ googlegroups.com . Pará POSTAR Neste Grupo, envie e-mail hum parágrafo soa-ap ... @ googlegroups.com . Visite Este Grupo los http: / / groups.google.com / group / soa-aplicado . Para obter Mais opções, Acessem https://groups.google.com/d/ optout .
--
Você recebeu essa mensagem porque está inscrito no grupo quot;SOA Aplicado" dos Grupos do Google.
Para cancelar inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para soa-aplicado...@googlegroups.com.
Para postar nesse grupo, envie um e-mail para soa-ap...@googlegroups.com.
Para mais opções, acesse https://groups.google.com/d/optout.