How to use AXIS to transfer attachments [original]

zhaozj2021-02-12  136

There are two ways to use AXIS to transfer attachments:

1. Package the file you want to send in the DataHandler, then use the DataHandler object or the DataHandler array (multiple files) as the parameter (from the client uploaded file to the server) Axis service (from the client) ( Transfer from the server-side download file to the client).

2. There is also a way to directly modify the contents of the SOAP envelope, and add attachment information to the SOAP envelope.

Here we only discuss the first method because it is very simple to achieve. There is a detailed original code for the second method in WebApps / Attachments / Testrf.java in the AXIS package.

The following example is to download the file from the server side to the client:

1. Services:

Assume that multiple files are transmitted: take the file out of the server and package the file in the DataHandler array. code show as below:

DataHandler [] ret= new datahandler [TotalFilenum]; ... java.io.file myfile = new java.io.file (filepath); if (myfile.isfile () && myfile.canread ()) {String FNAME = myfile.getabsolutefile (). getcanonicalpath (); datahandler [0] = new datahandler (new filedataroup (fname));} ...

Return Ret;

The above code puts all files in the DataHandler array and returns.

2. Client access:

The code is as follows: Service service = new service (); call call = (call) service.createcall ();

URL MyURL = New URL ("http://192.168.0.26:8080/AXIS/Servlet/AXisServlet"); call.SettargetendPointAddress (myURL); // Settings the host and location call.setoprationname ("URN" : Myattachserver "," echodir ")); // Setting the method to call QName QnameAttachment = New QName (" URN: MyattachServer "," DataHandler ");

Call.registertypemapping (DataHandler.Class, QNameAttachment, JafdataHandlerSerialfactory.class, jafdatahandlerDeserializerfactory.class); // Create a serialization generator for attachments (ie DataHandler class)

Call.addparameter ("Source", XMLTYPE.XSD_STRING, ParameterMode.in); // Sets the incoming parameter type call.setRetRntype (xmltype.soap_array); // Set the return type of the call service method, due to return It is a DataHandler array, so set to soap_Array type javax.activation.DataHandler [] Ret = (javax.activation.DataHandler []) call.invoke (new object [] {null}; // call method for (i = 0; I

3. Deployment of service:

Note: You have to define the serialization generator of DataHandler when you are deployed.

Write deploy.wsdd files:

Run java org.apache.axis.client.adminClient% * deploy.wsdd, deploy service.

If you want to want the source code, please leave an email address.

转载请注明原文地址:https://www.9cbs.com/read-6480.html

New Post(0)