public interface ExcelService {
List<JsonObject> getExcelInformation (String ExcelData);
}
@Component(service=ExcelService.class)
public class ExcelServiceImpl implements ExcelService{
@Reference
ResourceResolverFactory resourceResolverFactory;
@Override
public List<JsonObject> getExcelInformation(String ExcelData) {
Map<String, Object> map = new HashMap<>();
map.put(ResourceResolverFactory.SUBSERVICE, Constants.User.AEMSysUser);
InputStream inputstream=null;
try {
ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(map);
Session session = resourceResolver.adaptTo(Session.class);
if (session.itemExists("/content/dam/balic/C2ImportCalEventSample.csv")) {
Node getExcel = session.getNode("/content/dam/balic/C2ImportCalEventSample.csv");
Node rootnode=session.getRootNode();
if(getExcel!=null) {
inputstream=(InputStream) rootnode.getSession();
}
}
return (List<JsonObject>) inputstream;
}catch(Exception ex) {
ex.printStackTrace();
// TODO Auto-generated method stub
}
return null;
}
}
@Component(service = Servlet.class, property = {
Constants.SERVICE_DESCRIPTION + "=Get Excel Demo Servlet",
"sling.servlet.methods="+ HttpConstants.METHOD_POST,
"sling.servlet.methods="+ HttpConstants.METHOD_GET,
"sling.servlet.paths="+ "/bin/csvfile",
"sling.servlet.extension=" + "json" })
public class AddExeclInfo extends SlingAllMethodsServlet {
private static final String ExcelData = null;
@Reference
ExcelService excelService;
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter pr=response.getWriter();
List<JsonObject> getExcelInformation=excelService.getExcelInformation(ExcelData);
if(getExcelInformation.isEmpty()) {
pr.println(getExcelInformation);
}else {
pr.println("something went wrong");
}
}
}
This is what i am trying to get my Excel data but
Resource at '/bin/csvfile' not found: No resource found (404)
The requested URL /bin/csvfile resulted in an error in org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet.
Request Progress:
0 TIMER_START{Request Processing} 1 COMMENT timer_end format is
{<elapsed microseconds>,<timer name>} <optional message> 7 LOG Method=GET,
PathInfo=null 7 TIMER_START{handleSecurity} 3487 TIMER_END{3478,handleSecurity}
authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@4426f55c returns
true 3895 TIMER_START{ResourceResolution} 4233 TIMER_END{337,ResourceResolution}
URI=/bin/csvfile resolves to Resource=NonExistingResource, path=/bin/csvfile 4238
LOG Resource Path Info: SlingRequestPathInfo: path='/bin/csvfile', selectorString='null',
extension='null', suffix='null' 4238 TIMER_START{ServletResolution} 4241
TIMER_START{resolveServlet(/bin/csvfile)} 5226 LOG {0}: no servlet found 5233
TIMER_END{990,resolveServlet(/bin/csvfile)} Using
servlet org.apache.sling.servlets.get.DefaultGetServlet 5237
TIMER_END{998,ServletResolution} URI=/bin/csvfile handled by
Servlet=org.apache.sling.servlets.get.DefaultGetServlet 5240 LOG Applying Requestfilters