Form form = new Form(); form.add("x", "foo"); form.add("y", "bar"); Client client = ClientBuilder.newClient(); WebTarget resource = client.target("http://localhost:8080/someresource"); Builder request = resource.request(); request.accept(MediaType.APPLICATION_JSON); Response response = request.get(); if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { System.out.println("Success! " + response.getStatus()); System.out.println(response.getEntity()); } else { System.out.println("ERROR! " + response.getStatus()); System.out.println(response.getEntity()); }
Form form = new Form(); form.add("x", "foo"); form.add("y", "bar"); ClientResource resource = new ClientResource("http://localhost:8080/someresource"); Response response = resource.post(form.getWebRepresentation()); if (response.getStatus().isSuccess()) { System.out.println("Success! " + response.getStatus()); System.out.println(response.getEntity().getText()); } else { System.out.println("ERROR! " + response.getStatus()); System.out.println(response.getEntity().getText()); }
public String testMethodForList() { Form form = new Form(); form.add("list", "first String"); form.add("list", "second String"); form.add("list", "third String"); return service .path("bestellung") .path("add") .type(MediaType.APPLICATION_FORM_URLENCODED) .accept(MediaType.TEXT_XML) .post(String.class, form); }
... OutputStream out = new ByteArrayOutputStream(); JAXBContext context = JAXBContext.newInstance(Kunde.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(kunde, out); out.close(); Form form = new Form(); form.add("entity", out.toString()); ...
... OutputStream out = new ByteArrayOutputStream(); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, kunde); out.close(); Form form = new Form(); form.add("entity", out.toString()); ...
@Test public void uploadFile() throws Exception { String address = "http://0.0.0.0:8000/r/upload"; WebResource r = Client.create().resource(address); Form form = new Form(); form.add("name", "test"); form.add("content", "SOME CONTENT GOES HERE"); String s = r.post(String.class, form); System.out.println(s); }
class MyPage extends Page { private Date startDate; private Date endDate; public MyPage() { Form form = new Form("form"){ ... submit logic etc ...}; add(form); form.add(new DateField("startDate", new PropertyModel<Date>(this, "startDate"))); form.add(new DateField("endDate", new PropertyModel<Date>(this, "endDate"))); IModel<List<Item>> itemsModel = new LoadableDetachableModel<List<Item>>(){ @Override protected List<Item> load() { return logParseDao.findByDates(startDate, endDate); } }; add(new ListView<Item>("items", itemsModel) { ... }); } }
Client client = new Client(Protocol.HTTP); Form form = new Form(); form.add("foo", "bar"); form.add("abc", "123"); Response response = client.post("http://host/path/to/resource", form.getWebRepresentation()) if (response.getStatus().isError()) { // deal with the error return; } if (response.isEntityAvailable()) { System.out.println(response.getEntity().getText()); }
ClientResource resource = new ClientResource(yourUrl); Form headers = (Form)resource.getRequestAttributes().get("org.restlet.http.headers"); if (headers == null) { headers = new Form(); resource.getRequestAttributes().put("org.restlet.http.headers", headers); } headers.add("yourHeaderName", yourHeaderValue); resource.get(); Response response = resource.getResponse(); String text = response.getEntity().getText(); String status = response.getStatus().toString();
add(label); Form form = new Form("form"); form.add(new AjaxTimerFormSubmitBehavior(form, Duration.seconds(10)) {
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Test", new BoxLayout(BoxLayout.Y_AXIS)); Font font = new Button("Test").getUnselectedStyle().getFont(); Image t = pictures.getImage("Play.png").scaled(font.getHeight(), font.getHeight()); hi.add(b(Button.LEFT, " Left 123", t)) .add(b(Button.RIGHT, " Right ", t)) .add(b(Button.TOP, " Top ", t)) .add(b(Button.BOTTOM, " Bottom ", t)); hi.add(b(Button.LEFT, " Left ", t)) .add(b(Button.RIGHT, " Right ", t)) .add(b(Button.TOP, " Top ", t)) .add(b(Button.BOTTOM, " Bottom ", t)); hi.show(); } private Button b(int pos, String txt, Image t) { Button btn = new Button(txt, t); btn.setTextPosition(pos); return btn; }
Form hi = new Form("ShareButton"); ShareButton sb = new ShareButton(); sb.setText("Share Screenshot"); hi.add(sb); Image screenshot = Image.createImage(hi.getWidth(), hi.getHeight()); hi.revalidate(); hi.setVisible(true); hi.paintComponent(screenshot.getGraphics(), true); String imageFile = FileSystemStorage.getInstance().getAppHomePath() + "screenshot.png"; try { OutputStream os = FileSystemStorage.getInstance().openOutputStream(imageFile); ImageIO.getImageIO().save(screenshot, os, ImageIO.FORMAT_PNG, 1); Util.cleanup(os); } catch(IOException err) { Log.e(err); }
Form hi = new Form("ShareButton"); ShareButton sb = new ShareButton(); sb.setText("Share Screenshot"); hi.add(sb); Image screenshot = Image.createImage(hi.getWidth(), hi.getHeight()); hi.revalidate(); hi.setVisible(true); hi.paintComponent(screenshot.getGraphics(), true); String imageFile = FileSystemStorage.getInstance().getAppHomePath() + "screenshot.png"; try(OutputStream os = FileSystemStorage.getInstance().openOutputStream(imageFile)) { ImageIO.getImageIO().save(screenshot, os, ImageIO.FORMAT_PNG, 1); } catch(IOException err) { Log.e(err); } sb.setImageToShare(imageFile, "image/png");
checkBoxForm.add(checkBx, changeableTxt);