1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.sharepoint;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.util.ContentTypes;
28  import com.liferay.util.servlet.ServletResponseUtil;
29  
30  import javax.servlet.http.HttpServlet;
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  
34  /**
35   * <a href="SharepointWebServicesServlet.java.html"><b><i>View Source</i></b>
36   * </a>
37   *
38   * @author Bruno Farache
39   *
40   */
41  public class SharepointWebServicesServlet extends HttpServlet {
42  
43      protected void doPost(
44          HttpServletRequest request, HttpServletResponse response) {
45  
46          try {
47              String uri = request.getRequestURI();
48  
49              if (uri.equals("/_vti_bin/webs.asmx")) {
50                  vtiBinWebsAsmx(request, response);
51              }
52          }
53          catch (Exception e) {
54              _log.error(e, e);
55          }
56      }
57  
58      protected void vtiBinWebsAsmx(
59              HttpServletRequest request, HttpServletResponse response)
60          throws Exception {
61  
62          StringBuilder sb = new StringBuilder();
63  
64          String url =
65              "http://" + request.getLocalAddr() + ":" + request.getServerPort() +
66                  "/sharepoint";
67  
68          sb.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"");
69          sb.append("http://schemas.xmlsoap.org/soap/envelope/\">");
70          sb.append("<SOAP-ENV:Header/>");
71          sb.append("<SOAP-ENV:Body>");
72          sb.append("<WebUrlFromPageUrlResponse xmlns=\"");
73          sb.append("http://schemas.microsoft.com/sharepoint/soap/\">");
74          sb.append("<WebUrlFromPageUrlResult>");
75          sb.append(url);
76          sb.append("</WebUrlFromPageUrlResult>");
77          sb.append("</WebUrlFromPageUrlResponse>");
78          sb.append("</SOAP-ENV:Body>");
79          sb.append("</SOAP-ENV:Envelope>");
80  
81          response.setContentType(ContentTypes.TEXT_XML_UTF8);
82  
83          ServletResponseUtil.write(response, sb.toString());
84      }
85  
86      private static Log _log = LogFactoryUtil.getLog(SharepointServlet.class);
87  
88  }