001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }