You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by angeloimm <an...@libero.it> on 2005/04/28 13:20:58 UTC

Question about Axis1.2RC3

Hi all; first of all i want to thank Anne Thomas Manes for her tips.
I want to ask a thing i have a web service built in java; it is a java class that has several methods.
Now in my axis.wsdd i have added a service like this one:
    <service name="Interaction" type="" regenerateElement="false"
        provider="java:MSG" style="message" use="literal" validate="false">
        <parameter name="scope" value="Request" regenerateElement="false"/>
        <parameter name="className"
            value="it.eng.napsi.websrv.javabean.Interaction" regenerateElement="false"/>
        <parameter name="allowedMethods" value="*" regenerateElement="false"/>
        <namespace>http://javabean.websrv.napsi.eng.it</namespace>
        <operation name="byFiscalCode"
            returnQName="ns1:byFiscalCodeReturn"
            returnType="xsd:anyType" qname="ns1:byFiscalCode"
            regenerateElement="false" xmlns:ns1="http://javabean.websrv.napsi.eng.it"/>
    </service>

Now i have this simple client:
package it.eng.test.client.util;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.message.SOAPBody;
import org.apache.axis.utils.XMLUtils;
import javax.xml.rpc.ServiceException;

import java.util.Vector;
import org.w3c.dom.Document;
import javax.xml.namespace.QName;

import org.apache.log4j.Logger;
import java.net.URL;
import java.net.MalformedURLException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.util.*;

import it.eng.napsi.input.individuo.IndividualMarshaller;


public class SimpleAxisClient {
    public SimpleAxisClient() {
    }

    private static final Logger LOG = Logger.getLogger(SimpleAxisClient.class.
            getName());


    private Call getCall(String endpoint, String operation) throws
            ServiceException {

        if (LOG.isDebugEnabled()) {

            LOG.debug("Creating call.....");
        }
        Call result = (Call) (new Service()).createCall();
        try {
            result.setTargetEndpointAddress(new URL(endpoint));

        } catch (MalformedURLException ex) {

            LOG.error(ex);
        }

        result.setOperation(new QName(endpoint, operation), operation);
        if (LOG.isDebugEnabled()) {

            LOG.debug("Done!!");
        }
        return result;
    }

    public Document getDocument(Document doc, String endpoint,
                                String operation) throws Exception {
        Call call = getCall(endpoint, operation);
        Vector result = (Vector) call.invoke(new Object[] {doc});
        //Vector result = (Vector) call.invoke(new SOAPBodyElement[] { new SOAPBodyElement( doc.getDocumentElement() )});
        SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);

        if (LOG.isDebugEnabled()) {

            LOG.debug("Body ricevuto: " +
                      XMLUtils.DocumentToString(sbe.getAsDocument()));
        }
        return sbe.getAsDocument();
    }

    public static void main(String args[]) throws Exception {

        IndividualMarshaller ind = new IndividualMarshaller();
        Map envi = new Hashtable();
        envi.put( "codFisc","MMDNGL74C22H703K" );
        //String xmlString = ind.toStringDocument( envi );
        /*
        String xmlString = "<impl:doc xmlns:impl='http://javabean.websrv.napsi.eng.it'>"+
                           "<ricercaIndividuo><codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>"+
                           "</ricercaIndividuo></impl:doc>";
         */
        String xmlString = "<impl:byFiscalCod xmlns:impl='http://javabean.websrv.napsi.eng.it'>"+
                           "<ricercaIndividuo><codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>"+
                           "</ricercaIndividuo></impl:byFiscalCod>";
        System.out.println( xmlString );
        SimpleAxisClient client = new SimpleAxisClient();
        Call miaCall = client.getCall(
                "http://localhost:8082/ServicePublisher/services/Interaction","byFiscalCode");
        Document doc = XMLUtils.newDocument(new java.io.ByteArrayInputStream(xmlString.getBytes()));
        System.out.println("doc.getDocumentElement(): " +
                           doc.getDocumentElement().getNodeName());
        Vector result = (Vector) miaCall.invoke
                        (new SOAPBodyElement[] {new SOAPBodyElement(doc.
                getDocumentElement())});
        SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);

        System.out.println( "Ottenuto: "+ XMLUtils.DocumentToString( sbe.getAsDocument() ) );
    }
}

As you can see i have this file xml:

<impl:byFiscalCode xmlns:impl='http://javabean.websrv.napsi.eng.it'>
  <ricercaIndividuo>
          <codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>
  </ricercaIndividuo>
</impl:byFiscalCode>

Now by doing so the method is called... but the document that it receives is the file xml that i have showed before; i'ld like that the document that the operation byFiscalCode accepts is 
  <ricercaIndividuo>
          <codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>
  </ricercaIndividuo>

How can i do?
If i must insert the operation name in the xml ( that is: <impl:byFiscalCode ) why must i use the 

setOperation(new QName(endpoint, operation), operation) method of Call object?
Thanks to all




____________________________________________________________
6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di Libero!
Scaricalo su INTERNET GRATIS 6X http://www.libero.it



Re: Question about Axis1.2RC3

Posted by Anne Thomas Manes <at...@gmail.com>.
Another approach you might take is to create your own provider -- that
way you have complete control over how requests are dispatched.

Anne

On 4/28/05, Anne Thomas Manes <at...@gmail.com> wrote:
> Are you saying that you would like your SOAP message to look like this:
> 
> <env:Body>
>     <ricercaIndividuo>
>          <codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>
>     </ricercaIndividuo>
> </env:Body>
> 
> First -- the child of the <env:Body> element should be namespace
> qualified, so in general, I would say that this is a bad idea. The
> SOAP spec says that the child element MAY be namespace qualified, so,
> technically, it's okay that it isn't, but there's no way to define an
> unqualified element using WSDL, and I don't think that Axis can
> support it.
> 
> The only way that you can define this scenario in WSDL is to use the
> <xsd:any> element:
> 
> <wsdl:message name="byFiscalCodeRequest">
>    <wsdl:part name="body" element="xsd:any/>
> </wsdl:message>
> 
> But then you would not be able to expose multiple operations on the
> service. (Each operation must expose a unique method signature.)
> 
> If you are willing to namespace qualify your message payload, then you
> would be able to define the <ns1:ricercaIndividuo> as your input
> message:
> 
> <wsdl:message name="byFiscalCodeRequest">
>    <wsdl:part name="body" element="ns1:ricercaIndividuo/>
> </wsdl:message>
> 
> But this would only work if the <ns1:ricercaIndividuo> is unique to
> the byFiscalCode operation. If it isn't a unique signature, or if you
> can't namespace qualify the <ricercaIndividuo> element, then you would
> do better to keep the wrapper element that I described before.
> 
> If this is the case, then I suggest that you set up your schema thus:
> 
> <wsdl:types>
>   <xsd:schema targetNamespace="http://javabean.websrv.napsi.eng.it"
>      elementFormDefault="unqualified"/>
>      <xsd:element name="byFiscalCode">
>         <xsd:complexType>
>            <xsd:sequence>
>               <xsd:element name="ricercaIndividuo" type="anyType"/>
>            </xsd:sequence>
>         </xsd:complexType>
>      </xsd:element>
>   </xsd:schema>
> </wsdl:types>
> 
> <wsdl:message name="byFiscalCodeRequest">
>    <wsdl:part name="body" element="impl:byFiscalCode"/>
> </wsdl:message>
> 
> And then use the RPC provider instead of the message provider. Axis
> will then automatically dispatch the request to the proper method for
> you, and it should map the <ricercaIndividuo> element to a DOM for
> you.
> 
> I think that's what you want.
> 
> Anne
> 
> On 4/28/05, angeloimm <an...@libero.it> wrote:
> > Hi all; first of all i want to thank Anne Thomas Manes for her tips.
> > I want to ask a thing i have a web service built in java; it is a java class that has several methods.
> > Now in my axis.wsdd i have added a service like this one:
> >     <service name="Interaction" type="" regenerateElement="false"
> >         provider="java:MSG" style="message" use="literal" validate="false">
> >         <parameter name="scope" value="Request" regenerateElement="false"/>
> >         <parameter name="className"
> >             value="it.eng.napsi.websrv.javabean.Interaction" regenerateElement="false"/>
> >         <parameter name="allowedMethods" value="*" regenerateElement="false"/>
> >         <namespace>http://javabean.websrv.napsi.eng.it</namespace>
> >         <operation name="byFiscalCode"
> >             returnQName="ns1:byFiscalCodeReturn"
> >             returnType="xsd:anyType" qname="ns1:byFiscalCode"
> >             regenerateElement="false" xmlns:ns1="http://javabean.websrv.napsi.eng.it"/>
> >     </service>
> >
> > Now i have this simple client:
> > package it.eng.test.client.util;
> >
> > import org.apache.axis.client.Call;
> > import org.apache.axis.client.Service;
> > import org.apache.axis.message.SOAPBodyElement;
> > import org.apache.axis.message.SOAPBody;
> > import org.apache.axis.utils.XMLUtils;
> > import javax.xml.rpc.ServiceException;
> >
> > import java.util.Vector;
> > import org.w3c.dom.Document;
> > import javax.xml.namespace.QName;
> >
> > import org.apache.log4j.Logger;
> > import java.net.URL;
> > import java.net.MalformedURLException;
> > import javax.xml.parsers.DocumentBuilderFactory;
> > import javax.xml.parsers.DocumentBuilder;
> > import java.util.*;
> >
> > import it.eng.napsi.input.individuo.IndividualMarshaller;
> >
> > public class SimpleAxisClient {
> >     public SimpleAxisClient() {
> >     }
> >
> >     private static final Logger LOG = Logger.getLogger(SimpleAxisClient.class.
> >             getName());
> >
> >     private Call getCall(String endpoint, String operation) throws
> >             ServiceException {
> >
> >         if (LOG.isDebugEnabled()) {
> >
> >             LOG.debug("Creating call.....");
> >         }
> >         Call result = (Call) (new Service()).createCall();
> >         try {
> >             result.setTargetEndpointAddress(new URL(endpoint));
> >
> >         } catch (MalformedURLException ex) {
> >
> >             LOG.error(ex);
> >         }
> >
> >         result.setOperation(new QName(endpoint, operation), operation);
> >         if (LOG.isDebugEnabled()) {
> >
> >             LOG.debug("Done!!");
> >         }
> >         return result;
> >     }
> >
> >     public Document getDocument(Document doc, String endpoint,
> >                                 String operation) throws Exception {
> >         Call call = getCall(endpoint, operation);
> >         Vector result = (Vector) call.invoke(new Object[] {doc});
> >         //Vector result = (Vector) call.invoke(new SOAPBodyElement[] { new SOAPBodyElement( doc.getDocumentElement() )});
> >         SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
> >
> >         if (LOG.isDebugEnabled()) {
> >
> >             LOG.debug("Body ricevuto: " +
> >                       XMLUtils.DocumentToString(sbe.getAsDocument()));
> >         }
> >         return sbe.getAsDocument();
> >     }
> >
> >     public static void main(String args[]) throws Exception {
> >
> >         IndividualMarshaller ind = new IndividualMarshaller();
> >         Map envi = new Hashtable();
> >         envi.put( "codFisc","MMDNGL74C22H703K" );
> >         //String xmlString = ind.toStringDocument( envi );
> >         /*
> >         String xmlString = "<impl:doc xmlns:impl='http://javabean.websrv.napsi.eng.it'>"+
> >                            "<ricercaIndividuo><codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>"+
> >                            "</ricercaIndividuo></impl:doc>";
> >          */
> >         String xmlString = "<impl:byFiscalCod xmlns:impl='http://javabean.websrv.napsi.eng.it'>"+
> >                            "<ricercaIndividuo><codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>"+
> >                            "</ricercaIndividuo></impl:byFiscalCod>";
> >         System.out.println( xmlString );
> >         SimpleAxisClient client = new SimpleAxisClient();
> >         Call miaCall = client.getCall(
> >                 "http://localhost:8082/ServicePublisher/services/Interaction","byFiscalCode");
> >         Document doc = XMLUtils.newDocument(new java.io.ByteArrayInputStream(xmlString.getBytes()));
> >         System.out.println("doc.getDocumentElement(): " +
> >                            doc.getDocumentElement().getNodeName());
> >         Vector result = (Vector) miaCall.invoke
> >                         (new SOAPBodyElement[] {new SOAPBodyElement(doc.
> >                 getDocumentElement())});
> >         SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
> >
> >         System.out.println( "Ottenuto: "+ XMLUtils.DocumentToString( sbe.getAsDocument() ) );
> >     }
> > }
> >
> > As you can see i have this file xml:
> >
> > <impl:byFiscalCode xmlns:impl='http://javabean.websrv.napsi.eng.it'>
> >   <ricercaIndividuo>
> >           <codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>
> >   </ricercaIndividuo>
> > </impl:byFiscalCode>
> >
> > Now by doing so the method is called... but the document that it receives is the file xml that i have showed before; i'ld like that the document that the operation byFiscalCode accepts is
> >   <ricercaIndividuo>
> >           <codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>
> >   </ricercaIndividuo>
> >
> > How can i do?
> > If i must insert the operation name in the xml ( that is: <impl:byFiscalCode ) why must i use the
> >
> > setOperation(new QName(endpoint, operation), operation) method of Call object?
> > Thanks to all
> >
> > ____________________________________________________________
> > 6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di Libero!
> > Scaricalo su INTERNET GRATIS 6X http://www.libero.it
> >
> >
>

Re: Question about Axis1.2RC3

Posted by Anne Thomas Manes <at...@gmail.com>.
Are you saying that you would like your SOAP message to look like this:

<env:Body>
    <ricercaIndividuo>
         <codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>
    </ricercaIndividuo>
</env:Body>

First -- the child of the <env:Body> element should be namespace
qualified, so in general, I would say that this is a bad idea. The
SOAP spec says that the child element MAY be namespace qualified, so,
technically, it's okay that it isn't, but there's no way to define an
unqualified element using WSDL, and I don't think that Axis can
support it.

The only way that you can define this scenario in WSDL is to use the
<xsd:any> element:

<wsdl:message name="byFiscalCodeRequest">
   <wsdl:part name="body" element="xsd:any/>
</wsdl:message>

But then you would not be able to expose multiple operations on the
service. (Each operation must expose a unique method signature.)

If you are willing to namespace qualify your message payload, then you
would be able to define the <ns1:ricercaIndividuo> as your input
message:

<wsdl:message name="byFiscalCodeRequest">
   <wsdl:part name="body" element="ns1:ricercaIndividuo/>
</wsdl:message>

But this would only work if the <ns1:ricercaIndividuo> is unique to
the byFiscalCode operation. If it isn't a unique signature, or if you
can't namespace qualify the <ricercaIndividuo> element, then you would
do better to keep the wrapper element that I described before.

If this is the case, then I suggest that you set up your schema thus:

<wsdl:types>
  <xsd:schema targetNamespace="http://javabean.websrv.napsi.eng.it" 
     elementFormDefault="unqualified"/>
     <xsd:element name="byFiscalCode">
        <xsd:complexType>
           <xsd:sequence>
              <xsd:element name="ricercaIndividuo" type="anyType"/>
           </xsd:sequence>
        </xsd:complexType>
     </xsd:element>
  </xsd:schema>
</wsdl:types>

<wsdl:message name="byFiscalCodeRequest">
   <wsdl:part name="body" element="impl:byFiscalCode"/>
</wsdl:message>

And then use the RPC provider instead of the message provider. Axis
will then automatically dispatch the request to the proper method for
you, and it should map the <ricercaIndividuo> element to a DOM for
you.

I think that's what you want.

Anne
   
On 4/28/05, angeloimm <an...@libero.it> wrote:
> Hi all; first of all i want to thank Anne Thomas Manes for her tips.
> I want to ask a thing i have a web service built in java; it is a java class that has several methods.
> Now in my axis.wsdd i have added a service like this one:
>     <service name="Interaction" type="" regenerateElement="false"
>         provider="java:MSG" style="message" use="literal" validate="false">
>         <parameter name="scope" value="Request" regenerateElement="false"/>
>         <parameter name="className"
>             value="it.eng.napsi.websrv.javabean.Interaction" regenerateElement="false"/>
>         <parameter name="allowedMethods" value="*" regenerateElement="false"/>
>         <namespace>http://javabean.websrv.napsi.eng.it</namespace>
>         <operation name="byFiscalCode"
>             returnQName="ns1:byFiscalCodeReturn"
>             returnType="xsd:anyType" qname="ns1:byFiscalCode"
>             regenerateElement="false" xmlns:ns1="http://javabean.websrv.napsi.eng.it"/>
>     </service>
> 
> Now i have this simple client:
> package it.eng.test.client.util;
> 
> import org.apache.axis.client.Call;
> import org.apache.axis.client.Service;
> import org.apache.axis.message.SOAPBodyElement;
> import org.apache.axis.message.SOAPBody;
> import org.apache.axis.utils.XMLUtils;
> import javax.xml.rpc.ServiceException;
> 
> import java.util.Vector;
> import org.w3c.dom.Document;
> import javax.xml.namespace.QName;
> 
> import org.apache.log4j.Logger;
> import java.net.URL;
> import java.net.MalformedURLException;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.parsers.DocumentBuilder;
> import java.util.*;
> 
> import it.eng.napsi.input.individuo.IndividualMarshaller;
> 
> public class SimpleAxisClient {
>     public SimpleAxisClient() {
>     }
> 
>     private static final Logger LOG = Logger.getLogger(SimpleAxisClient.class.
>             getName());
> 
>     private Call getCall(String endpoint, String operation) throws
>             ServiceException {
> 
>         if (LOG.isDebugEnabled()) {
> 
>             LOG.debug("Creating call.....");
>         }
>         Call result = (Call) (new Service()).createCall();
>         try {
>             result.setTargetEndpointAddress(new URL(endpoint));
> 
>         } catch (MalformedURLException ex) {
> 
>             LOG.error(ex);
>         }
> 
>         result.setOperation(new QName(endpoint, operation), operation);
>         if (LOG.isDebugEnabled()) {
> 
>             LOG.debug("Done!!");
>         }
>         return result;
>     }
> 
>     public Document getDocument(Document doc, String endpoint,
>                                 String operation) throws Exception {
>         Call call = getCall(endpoint, operation);
>         Vector result = (Vector) call.invoke(new Object[] {doc});
>         //Vector result = (Vector) call.invoke(new SOAPBodyElement[] { new SOAPBodyElement( doc.getDocumentElement() )});
>         SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
> 
>         if (LOG.isDebugEnabled()) {
> 
>             LOG.debug("Body ricevuto: " +
>                       XMLUtils.DocumentToString(sbe.getAsDocument()));
>         }
>         return sbe.getAsDocument();
>     }
> 
>     public static void main(String args[]) throws Exception {
> 
>         IndividualMarshaller ind = new IndividualMarshaller();
>         Map envi = new Hashtable();
>         envi.put( "codFisc","MMDNGL74C22H703K" );
>         //String xmlString = ind.toStringDocument( envi );
>         /*
>         String xmlString = "<impl:doc xmlns:impl='http://javabean.websrv.napsi.eng.it'>"+
>                            "<ricercaIndividuo><codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>"+
>                            "</ricercaIndividuo></impl:doc>";
>          */
>         String xmlString = "<impl:byFiscalCod xmlns:impl='http://javabean.websrv.napsi.eng.it'>"+
>                            "<ricercaIndividuo><codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>"+
>                            "</ricercaIndividuo></impl:byFiscalCod>";
>         System.out.println( xmlString );
>         SimpleAxisClient client = new SimpleAxisClient();
>         Call miaCall = client.getCall(
>                 "http://localhost:8082/ServicePublisher/services/Interaction","byFiscalCode");
>         Document doc = XMLUtils.newDocument(new java.io.ByteArrayInputStream(xmlString.getBytes()));
>         System.out.println("doc.getDocumentElement(): " +
>                            doc.getDocumentElement().getNodeName());
>         Vector result = (Vector) miaCall.invoke
>                         (new SOAPBodyElement[] {new SOAPBodyElement(doc.
>                 getDocumentElement())});
>         SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
> 
>         System.out.println( "Ottenuto: "+ XMLUtils.DocumentToString( sbe.getAsDocument() ) );
>     }
> }
> 
> As you can see i have this file xml:
> 
> <impl:byFiscalCode xmlns:impl='http://javabean.websrv.napsi.eng.it'>
>   <ricercaIndividuo>
>           <codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>
>   </ricercaIndividuo>
> </impl:byFiscalCode>
> 
> Now by doing so the method is called... but the document that it receives is the file xml that i have showed before; i'ld like that the document that the operation byFiscalCode accepts is
>   <ricercaIndividuo>
>           <codiceFiscale>XXXXXXXXXXXXX</codiceFiscale>
>   </ricercaIndividuo>
> 
> How can i do?
> If i must insert the operation name in the xml ( that is: <impl:byFiscalCode ) why must i use the
> 
> setOperation(new QName(endpoint, operation), operation) method of Call object?
> Thanks to all
> 
> ____________________________________________________________
> 6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di Libero!
> Scaricalo su INTERNET GRATIS 6X http://www.libero.it
> 
>