1
22
23 package com.liferay.portal.servlet;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.servlet.StringServletResponse;
28 import com.liferay.portal.kernel.servlet.UncommittedServletResponse;
29 import com.liferay.portal.kernel.util.ContentTypes;
30 import com.liferay.portal.kernel.util.GetterUtil;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.kernel.util.StringUtil;
33 import com.liferay.portal.model.User;
34 import com.liferay.portal.security.auth.PrincipalThreadLocal;
35 import com.liferay.portal.security.permission.PermissionChecker;
36 import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
37 import com.liferay.portal.security.permission.PermissionThreadLocal;
38 import com.liferay.portal.service.UserLocalServiceUtil;
39 import com.liferay.util.servlet.ServletResponseUtil;
40 import com.liferay.util.xml.XMLFormatter;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44
45
50 public class AxisServlet extends org.apache.axis.transport.http.AxisServlet {
51
52 public void service(
53 HttpServletRequest request, HttpServletResponse response) {
54
55 try {
56 String remoteUser = request.getRemoteUser();
57
58 if (_log.isDebugEnabled()) {
59 _log.debug("Remote user " + remoteUser);
60 }
61
62 if (remoteUser != null) {
63 PrincipalThreadLocal.setName(remoteUser);
64
65 long userId = GetterUtil.getLong(remoteUser);
66
67 User user = UserLocalServiceUtil.getUserById(userId);
68
69 PermissionChecker permissionChecker =
70 PermissionCheckerFactoryUtil.create(user, true);
71
72 PermissionThreadLocal.setPermissionChecker(permissionChecker);
73 }
74
75 StringServletResponse stringResponse = new StringServletResponse(
76 response);
77
78 super.service(request, stringResponse);
79
80 String contentType = stringResponse.getContentType();
81
82 response.setContentType(contentType);
83
84 String content = stringResponse.getString();
85
86 if (contentType.contains(ContentTypes.TEXT_XML)) {
87 content = fixXml(content);
88 }
89
90 ServletResponseUtil.write(
91 new UncommittedServletResponse(response),
92 content.getBytes(StringPool.UTF8));
93 }
94 catch (Exception e) {
95 _log.error(e, e);
96 }
97 }
98
99 protected String fixXml(String xml) throws Exception {
100 if (xml.indexOf("<wsdl:definitions") == -1) {
101 return xml;
102 }
103
104 xml = StringUtil.replace(
105 xml,
106 new String[] {
107 "\r\n",
108 "\n",
109 " ",
110 "> <",
111 _INCORRECT_LONG_ARRAY,
112 _INCORRECT_STRING_ARRAY
113 },
114 new String[] {
115 StringPool.BLANK,
116 StringPool.BLANK,
117 StringPool.BLANK,
118 "><",
119 _CORRECT_LONG_ARRAY,
120 _CORRECT_STRING_ARRAY
121 });
122
123 xml = XMLFormatter.toString(xml);
124
125 return xml;
126 }
127
128 private static final String _INCORRECT_LONG_ARRAY =
129 "<complexType name=\"ArrayOf_xsd_long\"><simpleContent><extension/>" +
130 "</simpleContent></complexType>";
131
132 private static final String _CORRECT_LONG_ARRAY =
133 "<complexType name=\"ArrayOf_xsd_long\"><complexContent>" +
134 "<restriction base=\"soapenc:Array\"><attribute ref=\"soapenc:" +
135 "arrayType\" wsdl:arrayType=\"soapenc:long[]\"/>" +
136 "</restriction></complexContent></complexType>";
137
138 private static final String _INCORRECT_STRING_ARRAY =
139 "<complexType name=\"ArrayOf_xsd_string\"><simpleContent><extension/>" +
140 "</simpleContent></complexType>";
141
142 private static final String _CORRECT_STRING_ARRAY =
143 "<complexType name=\"ArrayOf_xsd_string\"><complexContent>" +
144 "<restriction base=\"soapenc:Array\"><attribute ref=\"soapenc:" +
145 "arrayType\" wsdl:arrayType=\"soapenc:string[]\"/>" +
146 "</restriction></complexContent></complexType>";
147
148 private static Log _log = LogFactoryUtil.getLog(AxisServlet.class);
149
150 }