users@jax-rpc.java.net

Re: DII with complex types?

From: YAWN,MICHAEL (HP-Cupertino,ex1) <"YAWN,MICHAEL>
Date: Fri, 12 Apr 2002 18:36:16 -0400

Arun,

Tried implementing serialization for the String[] based on your
example code. Failing with the following error:

---------------------------
invoking getDivisionNames()
Exception in thread "main" HTTP transport error:
java.lang.IllegalArgumentExcept
ion: Illegal MimeHeader name or value
        at
com.sun.xml.rpc.client.http.HttpClientTransport.invoke(HttpClientTran
sport.java:176)
        at
com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:64)

        at
com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.j
ava:49)
        at com.sun.xml.rpc.client.dii.CallImpl.invoke(CallImpl.java:227)
        at nfl.application.jaxrpc_clients.DynamicClient.run(Unknown Source)
        at nfl.application.jaxrpc_clients.DynamicClient.main(Unknown Source)

CAUSE:

java.lang.IllegalArgumentException: Illegal MimeHeader name or value
        at javax.xml.soap.MimeHeaders.setHeader(Unknown Source)
        at
com.sun.xml.rpc.client.http.HttpClientTransport.invoke(HttpClientTran
sport.java:65)
        at
com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:64)

        at
com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.j
ava:49)
        at com.sun.xml.rpc.client.dii.CallImpl.invoke(CallImpl.java:227)
        at nfl.application.jaxrpc_clients.DynamicClient.run(Unknown Source)
        at nfl.application.jaxrpc_clients.DynamicClient.main(Unknown Source)
-------------------------------

Problems like this will sure be hard to track down without some kind of
documentation of the com.sun.xml.rpc.encoding classes -- I have no idea
what the various parameters to many of these calls are doing. Here's
my code, which should be nearly identical to your example:

-- some types
   private static String BODY_NAMESPACE_VALUE =
           "http://hp.com/wsdl";
   private static String ENCODING_STYLE_PROPERTY =
           "javax.xml.rpc.encodingstyle.namespace.uri";
   private static String NS_OUR_TYPES =
           "http://hp.com/types";
-- end types

      // Must register serializers for String[]
      TypeMappingRegistry registry =
         service.getTypeMappingRegistry();
      TypeMapping mapping = registry.getTypeMapping(
         SOAPConstants.URI_NS_SOAP_ENCODING);
      QName stringArrayTypeQname =
         new QName(NS_OUR_TYPES, "ArrayOfstring");
      QName stringArrayElementQname =
         new QName("", "string");
      CombinedSerializer stringSerializer =
         new SimpleTypeSerializer(
                QNAME_TYPE_STRING,
                DONT_ENCODE_TYPE,
                NULLABLE,
                SOAPConstants.URI_NS_SOAP_ENCODING,
                XSDStringEncoder.getInstance());
      CombinedSerializer stringArraySerializer =
         new SimpleTypeArraySerializer(
                QNAME_TYPE_INT,
                ENCODE_TYPE,
                NULLABLE,
                SOAPConstants.URI_NS_SOAP_ENCODING,
                stringArrayElementQname,
                QNAME_TYPE_INT,
                String.class,
                1,
                null,
                (SimpleTypeSerializer) stringSerializer);
      stringArraySerializer=
         new ReferenceableSerializerImpl(
                SERIALIZE_AS_REF, stringArraySerializer);
      SerializerFactory stringArraySerializerFactory =
         new SingletonSerializerFactory(
                stringArraySerializer);
      DeserializerFactory stringArrayDeserializerFactory =
         new SingletonDeserializerFactory(
                stringArraySerializer);
      mapping.register(String[].class,
                           stringArrayTypeQname,
                           stringArraySerializerFactory,
                           stringArrayDeserializerFactory);
      // call getDivisionNames()
      getNamesCall.setPortTypeName(port);
      getNamesCall.setTargetEndpointAddress(endpointAddress);
      getNamesCall.setReturnType(stringArrayTypeQname);
      getNamesCall.setOperationName(
         new QName(BODY_NAMESPACE_VALUE,
                     "getDivisionNames"));

System.out.println("invoking getDivisionNames()");
      String[] divnames = null;
      try {
         divnames = (String[]) getNamesCall.invoke(noparms);
      } catch (RemoteException e) {
         e.printStackTrace(); System.exit(-1);
      }
System.out.println("back from getDivisionNames()");
--------------------------------

Can you see where I've gone wrong in this?

Mike


> -----Original Message-----
> From: Arun Gupta [mailto:arun.gupta_at_SUN.COM]
> Sent: Friday, April 12, 2002 11:57 AM
> To: JAXRPC-INTEREST_at_JAVA.SUN.COM
> Subject: Re: DII with complex types?
>
>
> Hi Michael,
>
> com.sun APIs are all internal to the JAX-RPC implementation. Javadocs
> are available for the standard classes defined by the specification.
>
> Thanks,
> -Arun
>
> YAWN,MICHAEL (HP-Cupertino,ex1) wrote:
>
> >Thanks! This is exactly what I needed.
> >
> >Are there javadocs available for the com.sun.xml.rpc.encoding
> >classes? They aren't included in the docs for either the EA1
> >or EA2 releases. I'd like to create some tables that
> >summarize the API calls.
> >
> >Mike
> >
> >>-----Original Message-----
> >>From: Arun Gupta [mailto:arun.gupta_at_SUN.COM]
> >>Sent: Friday, April 12, 2002 10:43 AM
> >>To: JAXRPC-INTEREST_at_JAVA.SUN.COM
> >>Subject: Re: DII with complex types?
> >>
> >>
> >> Hi Michael,
> >>
> >>Consider the following WSDL (for String[]):
> >>
> >><complexType name="ArrayOfstring">
> >> <complexContent>
> >> <restriction base="soap-enc:Array">
> >> <attribute ref="soap-enc:arrayType"
> >>wsdl:arrayType="string[]" />
> >> </restriction>
> >> </complexContent>
> >></complexType>
> >>
> >>Your DII client code needs to register the serializer for
> String[] in
> >>the type mapping registry. You do it using the following steps:
> >>
> >>1). Include the following import statements in your code:
> >>import javax.xml.rpc.Service;
> >>import javax.xml.rpc.namespace.QName;
> >>import com.sun.xml.rpc.encoding.SimpleTypeSerializer;
> >>import com.sun.xml.rpc.encoding.CombinedSerializer;
> >>import com.sun.xml.rpc.encoding.simpletype.XSDStringEncoder;
> >>import com.sun.xml.rpc.encoding.SimpleTypeArraySerializer;
> >>import com.sun.xml.rpc.encoding.ReferenceableSerializerImpl;
> >>import com.sun.xml.rpc.encoding.SingletonSerializerFactory;
> >>import com.sun.xml.rpc.encoding.SingletonDeserializerFactory;
> >>import javax.xml.rpc.encoding.SerializerFactory;
> >>import javax.xml.rpc.encoding.DeserializerFactory;
> >>
> >>2). Your client class should implement the following interfaces:
> >>
> >>com.sun.xml.rpc.encoding.SerializerConstants
> >>com.sun.xml.rpc.wsdl.document.schema.SchemaConstants
> >>
> >>3). You need to register the serializers for String[]:
> >>
> >>Service service = factory.createService(new QName("service-name"));
> >>TypeMappingRegistry registry = service.getTypeMappingRegistry();
> >>TypeMapping typeMapping =
> >>registry.getTypeMapping(SOAPConstants.URI_ENCODING);
> >>QName stringArrayTypeQname = new QName( "http://foo.bar/types" ,
> >>"ArrayOfstring");
> >>QName stringArrayElementQname = new QName("", "string");
> >>CombinedSerializer stringSerializer = new
> >>SimpleTypeSerializer(QNAME_TYPE_STRING, DONT_ENCODE_TYPE, NULLABLE,
> >>SOAPConstants.URI_ENCODING, XSDStringEncoder.getInstance());
> >>CombinedSerializer stringArraySerializer = new
> >>SimpleTypeArraySerializer(QNAME_TYPE_INT, ENCODE_TYPE, NULLABLE,
> >>SOAPConstants.URI_ENCODING, stringArrayElementQname, QNAME_TYPE_INT,
> >>String.class, 1, null, (SimpleTypeSerializer)stringSerializer);
> >>stringArraySerializer = new
> >>ReferenceableSerializerImpl(SERIALIZE_AS_REF,
> stringArraySerializer);
> >>SerializerFactory stringArraySerializerFactory = new
> >>SingletonSerializerFactory(stringArraySerializer);
> >>DeserializerFactory stringArrayDeserializerFactory = new
> >>SingletonDeserializerFactory(stringArraySerializer);
> >>typeMapping.register(String[].class, stringArrayTypeQname,
> >>boxedByteArraySerializerFactory, boxedByteArrayDeserializerFactory);
> >>
> >>4). Finally invoke the method on the port:
> >>
> >>QName port = new QName(YOUR_PORT);
> >>Call call = newCall(service, port);
> >>call.setReturnType(stringArrayTypeQname);
> >>call.setOperationName(new QName( "http://foo.bar/wsdl" ,
> >>"getStringArray"));
> >>String[] stringArray = (String[])call.invoke(new Object[0]);
> >>
> >>You can repeat the same steps for any other complex type
> >>defined by your
> >>WSDL.
> >>
> >>Thanks for your interest in JAX-RPC.
> >>
> >>Regards,
> >>-Arun
> >>
> >>YAWN,MICHAEL (HP-Cupertino,ex1) wrote:
> >>
> >>>Hi,
> >>>
> >>>I've gotten an example of DII to work, following the
> tutorial almost
> >>>exactly.
> >>>Now, I want to call two methods that return array types. One is an
> >>>array of Strings, the other an array of a complex data type
> >>>
> >>defined in
> >>
> >>>the WSDL.
> >>>
> >>>These data types are known in the WSDL -- is there some mechanism
> >>>to make them visible to the DII Client so I can use them as return
> >>>types?
> >>>
> >>>Thanks,
> >>>Mike
> >>>
> >>--
> >>=============================================
> >>There is only one me, I must live myself!
> >>There is only one today, I must live itself!
> >>=============================================
> >>http://members.tripod.com/~apgupta/index.html
> >>=============================================
> >>
>
> --
> =============================================
> There is only one me, I must live myself!
> There is only one today, I must live itself!
> =============================================
> http://members.tripod.com/~apgupta/index.html
> =============================================
>