1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.sharepoint;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.ContentTypes;
20  import com.liferay.portal.kernel.util.StringBundler;
21  import com.liferay.util.servlet.ServletResponseUtil;
22  
23  import javax.servlet.http.HttpServlet;
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  
27  /**
28   * <a href="SharepointWebServicesServlet.java.html"><b><i>View Source</i></b>
29   * </a>
30   *
31   * @author Bruno Farache
32   */
33  public class SharepointWebServicesServlet extends HttpServlet {
34  
35      protected void doPost(
36          HttpServletRequest request, HttpServletResponse response) {
37  
38          try {
39              String uri = request.getRequestURI();
40  
41              if (uri.equals("/_vti_bin/webs.asmx")) {
42                  vtiBinWebsAsmx(request, response);
43              }
44          }
45          catch (Exception e) {
46              _log.error(e, e);
47          }
48      }
49  
50      protected void vtiBinWebsAsmx(
51              HttpServletRequest request, HttpServletResponse response)
52          throws Exception {
53  
54          StringBundler sb = new StringBundler(12);
55  
56          String url =
57              "http://" + request.getLocalAddr() + ":" + request.getServerPort() +
58                  "/sharepoint";
59  
60          sb.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"");
61          sb.append("http://schemas.xmlsoap.org/soap/envelope/\">");
62          sb.append("<SOAP-ENV:Header/>");
63          sb.append("<SOAP-ENV:Body>");
64          sb.append("<WebUrlFromPageUrlResponse xmlns=\"");
65          sb.append("http://schemas.microsoft.com/sharepoint/soap/\">");
66          sb.append("<WebUrlFromPageUrlResult>");
67          sb.append(url);
68          sb.append("</WebUrlFromPageUrlResult>");
69          sb.append("</WebUrlFromPageUrlResponse>");
70          sb.append("</SOAP-ENV:Body>");
71          sb.append("</SOAP-ENV:Envelope>");
72  
73          response.setContentType(ContentTypes.TEXT_XML_UTF8);
74  
75          ServletResponseUtil.write(response, sb.toString());
76      }
77  
78      private static Log _log = LogFactoryUtil.getLog(SharepointServlet.class);
79  
80  }