简体   繁体   English

当我调用我的 web 服务 GET 请求时没有响应

[英]Not having a response when I call my web service GET request

I'm a student who needs help with a homework problem.我是一名需要帮助解决家庭作业问题的学生。 The thing is that I wrote a rest web service using SAX parser in order to display a xml file that I have stored on the same folder of the project.问题是我使用 SAX 解析器编写了 rest web 服务,以显示我存储在项目同一文件夹中的 xml 文件。 The problem is that when I use the path I provided to it, it's not happening anything.问题是当我使用我提供给它的路径时,它什么也没发生。 I'm probably doing something wrong on my code.我可能在我的代码上做错了什么。 Here it is:这里是:

package com.crunchify.restjersey;

import java.io.IOException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

@Path("/saxbooksxml")
public class SaxBooksXml {

    public SaxBooksXml(){}

    @GET
    @Produces(MediaType.APPLICATION_XML)
    public void gofindsaxbooks(){
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = null;
        try {
            saxParser = factory.newSAXParser();
        } catch (ParserConfigurationException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SAXException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        DefaultHandler handler = new DefaultHandler(){
            boolean bauthor = false;
            boolean btitle = false;
            boolean bgenre = false;
            boolean bprice = false;
            boolean bpublish_date = false;
            boolean bdescription = false;

            public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException{
                if(qName.equalsIgnoreCase("author")){
                    bauthor = true;
                }
                if(qName.equalsIgnoreCase("title")){
                    btitle = true;
                }
                if(qName.equalsIgnoreCase("genre")){
                    bgenre = true;
                }
                if(qName.equalsIgnoreCase("price")){
                    bprice = true;
                }
                if(qName.equalsIgnoreCase("publish_date")){
                    bpublish_date = true;
                }
                if(qName.equalsIgnoreCase("description")){
                    bdescription = true;
                }
            }

            public void endElement(String uri, String localName, String qName) throws SAXException{

            }

            public void characters(char ch[], int start, int lenght) throws SAXException{
                if(bauthor){
                    System.out.println("author: "+new String(ch, start, lenght));
                    bauthor = false;
                }
                if(btitle){
                    System.out.println("title: "+new String(ch, start, lenght));
                    btitle = false;
                }
                if(bgenre){
                    System.out.println("genre: "+new String(ch, start, lenght));
                    bgenre = false;
                }
                if(bprice){
                    System.out.println("price: "+new String(ch, start, lenght));
                    bprice = false;
                }
                if(bpublish_date){
                    System.out.println("publish_date: "+new String(ch, start, lenght));
                    bpublish_date = false;
                }
                if(bdescription){
                    System.out.println("description: "+new String(ch, start, lenght)+"\n");
                    bdescription = false;
                }
            }

        };

        try {
            saxParser.parse("Books.xml", handler);
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

This is a print of part of the file I'm trying to parse.这是我要解析的文件的一部分的打印。 The idea is to display it on the browser exactly the same.这个想法是在浏览器上完全一样地显示它。

enter image description here在此处输入图像描述

Your method gofindsaxbooks returns void您的方法gofindsaxbooks返回void

Change it like below:更改如下:

        @GET
        @Produces(MediaType.APPLICATION_XML)
        public Response gofindsaxbooks()
        {

            return Response.status(200).entity("Test XML created").build();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有其他对象列表的Spring Web服务请求和响应映射 - Spring web service request and response for mapping having list of other objects 我可以将Web服务称为HTTP请求吗? - can i call web service as a HTTP request? 如何获取JSON Web服务请求的响应时间? - How to get the response time of a json web service request? 当我创建soap请求并在android中调用soap服务时,我从服务器获取了错误字符串,其中我的pdf字符串长度为18139367 - when i create soap request and call the soap service in android then i get fault string from server where my pdf string length is18139367 我的jasonParser类无法从php Web Service获得响应 - My jasonParser class in doesnot get response from php web Service 当我在EJB服务中调用两个DAO时,为什么会出现EJBTransactionRolledbackException? - why do I get an EJBTransactionRolledbackException when I call two DAOs in my EJB Service? 使用针对请求和响应的String调用SOAP Web服务的最简单方法是什么? - What's the simplest way to call a SOAP web service using a String for the request and response? 从GET请求返回pojo时,Jersey Web服务挂起 - Jersey web service hangs when returning pojo from GET request 致电Web服务(SSL)时出现错误 - I am gettin error when I call Web Service (SSL) 调用Web服务并在Blackberry中解析xml响应 - Call a web service and parse xml response in blackberry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM