Back to project page droidBBpush.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project droidBBpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.arg3.examples.push.api; /*from w w w . jav a 2 s. c o m*/ import com.arg3.examples.push.dao.DeviceDAO; import com.arg3.examples.push.enums.DeviceType; import com.arg3.examples.push.model.Device; import org.json.simple.JSONObject; import java.io.IOException; import java.sql.SQLException; import javax.inject.Inject; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Created by c0der78 on 2014-09-19. * Test with curl: * curl -d "type=Blackberry&token=1233k3k3lkl12kmn23kn" http://localhost:1337/api/register */ public class RegisterDeviceServlet extends BaseAPIServlet { @Inject DeviceDAO deviceDAO; @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String deviceType = req.getParameter("type"); String token = req.getParameter("token"); if (deviceType == null || deviceType.trim().isEmpty()) { sendErrorResponse(resp, "No type specified"); return; } if (token == null || token.trim().isEmpty()) { sendErrorResponse(resp, "No token specified"); return; } DeviceType type = DeviceType.get(deviceType); if (type == null) { sendErrorResponse(resp, "Device type invalid"); return; } try { Device device = deviceDAO.findByTypeAndToken(type, token); if (device == null) { device = new Device(); device.setType(type); device.setToken(token); deviceDAO.save(device); } JSONObject obj = new JSONObject(); obj.put("deviceId", device.getId()); sendJSONResponse(resp, obj); } catch (SQLException e) { e.printStackTrace(); sendErrorResponse(resp, e); } } }