AEM学习:System Console ConfigMgr(七)

一,Service

Add interface 

public interface XicoService {
    public String getData();
}

Add Class

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Activate;

import java.util.Map;

@Component(immediate=true, label="Xico Service", description="This is a Service", metatype=true)
@Service
public class XicoServiceImpl implements XicoService {


    @Property(value="http://companyservices/myservice?wsdl")
    static final String SERVICE_ENDPOINT_URL = "service.endpoint.url";

    private String serviceEndpointUrl;

    @Activate
    public void activate(final Map<String, Object> props) {
        this.serviceEndpointUrl = (String)props.get(SERVICE_ENDPOINT_URL);
    }


    @Override
    public String getData() {
        return serviceEndpointUrl;
    }
}

  二,查看效果

http://localhost:4502/system/console/services

 

http://localhost:4502/system/console/configMgr

 

三,获取数据

import org.apache.felix.scr.annotations.*;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;


@Component(immediate = true)
@Service(value = Servlet.class)
@Properties({
        @Property(name = "service.description", value = { "Generating Page Servlet" }),
        @Property(name = "sling.servlet.paths", value = {"/libs/sling/generating/page"}),
        @Property(name = "sling.servlet.methods", value = { HttpConstants.METHOD_GET }) })
public class GeneratingPageServlet extends SlingAllMethodsServlet {

    
    @Reference(policyOption = ReferencePolicyOption.GREEDY) private XicoService xicoService;

    @Override
    protected void doGet(final SlingHttpServletRequest req,
             final SlingHttpServletResponse resp) throws ServletException, IOException {
        try {
            resp.getOutputStream().println(   "error!!" + xicoService.getData());
        } catch (IOException e) {
            resp.getOutputStream().println(   "error!!");
        }
    }
}

http://localhost:4502/libs/sling/generating/page

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值