Java Web服务将文件传输到本地系统 [英] Java web service to transfer file to Local system

查看:172
本文介绍了Java Web服务将文件传输到本地系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用两种方法在java中创建一个Web服务

I want to create a web service in java with two methods

1)通过返回本地URL将文件从Internet传输到本地文件服务器

1) to transfer a file from the internet to a local file server by returning local URL

2)通过获取网址从同一服务器检索文件

2) to retrieve the file from the same server by taking the url

注意:它应该适用于所有格式

Note: It should work with all the formats

它必须使用Java Web服务..

Its mandatory to use Java Web service..

任何类型:字节数组,十六进制或MIME类型转移没问题

any Type : Byte Array , Hexadecimal or MIME Type Transfer is OK

附件的大小是4mb ..

The size of the attachment is 4mb..

我无法直接连接到数据库,因为应用程序部署在DMZ上,我可以通过Web服务连接到Intranet中文件服务器的唯一方法。

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..

推荐答案

由于你用 soap 标记了这个问题,我要去假设您需要Java中的SOAP Web服务。这也使得 JAX-WS (用于XML Web服务的Java API)成为库的自然选择。使用。 Java(TM)Web服务教程将更详细地介绍您的问题。

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.

现在您需要实现逻辑来获取图像并返回URL,并获取URL并返回图像。

Now you're going to need to implement the logic to take images and return URLs, and take URLs and return images.

@WebService
public class MyJavaWebService {
    @WebMethod
    public String takeImage(byte[] image, String imageName) {
        //You'll need to write a method to save the image to the server.
        //How you actually implement this method is up to you.  You could
        //just open a FileOutputStream and write the image to a file on your
        //local server.
        this.saveImage(image, imageName);
        //Here is where you come up with your URL for the image.
        return this.computeURLForImage(imageName);
    }
    @WebMethod
    public byte[] getImage(String url) {
        final byte[] loadedImage = this.getImage(url);
        return loadedImage;
    }
}

您可能还需要设置一些额外的部署Metro Endpoint 中描述的配置。该文章的要点是,您需要将 sun-jaxws.xml 文件添加到 WEB-INF / 表格的文件夹

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 your WEB-INF/ folder of the form

<endpoints
        xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
        version="2.0">
    <endpoint
            name="MyJavaWebService"
            implementation="com.mycompany.MyJavaWebService"
            url-pattern="/MyJavaWebService"/>
</endpoints>

还要在 web.xml中添加一些JAX-WS东西这样的文件:

<web-app>
    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>MyJavaWebServiceServlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyJavaWebServiceServlet</servlet-name>
        <url-pattern>/MyJavaWebService</url-pattern>
    </servlet-mapping>
</web-app>

最后,将所有内容打包成.war文件并将其部署到Java Web服务器(例如Tomcat) )。

Finally, package everything up into a .war file and deploy it to a Java web server (e.g. Tomcat).

这篇关于Java Web服务将文件传输到本地系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆