Advertisement

02.23.2007 at 02:42AM PST, ID: 22408696
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

Axis2 User Guide Example

Asked by thomas908 in J2EE, Java Programming Language

Tags: , ,

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.axis2userguide;

import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;

public class SampleService {

    public OMElement sayHello(OMElement element) throws XMLStreamException {
            element.build();
            element.detach();

            String rootName = element.getLocalName();
            System.out.println("Reading "+rootName+" element");
           
            OMElement childElement = element.getFirstElement();
            String personToGreet = childElement.getText();

            OMFactory fac = OMAbstractFactory.getOMFactory();
            OMNamespace omNs = fac.createOMNamespace("http://example1.org/example1", "example1");
            OMElement method = fac.createOMElement("sayHelloResponse", omNs);
            OMElement value = fac.createOMElement("greeting", omNs);
            value.addChild(fac.createOMText(value, "Hello, "+personToGreet));
            method.addChild(value);

            return method;
        }

     private void ping(){
     }
   
}

This is services.xml
<?xml version='1.0' encoding='utf-8' ?>

<service name="UserGuideSampleService">
    <description>
        This is a sample service created in the Axis2 User's Guide
    </description>

    <parameter name="ServiceClass"
locked="false">org.apache.axis2.axis2userguide.SampleService
</parameter>

    <operation name="sayHello">
        <messageReceiver
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
    </operation>
    <operation name="ping">
        <messageReceiver
class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
    </operation>
</service>

I have copied the SampleService.aar file to
Tomcat_Home\webapps\axis2\WEB-INF\services

This the client file

package org.apache.axis2.axis2userguide;

import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.Constants;
import org.apache.axis2.client.ServiceClient;

public class SampleClient {

       private static EndpointReference targetEPR =
             new EndpointReference("http://localhost:8080/axis2/services/UserGuideSampleService");

        public static OMElement greetUserPayload(String personToGreet) {

                  OMFactory fac = OMAbstractFactory.getOMFactory();
            OMNamespace omNs = fac.createOMNamespace("http://example1.org/example1", "example1");
            OMElement method = fac.createOMElement("sayHello", omNs);
            OMElement value = fac.createOMElement("personToGreet", omNs);
            value.addChild(fac.createOMText(value, personToGreet));
            method.addChild(value);
            return method;
        }

        public static void main(String[] args) {
            try {
                OMElement payload = SampleClient.greetUserPayload("John");
System.out.println("11111111111111111");
                Options options = new Options();
                options.setTo(targetEPR);
                System.out.println("22222222222222");
                options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
System.out.println("33333333333");
                ServiceClient sender = new ServiceClient();
System.out.println("444444444");
                        sender.setOptions(options);
                        System.out.println("5555555555555555");
                OMElement result = sender.sendReceive(payload);
                        System.out.println("66666666666666");
                String response = result.getFirstElement().getText();
                System.out.println(response);

            } catch (Exception e) { //(XMLStreamException e) {
                System.out.println(e.toString());
            }
        }
   
}

It compiles fine, but when I try to run it, I get the following error

D:\sampleWebService>java org.apache.axis2.axis2userguide.SampleClient
11111111111111111
22222222222222
33333333333
Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.apache.axis2.deployment.DescriptionBuilder.buildOM(DescriptionBu
lder.java:86)
        at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisCon
igBuilder.java:58)
        at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfigurati
n(DeploymentEngine.java:690)
        at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfigurat
on(FileSystemConfigurator.java:109)
        at org.apache.axis2.context.ConfigurationContextFactory.createConfigura
ionContext(ConfigurationContextFactory.java:61)
        at org.apache.axis2.context.ConfigurationContextFactory.createConfigura
ionContextFromFileSystem(ConfigurationContextFactory.java:180)
        at org.apache.axis2.client.ServiceClient.initializeTransports(ServiceCl
ent.java:189)
        at org.apache.axis2.client.ServiceClient.configureServiceClient(Service
lient.java:118)
        at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:114)
        at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:207)
        at org.apache.axis2.axis2userguide.SampleClient.main(SampleClient.java:
8)
Caused by: java.lang.IllegalStateException: No valid ObjectCreator found.
        at org.apache.axiom.om.util.StAXUtils$Pool.<init>(StAXUtils.java:41)
        at org.apache.axiom.om.util.StAXUtils.<clinit>(StAXUtils.java:62)
        ... 11 more


Please tell me how to resolve this problem...
Thank You

Start Free Trial
[+][-]02.23.2007 at 03:42AM PST, ID: 18595049

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: J2EE, Java Programming Language
Tags: axis2, objectcreator, valid
Sign Up Now!
Solution Provided By: jcoombes
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.23.2007 at 04:20AM PST, ID: 18595205

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.23.2007 at 04:37AM PST, ID: 18595290

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.23.2007 at 09:43AM PST, ID: 18597730

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32