Java Web 服务将文件传输到本地系统
我想用两种方法在java中创建一个Web服务
1)通过返回本地URL将文件从互联网传输到本地文件服务器
2)通过获取url从同一服务器检索文件
注意:它应该与所有格式
必须使用 Java Web 服务..
任何类型:字节数组、十六进制或 MIME 类型 传输都可以
附件大小为 4mb..
我无法直接连接到数据库,因为应用程序部署在 DMZ 上,并且仅有的我可以使用 Web 服务连接到 Intranet 中的文件服务器。
与文件服务器的连接已经完成。
I want to create a web service in java with two methods
1) to transfer a file from the internet to a local file server by returning local URL
2) to retrieve the file from the same server by taking the url
Note: It should work with all the formats
Its mandatory to use Java Web service..
any Type : Byte Array , Hexadecimal or MIME Type Transfer is OK
The size of the attachment is 4mb..
I can not connect to database directly because the application is deployed on DMZ and the only way I can connect to the file server in Intranet is by using Webservices.
Connection to the fileserver is already done..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
类似的场景:
是这个,他用一个简短的代码进行了解释
A similar scenario:
is this and he has explained using a short code
如果您的主要问题是找到通过 Java 中的 Web 服务轻松传输文件的技巧,我会推荐 Hessian 服务,该服务在 Hessian with Large Binary Data (java) 发布在 SO 上。那里的链接提供了实现一种文件传输的示例。
如果您不想过多地搞乱 Web 服务本身的逻辑,那么 Hessian 是一个很好的解决方案。快速查看 Hessian 代码,您甚至不会意识到自己正在使用它。这是一个重量轻的解决方案。
Stefan 有一个解决方案,您可以在其中了解 Web 服务逻辑的大部分内容,因此这取决于您想要拥有多高的抽象级别。如果此任务的目的是展示如何使用 Web 服务而不仅仅是使其正常工作,那么 Stefan 就有了答案。
关于文件上传等,您想从互联网保存文件。看这个:如何下载和保存文件使用 Java 从 Internet 获取?。它使用纯 Java,并且在我的理解中不需要任何 Web 服务来完成给定的任务,但是如果将这两者结合起来,您会得到非常容易工作的东西!
If your main problem is to find tips for easy file transfer over a web service in java, I would recommend the Hessian service, discussed on Hessian with large binary data (java) post on SO. The link there goes for an example that implements one kind of file transfering.
Hessian is a good solution, if you don't want to mess up too much with the logic of the web services itself. Looking a Hessian code rapidly you would not even recognize you are using one. It is so light weight solution.
Stefan has a solution, where you get pretty much inside the Web Services logics, so it is up to you how high abstraction level you want to have. If the point of this task is to show how to use web services and not just get it work, then Stefan has the answer.
About file upload and such, you wanted to save a file from internet. Look this: How to download and save a file from Internet using Java?. This uses pure Java and in my understanding does not need any web services to accomplish the given task, but if you combine these two you get something that works very easily!
由于您已使用
soap
标记了这个问题,因此我假设您需要 Java 中的 SOAP Web 服务。这也使得 JAX-WS(用于 XML Web 服务的 Java API)成为该库的自然选择使用。 Java(TM) Web 服务教程 将更详细地涵盖您的问题。现在,您需要实现获取图像并返回 URL 的逻辑,以及获取 URL 并返回图像的逻辑。
您可能还需要设置一些额外的配置,如部署 Metro Endpoint 中所述。本文的要点是,您需要将
sun-jaxws.xml
文件添加到表单的WEB-INF/
文件夹中,并添加一些 JAX-WS 内容到您的
web.xml
文件中,如下所示:最后,将所有内容打包到 .war 文件中并将其部署到 Java Web 服务器(例如 Tomcat)。
Since you've tagged this question with
soap
, I'm going to assume you want a SOAP web service in Java. This also makes JAX-WS (the Java API for XML Web Services) a natural choice for the library to use. The Java(TM) Web Services Tutorial will cover your problem in greater detail.Now you're going to need to implement the logic to take images and return URLs, and take URLs and return images.
You'll also probably need to set up some additional configuration as described in Deploying Metro Endpoint. The gist of the article is that you need to add a
sun-jaxws.xml
file to yourWEB-INF/
folder of the formAnd also add some JAX-WS stuff to your
web.xml
file like so:Finally, package everything up into a .war file and deploy it to a Java web server (e.g. Tomcat).