public static void main(String[] args) throws Exception { RESTClient client = new RESTClient(); client.registerClientApplication(); client.createUserAccount(); client.reserveTable(); }
public RESTClient() { this(getPort()); }
public static void main(String[] args) throws Exception { RESTClient client = new RESTClient(); // Post XOP with CXF JAX-RS WebClient client.useXopAttachmentServiceWithWebClient(); // Post XOP with CXF JAX-RS Proxy client.useXopAttachmentServiceWithProxy(); // Post Book attachments in XML and JSON formats with CXF JAX-RS WebClient client.useAttachmentServiceWithWebClient(); // Post Book attachments in XML and JSON formats with CXF JAX-RS Proxy client.useAttachmentServiceWithProxy(); }
public static void main(String[] args) throws Exception { RESTClient client = new RESTClient(); // uses CXF JAX-RS WebClient client.usePersonService(); // uses a basic proxy client.useSimpleProxy(); // uses CXF JAX-RS WebClient to do the advanced search client.useSearchService(); }
public static void main(String args[]) throws Exception { RESTClient client = new RESTClient(); client.useOldRESTService(); System.out.println(); client.useOldRESTServiceWithNewClient(); System.out.println(); client.useOldRESTServiceWithNewClientAndXPath(); System.out.println(); client.useNewRESTService("http://localhost:" + RESTClient.getPort() + "/examples/direct/new-rest"); System.out.println(); client.useNewRESTServiceWithOldClient(); System.out.println(); client.useNewRESTServiceWithOldClientAndRedirection(); System.out.println(); client.useNewRESTService("http://localhost:" + RESTClient.getPort() + "/examples/new/rest-endpoint");
public static void main(String[] args) throws Exception { RESTClient client = new RESTClient(); // uses CXF JAX-RS Proxy client.sayHelloRest(); System.out.println(); // uses JAX-WS Client client.sayHelloSoap(); }
rest = new RESTClient("http://translate.google.com/translate_a/t"); rest.header("User-Agent", UA_LIST[new Random().nextInt(UA_LIST.length)]); rest.data("client", "j"); //t = TEXT rest.data("ie", "UTF-8"); rest.data("oe", "UTF-8"); rest.data("hl", params[0].getString("hl")); //, Locale.getDefault().getLanguage())); rest.data("sl", params[0].getString("sl")); rest.data("tl", params[0].getString("tl")); rest.data("q", params[0].getString("text")); json = rest.execute(); if (rest != null) rest.shutdown();
public static void main(String[] args) throws Exception { int port = args.length == 2 && "http.port".equals(args[0]) ? Integer.valueOf(args[1]) : 8080; System.out.println("Using CXF JAX-RS proxy to invoke on HelloWorld service"); RESTClient client = new RESTClient(port); client.sayHelloAsAdmin(); client.sayHelloAsUser(); } }
public static void main(String[] args) throws Exception { new RESTClient().run(); System.out.println("\n"); System.exit(0); }
BoxResourceHub hub = new BoxResourceHub(); BoxJSONParser parser = new BoxJSONParser(hub); this.client = new BoxClient(key, clientSecret, hub, parser, new RESTClient(), new BoxConfigBuilder().build());
public void reserveTable() throws Exception { WebClient rs = createClient("http://localhost:" + port + "/services/reservations/reserve/table", "barry@restaurant.com", "5678"); Response r = rs.form(new Form().param("name", "Barry") System.out.println("OAuth flow is broken"); WebClient authorizeClient = createClient(locationHeader.toString(), "barry@social.com", "1234"); OAuthAuthorizationData data = authorizeClient.get(OAuthAuthorizationData.class); System.out.println(authenticityCookie); Form authorizationResult = getAuthorizationResult(data); authorizeClient.reset(); authorizeClient.to(data.getReplyTo(), false); WebClient finalClient = createClient(locationHeader2.toString(), "barry@restaurant.com", "5678"); finalClient.accept("application/xml"); updateAndGetUserCalendar(7, "Dinner at " + confirm.getAddress()); } else { System.out.println("Reservation failed");
private void updateAndGetUserCalendar(int hour, String event) { WebClient client = createClient("http://localhost:" + port + "/services/social/accounts/calendar", "barry@social.com", "1234"); Form form = new Form().param("hour", Integer.toString(hour)).param("event", event); client.form(form); printUserCalendar(); }
public void sayHelloAsAdmin() throws Exception { HelloWorld service = createServiceProxy("jim", "jimspassword"); System.out.println("Using HelloServiceRest with admin priviliges"); System.out.println("Asking the service to add a new user and also say hi"); try { System.out.println(service.sayHi("Barry")); System.out.println(service.sayHiToUser(new UserImpl("Barry"))); } catch (WebApplicationException ex) { throw new RuntimeException("Should be able to sayHi", ex); } System.out.println("Getting the list of existing users"); try { Map<Integer, User> users = service.getUsers(); printUsers(users); } catch (WebApplicationException ex) { throw new RuntimeException("Admin should be able to invoke getUsers", ex); } }
private void useHelloService(HelloWorld service, String user) { System.out.println("Getting the list of existing users"); printUsers(service.getUsers()); System.out.println("Asking the service to add a new user " + user + " and also say hi"); System.out.println(service.sayHi(user)); System.out.println(service.sayHiToUser(new UserImpl(user))); System.out.println("Getting the list of existing users"); Map<Integer, User> users = service.getUsers(); printUsers(users); System.out.println("Echoing the list of existing users"); printUsers(service.echoUsers(users)); }
private void printUserCalendar() { WebClient client = createClient("http://localhost:" + port + "/services/social/accounts/calendar", "barry@social.com", "1234"); Calendar calendar = client.get(Calendar.class); System.out.println(calendar.toString()); }
public static void main(String[] args) throws Exception { RESTClient client = new RESTClient(); // uses CXF JAX-RS Proxy client.sayHelloRest(); System.out.println(); // uses JAX-WS Client client.sayHelloSoap(); }
public void reserveTable() throws Exception { WebClient rs = createClient("http://localhost:" + port + "/services/reservations/reserve/table", "barry@restaurant.com", "5678"); Response r = rs.form(new Form().param("name", "Barry") System.out.println("OAuth flow is broken"); WebClient authorizeClient = createClient(locationHeader.toString(), "barry@social.com", "1234"); OAuthAuthorizationData data = authorizeClient.get(OAuthAuthorizationData.class); Object authenticityCookie = authorizeClient.getResponse().getMetadata().getFirst("Set-Cookie"); Form authorizationResult = getAuthorizationResult(data); authorizeClient.reset(); authorizeClient.to(data.getReplyTo(), false); WebClient finalClient = createClient(locationHeader2.toString(), "barry@restaurant.com", "5678"); finalClient.accept("application/xml"); updateAndGetUserCalendar(7, "Dinner at " + confirm.getAddress()); } else { System.out.println("Reservation failed");
private void updateAndGetUserCalendar(int hour, String event) { WebClient client = createClient("http://localhost:" + port + "/services/social/accounts/calendar", "barry@social.com", "1234"); Form form = new Form().param("hour", Integer.toString(hour)).param("event", event); client.form(form); printUserCalendar(); }
public void sayHelloAsUser() throws Exception { HelloWorld service = createServiceProxy("bob", "bobspassword"); System.out.println("Using HelloServiceRest with user priviliges"); System.out.println("Getting the list of existing users"); try { Map<Integer, User> users = service.getUsers(); printUsers(users); throw new RuntimeException("Only admin should be able to invoke getUsers"); } catch (WebApplicationException ex) { Assert.assertEquals("403 response code is expected", 403, ex.getResponse().getStatus()); System.out.println("Access was denied for user bob"); } System.out.println("Asking the service to add a new user Barry and also say hi"); try { System.out.println(service.sayHi("Barry")); System.out.println(service.sayHiToUser(new UserImpl("Barry"))); } catch (WebApplicationException ex) { throw new RuntimeException("Should be able to sayHi"); } }
printUsers(service.getUsers()); if (!admin) { throw new RuntimeException("Only Admin can invoke getUsers"); printUsers(users); if (!admin) { throw new RuntimeException("Only Admin can invoke getUsers"); printUsers(service.echoUsers(users)); if (!admin) { throw new RuntimeException("Only Admin can invoke echoUsers");