在我的java Web服务中获取空值

时间:2016-03-01 12:23:50

标签: java json web-services rest jersey

嗨我有由jersey创建的java web服务。如果我从postman测试它工作正常。我在gui中集成了api。如果我从gui测试我得到null值。我不知道它为什么打印null我在邮递员中使用application / x-www-form-urlencoded

我的代码

public class RESTservice {

@POST
@Path("/data")

@Produces(MediaType.APPLICATION_JSON)
public Response getMsg(@FormParam("data") String JSONString) throws IOException, InterruptedException, URISyntaxException, JSONException
{
    StoreIntoHDFS obj = new StoreIntoHDFS(JSONString);
    String response1 = obj.storeAddress();
    return Response.status(200).entity(response1).build();
}
}

我的商店文件

public class StoreIntoHDFS {
public String JSONString;
public StoreIntoHDFS(String jSONString) {
    super();
    JSONString = jSONString;

}

 public String storeAddress() throws IOException, InterruptedException, URISyntaxException {

    Configuration conf = new Configuration();
    conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
    conf.addResource(new Path("/etc/hadoop/conf/core-site.xml"));
    conf.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));

    BufferedWriter br = null;
    FileSystem hdfs = null;

    JSONObject obj = new JSONObject();

    try {
        java.util.Date date = new java.util.Date();

        hdfs = FileSystem.get(new URI("hdfs://aserver:8020"), conf);

        Path file = new Path("hdfs://aserver:8020/user/ec2-user/PropertyDetails/" + date.getTime());

        StringBuilder sb = new StringBuilder();
        sb.append(JSONString);
        byte[] byt = sb.toString().getBytes();
        FSDataOutputStream fsOutStream = hdfs.create(file);
        fsOutStream.write(byt);
        fsOutStream.close();

        obj.put("status", 1);
        obj.put("msg", "Information stored successfully");
        obj.put("data", JSONString);

        return obj.toString();

    }

    catch (Exception e) {

        obj.put("status", 0);
        obj.put("msg", "Could not store the address");
        obj.put("data", e.toString());

        return obj.toString();
    }

    finally {
        if (br != null) {
            br.close();
        }

        if (hdfs != null) {
            hdfs.close();

        }

    }
}

}

我的web.xml

<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

任何帮助将不胜感激。

0 个答案:

没有答案