I am going throug the user guide for Axis2 and trying to build a simple web service. I have Tomcat 5 server.
This is the SampleService.java
package org.apache.axis2.axis2user
guide;
import javax.xml.stream.XMLStream
Exception;
import org.apache.axiom.om.OMAbst
ractFactor
y;
import org.apache.axiom.om.OMElem
ent;
import org.apache.axiom.om.OMFact
ory;
import org.apache.axiom.om.OMName
space;
public class SampleService {
public OMElement sayHello(OMElement element) throws XMLStreamException {
element.build();
element.detach();
String rootName = element.getLocalName();
System.out.println("Readin
g "+rootName+" element");
OMElement childElement = element.getFirstElement();
String personToGreet = childElement.getText();
OMFactory fac = OMAbstractFactory.getOMFac
tory();
OMNamespace omNs = fac.createOMNamespace("
http://example1.org/example1", "example1");
OMElement method = fac.createOMElement("sayHe
lloRespons
e", omNs);
OMElement value = fac.createOMElement("greet
ing", omNs);
value.addChild(fac.createO
MText(valu
e, "Hello, "+personToGreet));
method.addChild(value);
return method;
}
private void ping(){
}
}
This is services.xml
<?xml version='1.0' encoding='utf-8' ?>
<service name="UserGuideSampleServi
ce">
<description>
This is a sample service created in the Axis2 User's Guide
</description>
<parameter name="ServiceClass"
locked="false">org.apache.
axis2.axis
2userguide
.SampleSer
vice
</parameter>
<operation name="sayHello">
<messageReceiver
class="org.apache.axis2.re
ceivers.Ra
wXMLINOutM
essageRece
iver"/>
</operation>
<operation name="ping">
<messageReceiver
class="org.apache.axis2.re
ceivers.Ra
wXMLINOnly
MessageRec
eiver"/>
</operation>
</service>
I have copied the SampleService.aar file to
Tomcat_Home\webapps\axis2\
WEB-INF\se
rvices
This the client file
package org.apache.axis2.axis2user
guide;
import javax.xml.stream.XMLStream
Exception;
import org.apache.axiom.om.OMAbst
ractFactor
y;
import org.apache.axiom.om.OMElem
ent;
import org.apache.axiom.om.OMFact
ory;
import org.apache.axiom.om.OMName
space;
import org.apache.axis2.addressin
g.Endpoint
Reference;
import org.apache.axis2.client.Op
tions;
import org.apache.axis2.Constants
;
import org.apache.axis2.client.Se
rviceClien
t;
public class SampleClient {
private static EndpointReference targetEPR =
new EndpointReference("
http://localhost:8080/axis2/services/UserGuideSampleService");
public static OMElement greetUserPayload(String personToGreet) {
OMFactory fac = OMAbstractFactory.getOMFac
tory();
OMNamespace omNs = fac.createOMNamespace("
http://example1.org/example1", "example1");
OMElement method = fac.createOMElement("sayHe
llo", omNs);
OMElement value = fac.createOMElement("perso
nToGreet",
omNs);
value.addChild(fac.createO
MText(valu
e, personToGreet));
method.addChild(value);
return method;
}
public static void main(String[] args) {
try {
OMElement payload = SampleClient.greetUserPayl
oad("John"
);
System.out.println("111111
1111111111
1");
Options options = new Options();
options.setTo(targetEPR);
System.out.println("222222
22222222")
;
options.setTransportInProt
ocol(Const
ants.TRANS
PORT_HTTP)
;
System.out.println("333333
33333");
ServiceClient sender = new ServiceClient();
System.out.println("444444
444");
sender.setOptions(options)
;
System.out.println("555555
5555555555
");
OMElement result = sender.sendReceive(payload
);
System.out.println("666666
66666666")
;
String response = result.getFirstElement().g
etText();
System.out.println(respons
e);
} catch (Exception e) { //(XMLStreamException e) {
System.out.println(e.toStr
ing());
}
}
}
It compiles fine, but when I try to run it, I get the following error
D:\sampleWebService>java org.apache.axis2.axis2user
guide.Samp
leClient
11111111111111111
22222222222222
33333333333
Exception in thread "main" java.lang.ExceptionInIniti
alizerErro
r
at org.apache.axis2.deploymen
t.Descript
ionBuilder
.buildOM(D
escription
Bu
lder.java:86)
at org.apache.axis2.deploymen
t.AxisConf
igBuilder.
populateCo
nfig(AxisC
on
igBuilder.java:58)
at org.apache.axis2.deploymen
t.Deployme
ntEngine.p
opulateAxi
sConfigura
ti
n(DeploymentEngine.java:69
0)
at org.apache.axis2.deploymen
t.FileSyst
emConfigur
ator.getAx
isConfigur
at
on(FileSystemConfigurator.
java:109)
at org.apache.axis2.context.C
onfigurati
onContextF
actory.cre
ateConfigu
ra
ionContext(ConfigurationCo
ntextFacto
ry.java:61
)
at org.apache.axis2.context.C
onfigurati
onContextF
actory.cre
ateConfigu
ra
ionContextFromFileSystem(C
onfigurati
onContextF
actory.jav
a:180)
at org.apache.axis2.client.Se
rviceClien
t.initiali
zeTranspor
ts(Service
Cl
ent.java:189)
at org.apache.axis2.client.Se
rviceClien
t.configur
eServiceCl
ient(Servi
ce
lient.java:118)
at org.apache.axis2.client.Se
rviceClien
t.<init>(S
erviceClie
nt.java:11
4)
at org.apache.axis2.client.Se
rviceClien
t.<init>(S
erviceClie
nt.java:20
7)
at org.apache.axis2.axis2user
guide.Samp
leClient.m
ain(Sample
Client.jav
a:
8)
Caused by: java.lang.IllegalStateExce
ption: No valid ObjectCreator found.
at org.apache.axiom.om.util.S
tAXUtils$P
ool.<init>
(StAXUtils
.java:41)
at org.apache.axiom.om.util.S
tAXUtils.<
clinit>(St
AXUtils.ja
va:62)
... 11 more
Please tell me how to resolve this problem...
Thank You
Start Free Trial