如何将数据从geojson文件提取到REST服务中

时间:2019-05-31 12:16:29

标签: java rest netbeans-8

我有一个纯geojson文件,我想在Netbeans 8.2上使用Java将其放入REST服务。当前文件存储在Netbeans的org.geojson包中“ Other Sources”部分的文件名下:Bramownice_waw_7.json。我当前的代码如下:

 package com.test;

    import java.io.InputStream; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.io.InputStreamReader; 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.StringWriter; 
import java.nio.charset.Charset; 
import java.util.Scanner; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import org.apache.commons.io.IOUtils;

    public class Wirtb {
        public String getData() {
        String queryres = "abc";  
            try {
                String data = "abc";
                String respath = "/org/geojson/Bramownice_waw_7.json";
                InputStream in = Wirtb.class.getResourceAsStream(respath);
                /*
                if ( in == null )
                throw new Exception("resource not found: " + respath);
                */
                StringWriter writer = new StringWriter();
                IOUtils.copy(in, writer);
                queryres = writer.toString();
                return queryres;
            } catch (IOException ex) {
                Logger.getLogger(Wirtb.class.getName()).log(Level.SEVERE, null, ex);
            }
            return queryres;
        }
        public static void main(String[] args) throws Exception {
            Wirtb wirtb = new Wirtb();
            //app2.connect();
            //String abc = wbram.connect
            String abc = wirtb.getData();
            System.out.println(abc);
        } }

这将json作为String返回。我还尝试设置REST服务:

private static String wirtualnabgeoJSON(boolean prettyPrint, int wirtualna){
        Wirtb wirtb = new Wirtb();
        String qr = wirtb.getData();
        return qr;
    }

@GET
    @Path("wirtb/{wirtualna}")
    @Produces(MediaType.APPLICATION_JSON)
    //@Produces(MediaType.TEXT_PLAIN)
    public Response wirtubfetch(@PathParam("wirtualna") int wirtualna)  {
    //JSONObject jsono = createJSON(true);
        //GeometryJSON gjson = creategeoJSON(true);
        String wb = wirtualnabgeoJSON(true, wirtualna);
    //return Response.ok().entity(jsono.toString()).build();
        return Response.ok().header("Access-Control-Allow-Origin", "*").entity(wb).build();

但是结果是错误404。如何解决? 谢谢

0 个答案:

没有答案