Upgrade JDK 5.0 Update 1 or 2 to customize and deploy WebServices-axis!

Source: Internet
Author: User

Upgrade JDK 5.0 Update 1 or 2 to customize and deploy WebServices-axis!

JDK 1.4.x is normal!
However, when JDK 5.0 customizes and deploys WebServices-axis, run the following command:
Java org. Apache. axis. Client. adminclient deploy. WSDD
Always abnormal!
Upgrade to update 1:
Java version "1.5.0 _ 01"
Java (TM) 2 Runtime Environment, Standard Edition (build 1.5.0 _ 01-b08)
Java hotspot (TM) Client VM (build 1.5.0 _ 01-b08, mixed mode, sharing)
Finally, you can!
Related downloads:

JDK 5.0 Update 1:
Http://dlc.sun.com/jdk/jdk-1_5_0_01-windows-i586-p.exe

Resin 2.1.16 (recommended because it is smaller than Tomcat)
Http://www.caucho.com/download/resin-2.1.16.zip

Tomcat 5.5.7
Http://apache.justdn.org/jakarta/tomcat-5/v5.5.7/bin/jakarta-tomcat-5.5.7.zip

Apache WebServices-axis V1.1: (Jun 16,200 3)
Http://apache.freelamp.com/ws/axis/1_1/axis-1_1.zip
After decompression, copy the axis directory under the axis-1_1/webapps/directory to the resin or Tomcat webapps directory!

Javamail API 1.3.2 FCs:
Http: // 192.18.97.52/ECOM/ecomticketservlet/begin0c28a9f424724b9dd60f1da518a6c32a/-2147483648/755528103/1/540782/540770/755528103/2ts +/westcoastfsend/javamail-1_3_2-oth-JPR/javamail-1_3_2-oth-JPR: 1/javamail-1_3_2.zip

JavaBeans (TM) activation framework 1.0.2:
Http: // 192.18.97.131/ECOM/ecomticketservlet/tests/-2147483648/755539779/1/359918/359906/755539779/2ts +/westcoastfsend/7017-jaf-1.0.2-oth-jpr/7017-jaf-1.0.2-oth-jpr: 1/jaf-1_0_2-upd.zip

XML security version 1.2 of the Java Library:
Http://xml.apache.org/security/dist/java-library/xml-security-bin-1_2_0.zip

List:
Activation. Jar
Axis-ant.jar
Axis. Jar
Commons-discovery.jar
Commons-logging-api.jar
Commons-logging.jar
Jaxrpc. Jar
Log4j-1.2.8.jar
Mail. Jar
SAAJ. Jar
Stylebook-1.0-b3_xalan-2.jar
Wsdl4j. Jar
Xalan. Jar
Xercesimpl. Jar
Xml-apis.jar
Xmlparserapis. Jar
Xmlsec. Jar
Xmlsecsamples. Jar
Xmlsectests. Jar

Class1.java File Save to/webapps/axis/WEB-INF/classes/class1.java
Run: javac class1.java to compile it into class1.class:
Public class class1
{
Public static void main ()
{
System. Out. println ("Hello world! ");
// System. Out. println (new example sclass1 (). sayhelloto ("world! "));
}
Public String sayhelloto (string who)
{
Return "Hello:" + WHO;
}
Public String sayhellotoo (string who)
{
Return "Hello:" + WHO;
}
}

Http: // localhost: 1080/axis/services/class1service? WSDL
Save as: XX. WSDL
Deploy. WSDD (undeploy. WSDD) file,
Deploy. WSDD (undeploy. WSDD) Deployment File
<Deployment xmlns = "http://xml.apache.org/axis/wsdd/" xmlns: Java = "http://xml.apache.org/axis/wsdd/providers/java">
<Service name = "class1service" provider = "Java: RPC">
<Parameter name = "classname" value = "class1"/>
<Parameter name = "allowedmethods" value = "*"/>
</Service>
</Deployment>

Client:

(A) Generate a client stub (stub) from the WSDL File)Code, Server framework (skeleton) Code and Data Type files in WSDL (generate corresponding Java code)
It can be generated by the command line ::
Java org. Apache. axis. WSDL. wsdl2java -- skeletondeploy true XX. WSDL

1. Deploy. WSDD: Deployment description file of myservice
2. myservice. Java: interface file of myservice
3. myserviceservice. Java: Obtain the interface file of myservice.
4. myserviceservicelocator. Java: implements the myserviceservice interface.
5. myservicesoapbindingimpl. Java: implements the myservice interface and adds the business logic to it.
6. myservicesoapbindingskeleton. Java: the Server framework code of myservice to implement the interfaces of myservice, org. Apache. axis. WSDL. Skeleton.
7. myservicesoapbindingstub. Java: client stub code of myservice to implement the myservice Interface
8. undeploy. WSDD: unregister the deployment description file of the myservice service.

(B)
Dynamic WebServices call:
See: Wang Yonggang
Wscaller: common web service client and Test Tool
Http://www.contextfree.net/wangyg/c/wsCaller/wsCaller.html

Import org. Apache. axis. constants;
Import org. Apache. axis. encoding. Ser. simpledeserializer;
Import org. Apache. axis. WSDL. gen. parser;
Import org. Apache. axis. WSDL. symboltable .*;

Import javax. WSDL .*;
// Import javax. WSDL. Extensions. Soap. soapaddress;
Import javax. xml. namespace. QNAME;
Import javax. xml. rpc. call;
Import javax. xml. rpc. encoding. deserializer;
Import javax. xml. rpc. encoding. deserializerfactory;

Import java. util .*;

// Import localhost. axis. Services;
// Web service dynamic invoker

Public class dynamicinvoker
{
Private parser wsdlparser = NULL;
Private map services = NULL;

Public dynamicinvoker (string wsdlurl) throws exception
{
Wsdlparser = new Parser ();
Wsdlparser. Run (wsdlurl );
Services = enumsymtabentry (serviceentry. Class );
}

Public map invoke (string servicename,
String portname,
String operationname,
Vector parametervalues) throws exception
{
Vector inputs = new vector ();
String returnname = NULL;

Serviceentry = (serviceentry) services. Get (servicename );
Service = serviceentry. getservice ();
Org. Apache. axis. Client. Service clientservice = new
Org. Apache. axis. Client. Service (wsdlparser, Service. getqname ());

Call call = clientservice. createcall (QNAME. valueof (portname), QNAME. valueof (operationname ));
(Org. Apache. axis. Client. Call). setTimeout (New INTEGER (15*1000 ));

Bindingentry = getbindingentry (servicename, portname );
Operation o = getoperation (bindingentry, operationname );
Parameters = bindingentry. getparameters (O );

If (parameters. returnparam! = NULL)
{
// QNAME returntype = org. Apache. axis. WSDL. tojava. utils. getxsitype (parameters. returnparam );
QNAME returnqname = parameters. returnparam. getqname ();
Returnname = returnqname. getlocalpart ();
}

Int size = parameters. List. Size ();
For (INT I = 0; I <size; I ++)
{
Parameter P = (parameter) parameters. list. Get (I );
Switch (P. getmode ())
{
Case parameter. In:
Inputs. Add (getparamdata (Org. Apache. axis. Client. Call) Call
, P
, (String) parametervalues. elementat (I )));
Break;
Case parameter. out:
Break;
Case parameter. inout:
Inputs. Add (getparamdata (Org. Apache. axis. Client. Call) call,
P,
(String) parametervalues. elementat (I )));
Break;
}
}

Object ret = call. Invoke (inputs. toarray ());
Map outputs = call. getoutputparams ();
Hashmap map = new hashmap ();
If (Ret! = NULL & returnname! = NULL)
{
Map. Put (returnname, RET );
}
If (outputs! = NULL)
{
For (iterator I = outputs. keyset (). iterator (); I. hasnext ();)
{
Object OBJ = I. Next ();
String name;
Object value;
If (obj. getclass (). getname (). Equals ("Java. Lang. String "))
{
Name = (string) OBJ;
}
Else
{
Name = (QNAME) OBJ). getlocalpart ();
}
Value = outputs. Get (OBJ );
Map. Put (name, value );
}
}
Return map;
}

Public vector enumservicenames ()
{
Vector v = new vector ();
Iterator I = services. keyset (). iterator ();
While (I. hasnext ())
{
String S = (string) I. Next ();
V. addelement (s );
}
Return V;
}

Public vector enumportnames (string servicename)
{< br> vector v = new vector ();
serviceentry = (serviceentry) services. get (servicename);
map ports = serviceentry. getservice (). getports ();
iterator I = ports. keyset (). iterator ();
while (I. hasnext ()
{< br> string S = (string) I. next ();
v. addelement (s);
}< br> return V;
}

Public vector enumoperationnames (string servicename, string portname)
{< br> vector v = new vector ();
bindingentry entry = getbindingentry (servicename, portname);
Set Operations = entry. getoperations ();
iterator I = operations. iterator ();
while (I. hasnext ()
{< br> operation o = (operation) I. next ();
string S = O. getname ();
v. addelement (s);
}< br> return V;
}

Public parameters enumparameters (string servicename
, string portname
, string operationname)
{< br> bindingentry entry = getbindingentry (servicename, portname );
operation o = getoperation (entry, operationname);
parameters = entry. getparameters (o);
return parameters;
}

Public String getparametermodestring (parameter P)
{< br> string ret = NULL;
switch (P. getmode ()
{< br> case parameter. in:
ret = "[in]";
break;
case parameter. inout:
ret = "[In, out]";
break;
case parameter. out:
ret = "[out]";
break;
}< br> return ret;
}

Private bindingentry getbindingentry (string servicename, string portname)
{
Serviceentry = (serviceentry) services. Get (servicename );
Port port = serviceentry. getservice (). getport (portname );
Binding binding = port. getbinding ();
Symboltable table = wsdlparser. getsymboltable ();
Return table. getbindingentry (binding. getqname ());
}

Private operation getoperation (bindingentry entry, string operationname)
{
Set Operations = entry. getoperations ();
Iterator I = operations. iterator ();
While (I. hasnext ())
{
Operation o = (operation) I. Next ();
If (operationname. Equals (O. getname ()))
{
Return O;
}
}
Return NULL;
}

// Return map of <QNAME. getlocalpart, symtabentry>
Private map enumsymtabentry (class CLs)
{
Hashmap ret = new hashmap ();
Hashmap map = wsdlparser. getsymboltable (). gethashmap ();
Iterator = map. entryset (). iterator ();
While (iterator. hasnext ())
{
Map. Entry entry = (Map. Entry) iterator. Next ();
QNAME key = (QNAME) entry. getkey ();
Vector v = (vector) entry. getvalue ();
Int size = V. Size ();
For (INT I = 0; I <size; ++ I)
{
Symtabentry = (symtabentry) v. elementat (I );
If (CLS. isinstance (symtabentry ))
{
Ret. Put (key. getlocalpart (), symtabentry );
}
}
}
Return ret;
}

Private object getparamdata (Org. Apache. axis. Client. Call C, parameter P,
String Arg) throws exception
{
// Get the QNAME representing the parameter type
QNAME paramtype = org. Apache. axis. WSDL. tojava. utils. getxsitype (P );

Typeentry type = P. GetType ();
If (type instanceof basetype & (basetype) type). isbasetype ())
{
Deserializerfactory factory = C. gettypemapping (). getdeserializer (paramtype );
Deserializer = factory. getdeserializeras (constants.
Axis_sax );
If (deserializer instanceof simpledeserializer)
{
Return (simpledeserializer) deserializer). makevalue (ARG );
}
}
Throw new runtimeexception ("not know how to convert'" + Arg
+ "'Into" + C );
}
}

Class apptest
{
Public static void main (string [] ARGs) throws exception
{
System. Out. println ("Hello world! ");
// Dynamically call webservics
String location = "http: // localhost: 1080/axis/services/class1service? WSDL ";
Dynamicinvoker invoker = new dynamicinvoker (location );
Vector vservices = invoker. enumservicenames ();
Object [] services = vservices. toarray ();
Arrays. Sort (services );
For (INT I = 0; I <services. length; I ++)
{
String servicename = (string) services [I];
System. Out. println (servicename );
Vector v = invoker. enumportnames (servicename );
String portname = (string) v. elementat (0 );
V = invoker. enumoperationnames (servicename, portname );
Object [] operationnames = V. toarray ();
Arrays. Sort (operationnames );
For (Int J = 0; j <operationnames. length; j ++)
{
String operationname = (string) operationnames [J];
System. Out. println ("/t" + (string) operationnames [J]);
Parameters = invoker. enumparameters (servicename, portname, operationname );
Vector v = parameters. List;
Vector parametervalues = new vector ();
For (int K = 0; k <v. Size (); k ++)
{
Parameter para = (parameter) v. elementat (k );
System. Out. Print ("/T" + para. getqname (). getlocalpart ());
If (para. GetType (). getqname (). getlocalpart (). Equals ("string "))
{
Parametervalues. addelement ("asdasdas ");
}
Else
{
Parametervalues. addelement (null );
}
System. Out. Print ("/t" + para. GetType (). getqname (). getlocalpart ());
System. Out. println ("/t" + invoker. getparametermodestring (para ));
}
Map result = invoker. Invoke (servicename, portname, operationname, parametervalues );
For (iterator it = result. keyset (). iterator (); it. hasnext ();)
{
String name = (string) it. Next ();
Object value = result. Get (name );
String line;
If (value! = NULL)
{
Line = Name + "=" + result. Get (name). tostring () + "/N ";
}
Else
{
Line = Name + "= (null)/n ";
}
System. Out. println (line );
}
}
}

// Call the proxy class to call WebServices
Localhost. axis. Services. class1service. class1 x = new localhost. axis. Services. class1service. class1servicelocator (). getclass1service ();
// (Localhost. axis. Services. class1service. class1servicesoapbindingstub) x). setmaintainsession (true );
System. Out. println (X. sayhelloto ("Three ADAs "));
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.