📄 buffaloserviceexporter.java
字号:
/*
* Copyright 2002-2004 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.buffalo.spring;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.buffalo.server.Buffalo;
import net.buffalo.server.BuffaloService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.support.WebContentGenerator;
import com.caucho.burlap.io.BurlapInput;
import com.caucho.burlap.io.BurlapOutput;
import com.caucho.burlap.server.BurlapSkeleton;
/**
* This is a wrap for the buffalo service.
* The changes is for javascript client use, since the old serialized xml
* string is not a valid xml content.
*
* @deprecated
* @author michael
* @since 1.1
*/
public class BuffaloServiceExporter implements Controller, InitializingBean {
private Map services;
/**
* @return Returns the services.
*/
public Map getServices() {
return services;
}
/**
* @param services The services to set.
*/
public void setServices(Map services) {
this.services = services;
}
public void afterPropertiesSet() throws Exception {
String key;
Object value;
for(Iterator it = services.keySet().iterator(); it.hasNext();) {
key = (String)it.next();
value = services.get(key);
services.put(key, value);
}
}
/**
* Process the incoming buffalo request and create a Buffalo response.
*/
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (!WebContentGenerator.METHOD_POST.equals(request.getMethod())) {
throw new ServletException("BuffaloServiceExporter only supports POST requests");
}
String serviceName = request.getParameter(Buffalo.SERVICE_NAME_ID);
Object service = services.get(serviceName);
if (service == null) throw new IllegalArgumentException("Service cannot be null!");
if (service instanceof BuffaloService) {
((BuffaloService) service).init(request.getSession().getServletContext(), request);
}
BurlapSkeleton skeleton = new BurlapSkeleton(service);
BurlapInput in = new BurlapInput(request.getInputStream());
BurlapOutput out = new BurlapOutput(response.getOutputStream()) {
public void startReply() throws IOException {
print("<?xml version=\"1.0\" encoding=\"utf-8\"?><burlap:reply xmlns:burlap=\"http://www.buffalo.net/burlap/\">");
}
};
try {
skeleton.invoke(in, out);
return null;
} catch (Exception ex) {
throw ex;
} catch (Error ex) {
throw ex;
} catch (Throwable ex) {
// Should never happen: There are no Throwables other than Exceptions and Errors.
throw new ServletException(ex);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -