1

我们有一些视频 (mp4) 存储在我们的防火墙后面。我有一个 Java 代理,用于通过 RESTful Web 服务将 PDF、DOC 等其他文档提供给外部站点。同样的网络服务适用于 PC 浏览器中的视频,但在 iPad 上,我只是得到一个黑屏,播放按钮被阻止。如果我浏览到视频的直接位置,它可以正常播放。这让我相信视频很好,但我的网络服务代码中缺少一些可以备份它的东西。有什么想法吗?有其他人在 iPad 上征服了这个吗?

    @GET
    @Path("/open/{objectId}/{ticket}/{objectName}/")
    public Response openDocument(@PathParam("objectId") String objectId, @PathParam("ticket") String ticket, @PathParam("objectName") String objectName) throws Exception {
        return download(objectId, ticket, objectName, false);
    }

    private Response download(String objectId, String ticket, String objectName, boolean attachment) throws Exception {

        String url = "";
        if (objectName.endsWith(".mp4")) {
            url = "http://videosite.com/videos/" + objectName;
        }
        else {
            url = "http://documentsite.com/" + objectName;
        }

        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(url);

        try {

            HttpResponse response = client.execute(get);

            HttpEntity entity = response.getEntity();

            StatusLine status = response.getStatusLine();
            if (status.getStatusCode() == 200 || status.getStatusCode() == 206) {

                ResponseBuilder rb = Response.ok(entity.getContent());

                rb.header("Connection", "Keep-Alive");
                rb.header("Content-Length", entity.getContentLength());
                rb.header("Content-Type", entity.getContentType().getValue());
                rb.header("Keep-Alive", "timeout=5, max=99");

                if (attachment) rb.header("Content-Disposition", "attachment; filename=\"" + objectName.replaceAll("\\+", " ") + "\"");
                else rb.header("Content-Disposition", "filename=\"" + objectName.replaceAll("\\+", " ") + "\"");

                return rb.build();
            }
            else return Response.noContent().build();

        }
        catch (Exception e) {
            e.printStackTrace();
            return Response.noContent().build();
        } 
    }
4

0 回答 0