1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class SharepointWebServicesServlet extends HttpServlet {
41  
42      protected void doPost(
43          HttpServletRequest request, HttpServletResponse response) {
44  
45          try {
46              String uri = request.getRequestURI();
47  
48              if (uri.equals("/_vti_bin/webs.asmx")) {
49                  vtiBinWebsAsmx(request, response);
50              }
51          }
52          catch (Exception e) {
53              _log.error(e, e);
54          }
55      }
56  
57      protected void vtiBinWebsAsmx(
58              HttpServletRequest request, HttpServletResponse response)
59          throws Exception {
60  
61          StringBuilder sb = new StringBuilder();
62  
63          String url =
64              "http://" + request.getLocalAddr() + ":" + request.getServerPort() +
65                  "/sharepoint";
66  
67          sb.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"");
68          sb.append("http://schemas.xmlsoap.org/soap/envelope/\">");
69          sb.append("<SOAP-ENV:Header/>");
70          sb.append("<SOAP-ENV:Body>");
71          sb.append("<WebUrlFromPageUrlResponse xmlns=\"");
72          sb.append("http://schemas.microsoft.com/sharepoint/soap/\">");
73          sb.append("<WebUrlFromPageUrlResult>");
74          sb.append(url);
75          sb.append("</WebUrlFromPageUrlResult>");
76          sb.append("</WebUrlFromPageUrlResponse>");
77          sb.append("</SOAP-ENV:Body>");
78          sb.append("</SOAP-ENV:Envelope>");
79  
80          response.setContentType(ContentTypes.TEXT_XML_UTF8);
81  
82          ServletResponseUtil.write(response, sb.toString());
83      }
84  
85      private static Log _log = LogFactoryUtil.getLog(SharepointServlet.class);
86  
87  }