Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 146 147 148 149 150 151 < 152 > 153 154 155 156 157 158 .. 166 >> Next

001 package org.javapitfalls.item48;
002
003 import java.net.URL;
004 import javax.xml.rpc.Service;
005 import javax.xml.rpc.JAXRPCException;
006 import javax.xml.namespace.QName;
007 import javax.xml.rpc.ServiceFactory;
008
009 public class DynamicProxyClient
010 {
011
Listing 48.4 A simple client using dynamic proxies (continued)
422 Item 48
012 public static void main(String[] args)
013 {
014 try
015 {
016
017 long initial, afterproxy, preInvokeTime, invokeTime;
018
019 initial = System.currentTimeMillis();
020
021 String UrlString =
022 "http://localhost:8080/simpletest- 2
jaxrpc/simpletest?WSDL";
023 String nameSpaceUri =
024 "http://org.javapitfalls.item48/wsdl/SimpleTest";
025 String serviceName = "SimpleTest";
026 String portName = "SimpleTestIFPort";
027
028 URL WsdlUrl = new URL(UrlString);
029
030 ServiceFactory serviceFactory =
031 ServiceFactory.newInstance();
032 Service simpleService =
033 serviceFactory.createService(WsdlUrl,
034 new QName(nameSpaceUri, serviceName));
035 SimpleTestIF myProxy = (SimpleTestIF) 2
simpleService.getPort(
036 new QName(nameSpaceUri, portName),
037 org.javapitfalls.item48.SimpleTestIF.class);
038
039 afterproxy = System.currentTimeMillis();
040 preInvokeTime = afterproxy - initial;
041
042 String response = myProxy.doStuff(
043 "Hello from Dynamic Proxy..");
044
045 //Print out stats
046 System.out.println("Invocation setup took "
047 + preInvokeTime + " milliseconds.");
048
049 }
050 catch ( Exception ex )
051 {
052 ex.printStackTrace();
053 }
054 }
055 }
Listing 48.4 (continued)
Performance Pitfalls in JAX-RPC Application Clients 423
It is important to realize that this example requires a copy of the compiled Java interface class that we created (in order to cast it on line 35), but it does not require any precompilation steps. Where our precompilation process for our first example involved downloading the WSDL and creating the stubs before runtime, the dynamic proxy method does everything at runtime. This convenience will come at a cost. On line 46 of Listing 48.4, we print out our invocation setup time.
Two Clients Using the Dynamic Invocation Interface (Dll)
A client can call a Web service using the Dynamic Invocation Interface (DII). The javax.xml.rpc.Call interface provides support for the dynamic invocation of an operation on a target service endpoint. In this section, we demonstrate two examples. In the first example, shown in Listing 48.5, we know where our Web service is, and we know the methods of our Web service. We will simply create our Call object and invoke the doStuff() method.
In lines 28 to 30 of Listing 48.5, we create our Service object. In line 35, we create the Call object by passing the port name (which is the qualified name for "SimpleTestIF" set up on line 32). In lines 36 to 55, we create our call by setting properties, setting our return types, and setting up our parameter information. Finally, on line 62, we perform the invocation.
001 package org.javapitfalls.item48;
002
003 import javax.xml.rpc.*;
004 import javax.xml.namespace.*;
005
006 public class DIIClient
007 {
008
009
010 public static void main(String[] args)
011 {
012 String endpoint =
013 "http://localhost:8080/simpletest-jaxrpc/simpletest";
014 String servicenamespace =
015 "http://org.javapitfalls.item48/wsdl/SimpleTest";
016 String encodingStyleProperty =
017 "javax.xml.rpc.encodingstyle.namespace.uri";
018
019 try
020 {
021
022 long initial, afterproxy, preInvokeTime, invokeTime;
023
Listing 48.5 A simple client using DII hard-coded calls (continued)
424 Item 48
024 initial = System.currentTimeMillis();
025
026 //Set up the service, giving it the service name
027 //and the port (interface)
028 ServiceFactory factory = ServiceFactory.newInstance();
029 Service service = factory.createService(
030 new QName("SimpleTest")
031 );
032 QName port = new QName("SimpleTestIF");
033
034 //Set up the call & the endpoint..
035 Call call = service.createCall(port);
036 call.setTargetEndpointAddress(endpoint);
037
038 //Set up the Call properties...
039 call.setProperty(Call.SOAPACTION_USE_PROPERTY,
040 new Boolean(true)
041 );
042 call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
043 call.setProperty(encodingStyleProperty,
044 "http://schemas.xmlsoap.org/soap/encoding/");
045
046 QName qnametype =
047 new QName("http://www.w3.org/2001/XMLSchema","string");
048 call.setReturnType(qnametype);
049
050 //Set up the operation name & parameter...
051 call.setOperationName(
052 new QName(servicenamespace, "doStuff"));
053
054 call.addParameter("String_1", qnametype, ParameterMode.IN);
055 String[] params = { "Hello from DII Client!"};
056
057 afterproxy = System.currentTimeMillis();
Previous << 1 .. 146 147 148 149 150 151 < 152 > 153 154 155 156 157 158 .. 166 >> Next