001    /**
002     * Copyright (c) 2000-2010 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.util.ContentTypes;
020    import com.liferay.portal.kernel.util.StringBundler;
021    import com.liferay.util.servlet.ServletResponseUtil;
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            protected void doPost(
033                    HttpServletRequest request, HttpServletResponse response) {
034    
035                    try {
036                            String uri = request.getRequestURI();
037    
038                            if (uri.equals("/_vti_bin/webs.asmx")) {
039                                    vtiBinWebsAsmx(request, response);
040                            }
041                    }
042                    catch (Exception e) {
043                            _log.error(e, e);
044                    }
045            }
046    
047            protected void vtiBinWebsAsmx(
048                            HttpServletRequest request, HttpServletResponse response)
049                    throws Exception {
050    
051                    StringBundler sb = new StringBundler(12);
052    
053                    String url =
054                            "http://" + request.getLocalAddr() + ":" + request.getServerPort() +
055                                    "/sharepoint";
056    
057                    sb.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"");
058                    sb.append("http://schemas.xmlsoap.org/soap/envelope/\">");
059                    sb.append("<SOAP-ENV:Header/>");
060                    sb.append("<SOAP-ENV:Body>");
061                    sb.append("<WebUrlFromPageUrlResponse xmlns=\"");
062                    sb.append("http://schemas.microsoft.com/sharepoint/soap/\">");
063                    sb.append("<WebUrlFromPageUrlResult>");
064                    sb.append(url);
065                    sb.append("</WebUrlFromPageUrlResult>");
066                    sb.append("</WebUrlFromPageUrlResponse>");
067                    sb.append("</SOAP-ENV:Body>");
068                    sb.append("</SOAP-ENV:Envelope>");
069    
070                    response.setContentType(ContentTypes.TEXT_XML_UTF8);
071    
072                    ServletResponseUtil.write(response, sb.toString());
073            }
074    
075            private static Log _log = LogFactoryUtil.getLog(SharepointServlet.class);
076    
077    }