Last active
August 29, 2015 14:05
-
-
Save 9SQ/717ac76b71d032455cee to your computer and use it in GitHub Desktop.
Yo APIからのcallbackでコマンド等を実行
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.PrintWriter; | |
import javax.servlet.ServletException; | |
import javax.servlet.annotation.WebServlet; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
@WebServlet("/callback") | |
public class Callback extends HttpServlet { | |
private static final long serialVersionUID = 1L; | |
public Callback() { | |
super(); | |
} | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
PrintWriter out = response.getWriter(); | |
String username = request.getParameter("username"); | |
response.setContentType("text/html;charset=UTF8"); | |
if (username != null && !username.isEmpty()) { | |
try { | |
Runtime runtime = Runtime.getRuntime(); | |
runtime.exec("/path/to/command " + username); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
response.setStatus(HttpServletResponse.SC_OK); | |
out.println("ok"); | |
} else { | |
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad Request (username not set)"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment