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 Anne Thomas Manes <at...@gmail.com> on 2006/03/27 16:09:08 UTC

Re: Using Document Model axis client to talk to a Perl

Did you check out the resources cited in the Wiki?
http://wiki.apache.org/ws/FrontPage/Axis/CastorWithAxis

Anne

ps -- the Apache SOAP project has been dormant for about 4 years.

On 3/27/06, Steve Pitchford <st...@metalogicplc.com> wrote:
>
>
> I'm terribly sorry if this is a FAQ - I've been hunting for a few days
> now,
> and have not had much luck.
>
> I've been using Apache::Soap to talk to a soap::lite mod_perl server, and
> up till now I've been using RPC and, what I have to say is a bit of a
> hack.
>
> ( In my defence its been a prototype ). I'm trying to get an axis client
> to send a document style soap request, containing a body generated by
> a marshalled castor object.
>
> A typical call in the client ( using Apache Soap ) uses like something
> as follows:
>
> public Object simple_object_send ( String request, Object o, Class c )
> throws Exception
> {
>     Call call = generateCall();
>     call.setTargetObjectURI("urn:"+Package());
>     call.setMethodName( request );
>     call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>
>     // format object
>
>     StringWriter writer = new StringWriter();
>     Marshaller.marshal(o, writer);
>     String s = writer.toString();
>
>     Vector params = new Vector();
>     params.addElement(new Parameter("p1", String.class, s, null));
>     call.setParams (params);
>     Response resp = call.invoke(serverURL(), "" );
>
>     if (resp != null && !resp.generatedFault())
>     {
>         Parameter result = resp.getReturnValue();
>         Object value = result.getValue();
>         String resultstring = new String (value.toString());
>         // And Call Castor
>         java.io.StringReader s_out = new java.io.StringReader(
> resultstring );
>         Object o_out = Unmarshaller.unmarshal(c,s_out);
>         return o_out;
>     }
>     else
>     {
>         Fault fault = resp.getFault ();
>         String flt = new String("Generated fault: \n Fault Code = "+
> fault.getFaultCode()+"\n Fault Message: "+fault.getFaultString());
>         Exception e = new Exception(flt);
>         throw e;
>     }
> }
>
> As I said earlier - a bit of a hack. It doesn't seem to cope to well
> with certain unicode charactors
> such as the pound sign ( as in GBP ) - presumably due to UTF-8 and
> UTF-16 issues and the use of the
> StringWriter to grab the Marshalled xml.
>
> So in order to move on I looked at using a custom serializer, again,
> using castor ( I also tried
> Section 5 ). I came across issues, as one of the java side components
> was populating one of the
> with attributes with java: xml namespace, but the name space wasn't
> defined in the soap message,
> the perl server refused to decode it and spat back an error at me ( The
> code is abbreviated below: )
>
> public class CastorSerializer implements Serializer, Deserializer{
>
>
>     public void marshall(String string, Class aClass, Object object,
> Object object0, Writer writer, NSStack nSStack, XMLJavaMappingRegistry
> xMLJavaMappingRegistry, SOAPContext sOAPContext) throws
> IllegalArgumentException, IOException
>     {
>
>             Marshaller mars = new Marshaller(writer);
>             mars.setSupressXMLDeclaration(true);
>             mars.marshal(object);
>     }
>
> }
>
> And then, in practise:
>
>     Vector params = new Vector();
>     CastorSerializer castorSerializer = new CastorSerializer();
>
>     SOAPMappingRegistry smr = new SOAPMappingRegistry();
>     org.apache.soap.encoding.soapenc.BeanSerializer beanSer = new
> org.apache.soap.encoding.soapenc.BeanSerializer();
>     smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("urn:ns",
> c.toString()), c, beanSer, beanSer);
>
>     call.setSOAPMappingRegistry(registry);
>     call.setSOAPMappingRegistry(smr);
>
>     params.addElement(new Parameter( "Object", message.getClass(),
> message, null ));
>
>     call.setParams (params);
>
>     Response resp = null;
>         resp = call.invoke(serverURL(), "" );
>
> I then decided to look at Axis ( as it seemed the natural successor to
> SOAP ) and after a bit of
> uncertainty plugged for version 1.3.
>
> I've read the Castor/Axis article at:
>
> http://www-128.ibm.com/developerworks/webservices/library/ws-castor/
>
> And followed it to Listing 8. "First attempt at a client for the
> StockQuote service". The example code
> still doesn't appreciatte the aforementioned signs too much, but I think
> a way foward might be to use
> the technique which proved successfull with regards to the custom
> serialiser used with Apache SOAP.
> I'm not having a great deal of luck progressing this though.
>
> Any assistance or pointers you could offer would be much appreciatted.
>
> Cheers,
>
> Steve
>
>