All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mvnsearch.boot.xtermjs.XtermRSocketController Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package org.mvnsearch.boot.xtermjs;

import org.intellij.lang.annotations.Language;
import org.intellij.lang.annotations.Subst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import reactor.core.publisher.Flux;

import java.io.File;

/**
 * xterm rsocket controller
 *
 * @author linux_china
 */
@Controller
public class XtermRSocketController extends XtermCommandHandler {

	@Autowired
	private Environment environment;

	@MessageMapping("xterm.shell")
	public Flux shell(Flux commands, RSocketRequester rsocketRequester) {
		MutableContext mutableContext = new MutableContext();
		mutableContext.put("path", new File(System.getProperty("user.home", ".")).getAbsolutePath());
		return commands.filter(data -> !data.trim().isEmpty()).flatMap(this::executeCommand)
				.subscriberContext(mutableContext::putAll);
	}

	@GetMapping(value = "/xterm", produces = "text/html; charset=utf-8")
	@ResponseBody()
	public String xterm() {
		@Subst("/rsocket")
		String path = environment.getProperty("spring.rsocket.server.mapping-path");
		@Subst("app-name")
		String appName = environment.getProperty("spring.application.name");
		@Language("HTML")
		String html = "\n" + "\n" + "\n" + "    \n"
				+ "    Xterm for " + appName + "\n" + "    \n" + "\n" + "\n"
				+ "\n"
				+ "\n" + "";
		return html;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy