如何使用泽西改变状态Openhab项目?

时间:2018-06-02 19:19:34

标签: java rest jersey

如何使用Jersey改变状态Openhab项目?

源代码:

ClientConfig clientConfig = new ClientConfig();
Client client = ClientBuilder.newClient(clientConfig);
WebTarget webTarget = client.target("http://demo.openhab.org:8080/rest");
WebTarget resourceWebTarget = webTarget.path("things");
Form form =new Form();
if (item.getState().equals("ON"))
   form.param("state", "OFF");
else
   form.param("state", "ON");
response = 
webTarget.path("items").path("Light_GF_Corridor_Ceiling").request()
.header("Content-Type", "text/plain")
.header("Accept", "application/json")        
.post(Entity.entity(form,MediaType.APPLICATION_JSON),Response.class);
System.out.println("Status Info Response " + response.getStatusInfo());

输出:     状态信息响应不支持的媒体类型

1 个答案:

答案 0 :(得分:0)

// In Collection default Stream<E> stream() { return StreamSupport.stream(spliterator(), false); } // In ArrayList public Spliterator<E> spliterator() { return new ArrayListSpliterator(0, -1, 0); } // In StreamSupport public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel) { return new ReferencePipeline.Head<>(spliterator, StreamOpFlag.fromCharacteristics(spliterator), parallel); } // In ReferencePipeline public void forEach(Consumer<? super P_OUT> action) { evaluate(ForEachOps.makeRef(action, false)); } // In ForEachOps public static <T> TerminalOp<T, Void> makeRef(Consumer<? super T> action, boolean ordered) { return new ForEachOp.OfRef<>(action, ordered); } // many method calls eventually leading to // In ArrayListSpliterator public void forEachRemaining(Consumer<? super E> action) { for (int i = 0; i < size(); i++) action.accept(get(i)); } 并不打算与Form一起使用(它意味着与application/json一起使用)。使用JSON,您应该使用POJO,POJOS集合或字符串。如果要发送POJO集合,则需要将其包装在GenericEntity