use of org.apache.pulsar.broker.web.plugin.servlet.AdditionalServlet in project pulsar by yahoo.
the class PulsarService method addBrokerAdditionalServlets.
private void addBrokerAdditionalServlets(WebService webService, Map<String, Object> attributeMap, ServiceConfiguration config) {
if (this.getBrokerAdditionalServlets() != null) {
Collection<AdditionalServletWithClassLoader> additionalServletCollection = this.getBrokerAdditionalServlets().getServlets().values();
for (AdditionalServletWithClassLoader servletWithClassLoader : additionalServletCollection) {
servletWithClassLoader.loadConfig(config);
AdditionalServlet additionalServlet = servletWithClassLoader.getServlet();
if (additionalServlet instanceof AdditionalServletWithPulsarService) {
((AdditionalServletWithPulsarService) additionalServlet).setPulsarService(this);
}
webService.addServlet(servletWithClassLoader.getBasePath(), servletWithClassLoader.getServletHolder(), config.isAuthenticationEnabled(), attributeMap);
LOG.info("Broker add additional servlet basePath {} ", servletWithClassLoader.getBasePath());
}
}
}
use of org.apache.pulsar.broker.web.plugin.servlet.AdditionalServlet in project pulsar by yahoo.
the class ProxyAdditionalServletTest method mockAdditionalServlet.
private void mockAdditionalServlet() {
Servlet servlet = new Servlet() {
@Override
public void init(ServletConfig servletConfig) throws ServletException {
log.info("[init]");
}
@Override
public ServletConfig getServletConfig() {
log.info("[getServletConfig]");
return null;
}
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
log.info("[service] path: {}", ((Request) servletRequest).getOriginalURI());
String value = servletRequest.getParameterMap().get(QUERY_PARAM)[0];
ServletOutputStream servletOutputStream = servletResponse.getOutputStream();
servletResponse.setContentLength(value.getBytes().length);
servletOutputStream.write(value.getBytes());
servletOutputStream.flush();
}
@Override
public String getServletInfo() {
log.info("[getServletInfo]");
return null;
}
@Override
public void destroy() {
log.info("[destroy]");
}
};
AdditionalServlet proxyAdditionalServlet = Mockito.mock(AdditionalServlet.class);
Mockito.when(proxyAdditionalServlet.getBasePath()).thenReturn(BASE_PATH);
Mockito.when(proxyAdditionalServlet.getServletHolder()).thenReturn(new ServletHolder(servlet));
AdditionalServlets proxyAdditionalServlets = Mockito.mock(AdditionalServlets.class);
Map<String, AdditionalServletWithClassLoader> map = new HashMap<>();
map.put("prometheus-proxy-servlet", new AdditionalServletWithClassLoader(proxyAdditionalServlet, null));
Mockito.when(proxyAdditionalServlets.getServlets()).thenReturn(map);
Mockito.when(proxyService.getProxyAdditionalServlets()).thenReturn(proxyAdditionalServlets);
}
use of org.apache.pulsar.broker.web.plugin.servlet.AdditionalServlet in project pulsar by yahoo.
the class BrokerAdditionalServletTest method mockAdditionalServlet.
private void mockAdditionalServlet(PulsarService pulsar) {
Servlet servlet = new OrdinaryServlet();
AdditionalServlet brokerAdditionalServlet = Mockito.mock(AdditionalServlet.class);
Mockito.when(brokerAdditionalServlet.getBasePath()).thenReturn(BASE_PATH);
Mockito.when(brokerAdditionalServlet.getServletHolder()).thenReturn(new ServletHolder(servlet));
AdditionalServletWithPulsarService brokerAdditionalServletWithPulsarService = new AdditionalServletWithPulsarService() {
private PulsarService pulsarService;
@Override
public void setPulsarService(PulsarService pulsarService) {
this.pulsarService = pulsarService;
}
@Override
public void loadConfig(PulsarConfiguration pulsarConfiguration) {
// No-op
}
@Override
public String getBasePath() {
return WITH_PULSAR_SERVICE_BASE_PATH;
}
@Override
public ServletHolder getServletHolder() {
return new ServletHolder(new WithPulsarServiceServlet(pulsarService));
}
@Override
public void close() {
// No-op
}
};
AdditionalServlets brokerAdditionalServlets = Mockito.mock(AdditionalServlets.class);
Map<String, AdditionalServletWithClassLoader> map = new HashMap<>();
map.put("broker-additional-servlet", new AdditionalServletWithClassLoader(brokerAdditionalServlet, null));
map.put("broker-additional-servlet-with-pulsar-service", new AdditionalServletWithClassLoader(brokerAdditionalServletWithPulsarService, null));
Mockito.when(brokerAdditionalServlets.getServlets()).thenReturn(map);
Mockito.when(pulsar.getBrokerAdditionalServlets()).thenReturn(brokerAdditionalServlets);
}
use of org.apache.pulsar.broker.web.plugin.servlet.AdditionalServlet in project incubator-pulsar by apache.
the class ProxyAdditionalServletTest method mockAdditionalServlet.
private void mockAdditionalServlet() {
Servlet servlet = new Servlet() {
@Override
public void init(ServletConfig servletConfig) throws ServletException {
log.info("[init]");
}
@Override
public ServletConfig getServletConfig() {
log.info("[getServletConfig]");
return null;
}
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
log.info("[service] path: {}", ((Request) servletRequest).getOriginalURI());
String value = servletRequest.getParameterMap().get(QUERY_PARAM)[0];
ServletOutputStream servletOutputStream = servletResponse.getOutputStream();
servletResponse.setContentLength(value.getBytes().length);
servletOutputStream.write(value.getBytes());
servletOutputStream.flush();
}
@Override
public String getServletInfo() {
log.info("[getServletInfo]");
return null;
}
@Override
public void destroy() {
log.info("[destroy]");
}
};
AdditionalServlet proxyAdditionalServlet = Mockito.mock(AdditionalServlet.class);
Mockito.when(proxyAdditionalServlet.getBasePath()).thenReturn(BASE_PATH);
Mockito.when(proxyAdditionalServlet.getServletHolder()).thenReturn(new ServletHolder(servlet));
AdditionalServlets proxyAdditionalServlets = Mockito.mock(AdditionalServlets.class);
Map<String, AdditionalServletWithClassLoader> map = new HashMap<>();
map.put("prometheus-proxy-servlet", new AdditionalServletWithClassLoader(proxyAdditionalServlet, null));
Mockito.when(proxyAdditionalServlets.getServlets()).thenReturn(map);
Mockito.when(proxyService.getProxyAdditionalServlets()).thenReturn(proxyAdditionalServlets);
}
use of org.apache.pulsar.broker.web.plugin.servlet.AdditionalServlet in project incubator-pulsar by apache.
the class PulsarService method addBrokerAdditionalServlets.
private void addBrokerAdditionalServlets(WebService webService, Map<String, Object> attributeMap, ServiceConfiguration config) {
if (this.getBrokerAdditionalServlets() != null) {
Collection<AdditionalServletWithClassLoader> additionalServletCollection = this.getBrokerAdditionalServlets().getServlets().values();
for (AdditionalServletWithClassLoader servletWithClassLoader : additionalServletCollection) {
servletWithClassLoader.loadConfig(config);
AdditionalServlet additionalServlet = servletWithClassLoader.getServlet();
if (additionalServlet instanceof AdditionalServletWithPulsarService) {
((AdditionalServletWithPulsarService) additionalServlet).setPulsarService(this);
}
webService.addServlet(servletWithClassLoader.getBasePath(), servletWithClassLoader.getServletHolder(), config.isAuthenticationEnabled(), attributeMap);
LOG.info("Broker add additional servlet basePath {} ", servletWithClassLoader.getBasePath());
}
}
}
Aggregations