KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > attachmentstepbystep > MyServiceImpl


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.webservice.attachmentstepbystep;
23
24 import java.io.BufferedReader JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.InputStreamReader JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.rmi.RemoteException JavaDoc;
29 import javax.activation.DataHandler JavaDoc;
30
31
32
33 /**
34  * Implementation des m�thodes du service
35  */

36 public class MyServiceImpl implements MyService
37 {
38     
39     // CTOR
40
public MyServiceImpl() {
41         super();
42     }
43     
44     public DataHandler JavaDoc myService(DataHandler JavaDoc mimepart) throws RemoteException JavaDoc
45     {
46         URL JavaDoc url = null;
47         String JavaDoc result="";
48         try {
49             // print the recieved file
50
InputStream JavaDoc is = mimepart.getInputStream();
51             if (is != null) {
52                 BufferedReader JavaDoc in = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(is));
53                 
54                 String JavaDoc line="";
55                 line = in.readLine();
56                 result = "" + line;
57                 while (line != null)
58                 {
59                     System.out.println(line);
60                     line = in.readLine();
61                     result = result + line;
62                 }
63                 in.close();
64             }
65             // the file to return if size of received file == 192
66
if (result.length() == 190)
67             {
68                 url = new URL JavaDoc("http://" + System.getProperty("jboss.bind.address", "localhost") + ":8080/myservice/resources/attachment_server2client.txt");
69             }
70             else
71             {
72                 throw new Exception JavaDoc("The received file isn't 190 bytes length as expected. Length = " + result.length());
73             }
74         }
75         catch (Exception JavaDoc ex) {
76             System.err.println(ex);
77         }
78         return new DataHandler JavaDoc(url);
79     }
80
81     
82 }
83
Popular Tags