001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.sharepoint;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.servlet.ServletResponseUtil;
020    import com.liferay.portal.kernel.util.ContentTypes;
021    import com.liferay.portal.kernel.util.StringBundler;
022    
023    import javax.servlet.http.HttpServlet;
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.http.HttpServletResponse;
026    
027    /**
028     * @author Bruno Farache
029     */
030    public class SharepointWebServicesServlet extends HttpServlet {
031    
032            @Override
033            protected void doPost(
034                    HttpServletRequest request, HttpServletResponse response) {
035    
036                    try {
037                            String uri = request.getRequestURI();
038    
039                            if (uri.equals("/_vti_bin/webs.asmx")) {
040                                    vtiBinWebsAsmx(request, response);
041                            }
042                    }
043                    catch (Exception e) {
044                            _log.error(e, e);
045                    }
046            }
047    
048            protected void vtiBinWebsAsmx(
049                            HttpServletRequest request, HttpServletResponse response)
050                    throws Exception {
051    
052                    StringBundler sb = new StringBundler(12);
053    
054                    String url =
055                            "http://" + request.getLocalAddr() + ":" + request.getServerPort() +
056                                    "/sharepoint";
057    
058                    sb.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"");
059                    sb.append("http://schemas.xmlsoap.org/soap/envelope/\">");
060                    sb.append("<SOAP-ENV:Header/>");
061                    sb.append("<SOAP-ENV:Body>");
062                    sb.append("<WebUrlFromPageUrlResponse xmlns=\"");
063                    sb.append("http://schemas.microsoft.com/sharepoint/soap/\">");
064                    sb.append("<WebUrlFromPageUrlResult>");
065                    sb.append(url);
066                    sb.append("</WebUrlFromPageUrlResult>");
067                    sb.append("</WebUrlFromPageUrlResponse>");
068                    sb.append("</SOAP-ENV:Body>");
069                    sb.append("</SOAP-ENV:Envelope>");
070    
071                    response.setContentType(ContentTypes.TEXT_XML_UTF8);
072    
073                    ServletResponseUtil.write(response, sb.toString());
074            }
075    
076            private static Log _log = LogFactoryUtil.getLog(SharepointServlet.class);
077    
078    }