Why are you returning stream reader instead of xml document ?

On 4/17/07, Yasumasa Shigemoto <[EMAIL PROTECTED]> wrote:
Hi,

I am trying to create a service to return an
instance of XMLStreamReader.

I have four simple code and I got an error
as follows.


Echo.java
import javax.xml.stream.XMLStreamReader;

public interface Echo {
        String echo(String echo);
        XMLStreamReader returnReader(String s);
}

EchoImpl.java
import javax.xml.stream.*;
import java.io.*;

public class EchoImpl implements Echo {
        public String echo(String echo) {
                return echo;
        }

        public XMLStreamReader returnReader(String s) {
                System.out.println("returnReader called with param: " + s);
                XMLStreamReader reader = null;
                try {
                        XMLInputFactory factory =
XMLInputFactory.newInstance();
                        BufferedInputStream stream = new
BufferedInputStream(new
 FileInputStream("/home/blast/xfire/testDir3/book.xml"));
                        reader = factory.createXMLStreamReader(stream);
                        System.out.println("after create XMLStreamReader");
                } catch(Exception e) {
                        e.printStackTrace();
                }
                return reader;
        }
}

ServiceStarter.java
import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.server.http.XFireHttpServer;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.codehaus.xfire.service.invoker.BeanInvoker;

/**
 * Creates an Echo service and exposes it via HTTP.
 */
public class ServiceStarter {
        XFireHttpServer server;

        public void start() throws Exception {
                // Create an XFire Service
                ObjectServiceFactory serviceFactory = new
ObjectServiceFactory()
;
                Service service = serviceFactory.create(Echo.class);
                service.setInvoker(new BeanInvoker(new EchoImpl()));

                // Register the service in the ServiceRegistry
                XFire xfire = XFireFactory.newInstance().getXFire();
                xfire.getServiceRegistry().register(service);

                // Start the HTTP server
                server = new XFireHttpServer();
                server.setPort(8191);
                server.start();
        }

        public void stop() throws Exception {
                server.stop();
        }
}

Main.java
import org.codehaus.xfire.*;
import org.codehaus.xfire.server.http.XFireHttpServer;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.codehaus.xfire.service.invoker.BeanInvoker;
import org.codehaus.xfire.client.*;
import javax.xml.stream.*;

public class Main {
        public static void main(String args[]) throws Exception {
                ServiceStarter starter = new ServiceStarter();
                starter.start();

                // Create a service model for the client
                ObjectServiceFactory serviceFactory = new
ObjectServiceFactory()
;
                Service serviceModel = serviceFactory.create(Echo.class);

                // Create a client proxy
                XFireProxyFactory proxyFactory = new XFireProxyFactory();
                Echo echo = (Echo) proxyFactory.create(serviceModel,
"http://loc
alhost:8191/Echo");
                System.out.println(echo.echo("Hello World"));
                XMLStreamReader reader = echo.returnReader("test");
                starter.stop();
        }
}

$ java Main
- Version Jetty/5.1.3
- Started [EMAIL PROTECTED]
- Started ServletHttpContext[/,/]
- Started SocketListener on 0.0.0.0:8191
- Started [EMAIL PROTECTED]
- XFireServlet: init
Hello World
returnReader called with param: test
after create XMLStreamReader
Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could
not i
nvoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault:
Index:
1, Size: 1
...

Could you please let me know how should I modify the
codes?

Thanks,
Yasumasa


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email




--
-----
When one of our products stops working, we'll blame another vendor
within 24 hours.

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to