You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by "R.Domingo" <ra...@domingo.nl> on 2003/07/06 08:13:51 UTC

urgent encoding problem

I'm currently working on my first production application using soap.
But the last I need to finish is causing problems.

I need to send an image to the server and respond with a
org.w3c.dom.Element.

If I use 'Constants.NS_URI_SOAP_ENC' the images is arriving at my server,
but I can't deserialize the 'org.w3c.dom.Element'.

If I use 'Constants.NS_URI_LITERAL_XML' I can't serialize the image.

This is my code at the client side:

try {
      photoDataSource = new ByteArrayDataSource(
          photoDataStream,
          "application/octet-stream");
      photoDataHandler = new DataHandler(
          photoDataSource);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (photoDataSource!=null && photoDataHandler!=null) {
      // Build the call.
      Call call = new Call();
      call.setSOAPMappingRegistry(soapRegistry);
      call.setTargetObjectURI("urn:PhotoService");
      call.setMethodName("createPhoto");
      call.setEncodingStyleURI(paramEncodingStyleURI);

      Vector params = new Vector();
      params.addElement(
          new Parameter("sessionId", String.class, sessionId,
paramEncodingStyleURI));
      params.addElement(
          new Parameter("publication", String.class, publication,
paramEncodingStyleURI));
      params.addElement(
          new Parameter("size", String.class, size, paramEncodingStyleURI));
      params.addElement(new Parameter( "photoData",
javax.activation.DataHandler.class, photoDataHandler, null));
      call.setParams(params);

      // Invoke the call.
      Response resp;
      try {
        resp = call.invoke(soapRouterUrl, "");
      } catch (SOAPException e) {
        System.err.println("Caught SOAPException (" +
            e.getFaultCode() + "): " +
            e.getMessage());
        return null;
      }



Re: urgent encoding problem

Posted by Barry White <ba...@thisbloke.com>.
Hello,

I'm pretty new to SOAP too so don'tknow how much help I'll be. I have been 
succesfully sending images with Apache SOAP using the byte array serializer 
but I don't know much about the server side  - except that it's happy with 
what I'm sending!

I've found the following link quite useful:
http://www-106.ibm.com/developerworks/webservices/library/ws-soapmap1/

I've noticed that DataHandler types use the MimePartSerializer and byte[]'s 
the base64Serializer.

Are you using SOAP with attachments?

Barry


At 07:13 06/07/2003, you wrote:
>I'm currently working on my first production application using soap.
>But the last I need to finish is causing problems.
>
>I need to send an image to the server and respond with a
>org.w3c.dom.Element.
>
>If I use 'Constants.NS_URI_SOAP_ENC' the images is arriving at my server,
>but I can't deserialize the 'org.w3c.dom.Element'.
>
>If I use 'Constants.NS_URI_LITERAL_XML' I can't serialize the image.
>
>This is my code at the client side:
>
>try {
>       photoDataSource = new ByteArrayDataSource(
>           photoDataStream,
>           "application/octet-stream");
>       photoDataHandler = new DataHandler(
>           photoDataSource);
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
>
>     if (photoDataSource!=null && photoDataHandler!=null) {
>       // Build the call.
>       Call call = new Call();
>       call.setSOAPMappingRegistry(soapRegistry);
>       call.setTargetObjectURI("urn:PhotoService");
>       call.setMethodName("createPhoto");
>       call.setEncodingStyleURI(paramEncodingStyleURI);
>
>       Vector params = new Vector();
>       params.addElement(
>           new Parameter("sessionId", String.class, sessionId,
>paramEncodingStyleURI));
>       params.addElement(
>           new Parameter("publication", String.class, publication,
>paramEncodingStyleURI));
>       params.addElement(
>           new Parameter("size", String.class, size, paramEncodingStyleURI));
>       params.addElement(new Parameter( "photoData",
>javax.activation.DataHandler.class, photoDataHandler, null));
>       call.setParams(params);
>
>       // Invoke the call.
>       Response resp;
>       try {
>         resp = call.invoke(soapRouterUrl, "");
>       } catch (SOAPException e) {
>         System.err.println("Caught SOAPException (" +
>             e.getFaultCode() + "): " +
>             e.getMessage());
>         return null;
>       }



Re: urgent encoding problem

Posted by Scott Nichol <sn...@scottnichol.com>.
To do what you are trying to do with Apache SOAP, you would need to 
write a serializer for Element.  As you have experienced, Apache SOAP 
lets you [de-]serialize an Element through its custom literal XML 
encoding.  When using literal XML, you can only [de-]serialize 
Element.  For standard SOAP encoding, there is no Element serializer.

The standard workarounds are to use either (1) the XML as a string or 
(2) Java classes appropriate for your problem domain, instead of 
Element.

On 6 Jul 2003 at 8:13, R.Domingo wrote:

> I'm currently working on my first production application using soap.
> But the last I need to finish is causing problems.
> 
> I need to send an image to the server and respond with a
> org.w3c.dom.Element.
> 
> If I use 'Constants.NS_URI_SOAP_ENC' the images is arriving at my server,
> but I can't deserialize the 'org.w3c.dom.Element'.
> 
> If I use 'Constants.NS_URI_LITERAL_XML' I can't serialize the image.
> 
> This is my code at the client side:
> 
> try {
>       photoDataSource = new ByteArrayDataSource(
>           photoDataStream,
>           "application/octet-stream");
>       photoDataHandler = new DataHandler(
>           photoDataSource);
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
> 
>     if (photoDataSource!=null && photoDataHandler!=null) {
>       // Build the call.
>       Call call = new Call();
>       call.setSOAPMappingRegistry(soapRegistry);
>       call.setTargetObjectURI("urn:PhotoService");
>       call.setMethodName("createPhoto");
>       call.setEncodingStyleURI(paramEncodingStyleURI);
> 
>       Vector params = new Vector();
>       params.addElement(
>           new Parameter("sessionId", String.class, sessionId,
> paramEncodingStyleURI));
>       params.addElement(
>           new Parameter("publication", String.class, publication,
> paramEncodingStyleURI));
>       params.addElement(
>           new Parameter("size", String.class, size, paramEncodingStyleURI));
>       params.addElement(new Parameter( "photoData",
> javax.activation.DataHandler.class, photoDataHandler, null));
>       call.setParams(params);
> 
>       // Invoke the call.
>       Response resp;
>       try {
>         resp = call.invoke(soapRouterUrl, "");
>       } catch (SOAPException e) {
>         System.err.println("Caught SOAPException (" +
>             e.getFaultCode() + "): " +
>             e.getMessage());
>         return null;
>       }
> 
> 
> 


Scott Nichol

Do not reply directly to this e-mail address,
as it is filtered to only receive e-mail from
specific mailing lists.