Skip to content

Instantly share code, notes, and snippets.

@9SQ 9SQ/Callback.java
Last active Aug 29, 2015

Embed
What would you like to do?
Yo APIからのcallbackでコマンド等を実行
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
You can’t perform that action at this time.