|
|
|
@ -7,6 +7,8 @@ import com.xxl.job.core.rpc.serialize.HessianSerializer;
|
|
|
|
|
import com.xxl.job.core.util.HttpClientUtil;
|
|
|
|
|
import org.eclipse.jetty.server.Request;
|
|
|
|
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
@ -19,17 +21,13 @@ import java.io.OutputStream;
|
|
|
|
|
* @author xuxueli 2015-11-19 22:32:36
|
|
|
|
|
*/
|
|
|
|
|
public class JettyServerHandler extends AbstractHandler {
|
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(JettyServerHandler.class);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
|
|
|
|
|
|
|
|
|
// deserialize request
|
|
|
|
|
byte[] requestBytes = HttpClientUtil.readBytes(request);
|
|
|
|
|
RpcRequest rpcRequest = (RpcRequest) HessianSerializer.deserialize(requestBytes, RpcRequest.class);
|
|
|
|
|
|
|
|
|
|
// invoke
|
|
|
|
|
RpcResponse rpcResponse = NetComServerFactory.invokeService(rpcRequest, null);
|
|
|
|
|
RpcResponse rpcResponse = doInvoke(request);
|
|
|
|
|
|
|
|
|
|
// serialize response
|
|
|
|
|
byte[] responseBytes = HessianSerializer.serialize(rpcResponse);
|
|
|
|
@ -44,4 +42,27 @@ public class JettyServerHandler extends AbstractHandler {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RpcResponse doInvoke(HttpServletRequest request) {
|
|
|
|
|
try {
|
|
|
|
|
// deserialize request
|
|
|
|
|
byte[] requestBytes = HttpClientUtil.readBytes(request);
|
|
|
|
|
if (requestBytes == null || requestBytes.length==0) {
|
|
|
|
|
RpcResponse rpcResponse = new RpcResponse();
|
|
|
|
|
rpcResponse.setError("RpcRequest byte[] is null");
|
|
|
|
|
return rpcResponse;
|
|
|
|
|
}
|
|
|
|
|
RpcRequest rpcRequest = (RpcRequest) HessianSerializer.deserialize(requestBytes, RpcRequest.class);
|
|
|
|
|
|
|
|
|
|
// invoke
|
|
|
|
|
RpcResponse rpcResponse = NetComServerFactory.invokeService(rpcRequest, null);
|
|
|
|
|
return rpcResponse;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
|
|
RpcResponse rpcResponse = new RpcResponse();
|
|
|
|
|
rpcResponse.setError("Servet-error:" + e.getMessage());
|
|
|
|
|
return rpcResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|