public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, SAXException, VerifierConfigurationException { String method = request.getMethod(); String requestUri = request.getRequestURI(); StringBuffer requestUrl = request.getRequestURL(); String head = requestUrl.substring(0, requestUrl.indexOf(requestUri)); try { if ("POST".equals(method)) { throw new XcapException(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } Map<String, String> context = getXpointer(request); XcapUri xcapUri = new XcapUri(requestUri, _rootName); XcapResourceImpl resource = getResource(xcapUri, PUT.equals(method), head, context); ifMatchConditionalProcessing(request, resource); ifNoneMatchConditionalProcessing(request, resource); resource.setAction(method); if (method.equals(GET)) doGet(response, resource); else if (method.equals(PUT)) doPut(request, resource); else if (method.equals(DELETE)) doDelete(request, resource); if (method.equals(PUT) || method.equals(DELETE)) { checkIfSameNodeSelected(resource); resource.getProcessor().processResource(resource); _dao.save(resource); notifyResourceChanged(resource); } String newEtag = getEtag(resource); resource.setNewEtag(newEtag); response.setHeader(Constants.ETAG, newEtag); response.setStatus(HttpServletResponse.SC_OK); if (_log.isDebugEnabled()) _log.debug(method + " " + requestUri + " sucessful"); } catch (XcapException e) { if (e.shouldShowStackTrace()) _log.info("Unable to process " + method + " " + requestUri, e); else _log.info("Unable to process " + method + " " + requestUri + ": " + e.getMessage()); e.sendResponse(response); } }
private void initXcapCaps() throws XcapException, IOException { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\"?>\n"); sb.append("<xcap-caps xmlns=\"urn:ietf:params:xml:ns:xcap-caps\"\n"); sb.append(" xmlns:xsi=\"htt//www.w3.org/2001/XMLSchema-instance\"\n"); sb.append(" xsi:schemaLocation=\"urn:ietf:params:xml:ns:xcap-caps xcap-caps.xsd\">\n"); sb.append("<auids>\n"); for (XcapResourceProcessor processor : _processors.values()) sb.append("\t<auid>").append(processor.getAuid()).append("</auid>\n"); sb.append("</auids>\n"); sb.append("<namespaces>\n"); for (XcapResourceProcessor processor : _processors.values()) { for (String namespace : processor.getNamespaceContext().values()) sb.append("\t<namespace>").append(namespace).append("</namespace>\n"); } sb.append("</namespaces>\n"); sb.append("</xcap-caps>"); XcapResourceImpl resource = getResource(new XcapUri("xcap-caps/global/index", ""), true, "", null); _dao.update(resource, sb.toString()); _dao.save(resource); }