createContext("/", new HttpHandler(){ @Override void handle(final HttpExchange exchange) throws IOException { // use getRequestURI() } });
return server.createContext("/customerservice/customer", new HttpHandler(...));
HttpHandler http = new HttpHandler(); String jsonSrc = http.makeServiceCall("https://api.wheretheiss.at/v1/satellites/25544"); JSONObject jsonObj = new JSONObject(jsonSrc); String value = jsonObj.getString("latitude");
HttpHandler httpHandler = new HttpHandler(); jsonStr = httpHandler.runHttpRequest(url_MAPS); try { JSONArray jsonArray = new JSONArray(jsonStr); // Getting JSON Array node // looping through for (int i = 0; i < jsonArray.length(); i++) { jsonObj = jsonArray.getJSONObject(i); String title = jsonObj.getString(TAG_TITLE); responseList.add(title); } } catch (JSONException e) { e.printStackTrace(); }
public class MainActivity extends Activity implements OnClickListener { private Button btnRequest; private EditText etResponse; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnRequest = (Button) findViewById(R.id.btnRequest); etResponse = (EditText) findViewById(R.id.etRespose); //check isConnected()...code is on github btnRequest.setOnClickListener(this); } @Override public void onClick(View v) { new HttpHandler() { @Override public HttpUriRequest getHttpRequestMethod() { return new HttpGet("http://hmkcode.com/examples/index.php"); // return new HttpPost(url) } @Override public void onResponse(String result) { Toast.makeText(getBaseContext(), "Received!", Toast.LENGTH_LONG).show(); etResponse.setText(result); } }.execute(); } // public boolean isConnected(){} }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); mDrawerList = (ListView)findViewById(android.R.id.list); mPublicProjectsList =(ListView)findViewById(R.id.list1); String[] projectItems = {"Project1", "Project2", "Project3", "Project4"}; mPublicProjectsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, projectItems); mPublicProjectsList.setAdapter(mPublicProjectsAdapter); e = (EditText)findViewById(R.id.email); p = (EditText)findViewById(R.id.password); s = (Button)findViewById(R.id.submit); s.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getEmail = e.getText().toString(); getPassword = p.getText().toString(); new HttpHandler().execute(); } }); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); mDrawerList = (ListView)findViewById(android.R.id.list);+ //setContentView(R.layout.activity_main); LayoutInflater layoutInflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View contentView = layoutInflater.inflate(R.layout.activity_main, null,false); mDrawerLayout.addView(contentView, 0); mPublicProjectsList =(ListView)contentView.findViewById(R.id.list1); String[] projectItems = {"Project1", "Project2", "Project3", "Project4"}; mPublicProjectsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, projectItems); mPublicProjectsList.setAdapter(mPublicProjectsAdapter); e = (EditText)findViewById(R.id.email); p = (EditText)findViewById(R.id.password); s = (Button)findViewById(R.id.submit); s.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getEmail = e.getText().toString(); getPassword = p.getText().toString(); new HttpHandler().execute(); } }); }
refresh_btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { HttpHandler httpHandler1 = new HttpHandler(); String res = null; try { Log.d("edwLog", TAG + " get_payment_notifications " + HttpHandler.API_URL + "get_payment_notifications/" + AuthToken + "/"); res = httpHandler1.makeServiceCall(HttpHandler.API_URL + "get_payment_notifications/" + AuthToken + "/", HttpHandler.GET); Log.d("edwLog", TAG + " response > " + res); if (res != null) { JSONObject jsonObject = new JSONObject(res); String responseType = jsonObject.getString("type"); if (responseType.equals("success")) { if (jsonObject.has("response")) { JSONArray jsonArray = jsonObject.getJSONArray("response"); for (int i = 0; i < jsonArray.length(); i++) { notifications.add(jsonArray.getJSONObject(i)); } } } } } catch (Exception e) { e.printStackTrace(); Log.d("edwLog", TAG + " IOException > " + e.toString()); } } });
Undertow server = Undertow.builder() .addHttpListener(80, "0.0.0.0") .setHandler(new HttpHandler() { @Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.getResponseSender().send("Hello World"); } }).build(); server.start();
HttpHandler jp = new HttpHandler(); String jsonstr = jp.makeServiceCall(url);
HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, new HttpHandler() {
private static String API_PACKAGE = "package where TestRESTService class"; public static final URI BASE_URI = UriBuilder .fromUri("http://localhost/") .port(8000) .build(); private static HttpServer initServer() throws IOException { System.out.println("Starting grizzly... " + BASE_URI); HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, new HttpHandler() { @Override public void service(Request rqst, Response rspns) throws Exception { rspns.sendError(404); } }); // Initialize and register Jersey Servlet WebappContext context = new WebappContext("GrizzlyContext", "/"); ServletRegistration registration = context.addServlet( ServletContainer.class.getName(), ServletContainer.class); registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS, PackagesResourceConfig.class.getName()); registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, API_PACKAGE); registration.addMapping("/*"); context.deploy(httpServer); return httpServer; }
import io.undertow.Undertow; import io.undertow.server.*; import io.undertow.server.handlers.BlockingHandler; import io.undertow.util.Headers; public class Under { public static void main(String[] args) { Undertow server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(new BlockingHandler(new HttpHandler() { public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.getResponseHeaders() .put(Headers.CONTENT_TYPE, "text/plain"); exchange.getResponseSender() .send("Hello World"); } })).build(); server.start(); } }
if (!isRootConfigured && wrapper.startsWith("*.")) { isRootConfigured = true; final HttpHandler a = new HttpHandler() {
if (!isRootConfigured && wrapper.startsWith("*.")) { isRootConfigured = true; final HttpHandler a = new HttpHandler() {
if (!isRootConfigured && wrapper.startsWith("*.")) { isRootConfigured = true; final HttpHandler a = new HttpHandler() {
if (!isRootConfigured && wrapper.startsWith("*.")) { isRootConfigured = true; final HttpHandler a = new HttpHandler() {
if (!isRootConfigured && wrapper.startsWith("*.")) { isRootConfigured = true; final HttpHandler a = new HttpHandler() {
import io.undertow.Undertow; import io.undertow.server.*; import io.undertow.util.Headers; public class Under { public static void main(String[] args) { Undertow server = Undertow.builder() .addListener(8080, "localhost") .setHandler(new HttpHandler() { public void handleRequest(HttpServerExchange exchange) throws Exception { if (exchange.isInIoThread()) { exchange.dispatch(this); return; } exchange.getResponseHeaders() .put(Headers.CONTENT_TYPE, "text/plain"); exchange.getResponseSender() .send("Hello World"); } }) .build(); server.start(); } }
String url = "http://myhost:8080/myURL"; URI uri = UriBuilder.fromUri(url).build(); HttpServer server = GrizzlyServerFactory.createHttpServer(uri, new HttpHandler() { @Override public void service(Request request, org.glassfish.grizzly.http.server.Response response) throws Exception {