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 Brosca Diana <Di...@atosorigin.com> on 2005/12/07 13:11:12 UTC

R: Web service with Attachment Problem

Hello Wade 
Firstly thanks for your help. 
Then, I'm trying to implement a web service with a WSDL as you have
indicated. 

The type: 

        <xs:schema xmlns:xs=" http://www.w3.org/2001/XMLSchema
<http://www.w3.org/2001/XMLSchema> " targetNamespace="
http://vbl.wservices.nomadic.atosorigin.com/ReceiverFileServiceInput
<http://vbl.wservices.nomadic.atosorigin.com/ReceiverFileServiceInput> "
elementFormDefault="qualified">

                <xs:complexType name="NodeDocument"> 
                <xs:sequence> 
                        <xs:element name="name" type="xsd:string"
default="Your document name"/> 
                        <xs:element name="type" type="xsd:string"/> 
                <xs:element name="content" type="xsd:base64Binary"/> 
                </xs:sequence> 
        </xs:complexType> 
</xs:schema> 



become in java: 


public class NodeDocument  implements java.io.Serializable { 
    private java.lang.String name; 
    private java.lang.String type; 
    private byte[] content; 

    public NodeDocument() { 
    } 

...... 
} 


I haven't a Object type but a byte[] type. Can I use the
javax.activation.DataHandler again? 

Moreover, how I can read the attachment in the
ReceiverFileBindingImplClass 
 that implements the web service? 


public class ReceiverFileBindingImpl implements
com.atosorigin.nomadic.wservices.ReceiverFilewebservice.ReceiverFilePort
Type{

        public java.lang.String
receiverFileOperation(com.atosorigin.nomadic.wservices.vbl.ReceiverFileS
erviceInput.NodeDocument in) throws java.rmi.RemoteException,
com.atosorigin.nomadic.wservices.vbl.FaultMessages.FaultMessage {

        
        return null; 
    } 

} 

Have you a example of this? 

Thanks for your help 

Diana 







Re: R: Web service with Attachment Problem

Posted by Wade Chandler <hw...@yahoo.com>.
Comments inline...

--- Brosca Diana <Di...@atosorigin.com> wrote:

> Hello Wade 
> Firstly thanks for your help. 
> Then, I'm trying to implement a web service with a
> WSDL as you have
> indicated. 
> 
> The type: 
> 
>         <xs:schema xmlns:xs="
> http://www.w3.org/2001/XMLSchema
> <http://www.w3.org/2001/XMLSchema> "
> targetNamespace="
>
http://vbl.wservices.nomadic.atosorigin.com/ReceiverFileServiceInput
>
<http://vbl.wservices.nomadic.atosorigin.com/ReceiverFileServiceInput>
> "
> elementFormDefault="qualified">
> 
>                 <xs:complexType name="NodeDocument">
> 
>                 <xs:sequence> 
>                         <xs:element name="name"
> type="xsd:string"
> default="Your document name"/> 
>                         <xs:element name="type"
> type="xsd:string"/> 
>                 <xs:element name="content"
> type="xsd:base64Binary"/> 
>                 </xs:sequence> 
>         </xs:complexType> 
> </xs:schema> 
> 
> 
> 
> become in java: 
> 
> 
> public class NodeDocument  implements
> java.io.Serializable { 
>     private java.lang.String name; 
>     private java.lang.String type; 
>     private byte[] content; 
> 
>     public NodeDocument() { 
>     } 
> 
> ...... 
> } 
> 
> 
> I haven't a Object type but a byte[] type. Can I use
> the
> javax.activation.DataHandler again? 
> 
You have to change the byte[] to Object.  Then you'll
have to modify the equals method if it generated one
for you.  You will also have to add activation.jar and
mail.jar to your web-app/axis server.


> Moreover, how I can read the attachment in the
> ReceiverFileBindingImplClass 
>  that implements the web service? 
> 
> 
> public class ReceiverFileBindingImpl implements
>
com.atosorigin.nomadic.wservices.ReceiverFilewebservice.ReceiverFilePort
> Type{
> 
>         public java.lang.String
>
receiverFileOperation(com.atosorigin.nomadic.wservices.vbl.ReceiverFileS
> erviceInput.NodeDocument in) throws
> java.rmi.RemoteException,
>
com.atosorigin.nomadic.wservices.vbl.FaultMessages.FaultMessage
> {
> 
>         
>         return null; 
>     } 
> 
> } 
> 
> Have you a example of this? 

Yes.  You will do something like this method which I
use to dump the attachments off into FileDataSources
on the remote side....I do this because I process info
in other threads after the axis call has finished and
the ManagedMemoryDataSource gets cleaned up by axis,
so the data is lost if you do processing later and
don't dump to some temporary space....this is an
example from some stuff I'm doing for
www.exchangenetwork.net for the state of South
Carolina...it's in production and working fine.

    /**
     *Method used to dump ManagedMemoryDataSources off
into a temp file.  This is needed because
     *these types of files will not be available after
the axis web service is called.  This is important
mainly
     *for submits because they will be operating on
data in a thread after the call has went away.  This
means
     *we have to put the data some where safe before
we try to process it or return the transaction id. 
This method
     *moves the data into temp submit files which are
marked to be deleted when the jvm exits.
     *@param documents the node documents to replace
the ManagedMemoryDataSources for.
     *@throws Throwable thrown on any error
     */
    public static void
submitPrepNodeDocuments(gov.epa.cdx.axis.v10.vo.NodeDocument[]
documents)
    throws Throwable {
        log.debug("[submitPrepNodeDocuments] entering
method");
        if( documents != null && documents.length > 0
) {
            log.debug("[submitPrepNodeDocuments] there
are documents available");
            log.debug("[submitPrepNodeDocuments]
preparing to loop documents");
            for(int i = 0; i < documents.length; i++)
{
                NodeDocument doc = documents[i];
                if( doc != null ) {
                   
log.debug("[submitPrepNodeDocuments] doc " + i + "
isn't null");
                    Object content = doc.getContent();
                    if( content != null ) {
                       
log.debug("[submitPrepNodeDocuments] the document
content is not null");
                        if( content instanceof
AttachmentPart ) {
                           
log.debug("[submitPrepNodeDocuments] the document
content is of type AttachmentPart");
                            AttachmentPart part =
(AttachmentPart)content;
                           
log.debug("[submitPrepNodeDocuments] getting
attachments DataHandler and setting content to that
type");
                            content =
part.getDataHandler();
                        }
                        if( content instanceof
DataHandler ) {
                           
log.debug("[submitPrepNodeDocuments] content is of
type DataHandler");
                            if( content != null ) {
                               
log.debug("[submitPrepNodeDocuments] content as
DataHandler is not null");
                               
log.debug("[submitPrepNodeDocuments] setting content
to the DataHandler's DataSource");
                                content =
((DataHandler)content).getDataSource();
                                if( content != null )
{
                                   
log.debug("[submitPrepNodeDocuments] the data source
is not null");
                                    if( content
instanceof ManagedMemoryDataSource ) {
                                       
log.debug("[submitPrepNodeDocuments] the data source
is a ManagedMemoryDataSource");
                                       
ManagedMemoryDataSource mm =
(ManagedMemoryDataSource)content;
                                       
log.debug("[submitPrepNodeDocuments] getting the data
source input stream");
                                        InputStream in
= mm.getInputStream();
                                       
FileOutputStream out = null;
                                        if( in != null
) {
                                           
log.debug("[submitPrepNodeDocuments] the input stream
is not null");
                                            String
fileName =
NodeProperties.getUniqueSubmitFileNameAndPath()
+".tmp";
                                           
log.debug("[submitPrepNodeDocuments] attempting to
create a temp file at '"+fileName+"'");
                                            File file
= new File(fileName).getCanonicalFile();
                                           
file.createNewFile();
                                           
log.debug("[submitPrepNodeDocuments] created empty
file successfully");
                                            //todo see
if we need to create a property to determine if we
should deleteOnExit or not
                                           
log.debug("[submitPrepNodeDocuments] setting file to
delete on exit");
                                           
file.deleteOnExit();
                                           
log.debug("[submitPrepNodeDocuments] creating a file
output stream to the file");
                                           
FileOutputStream fout = new
FileOutputStream(file.getCanonicalPath(), true);
                                            out =
fout;
                                           
BufferedOutputStream bout = new
BufferedOutputStream(fout);
                                           
BufferedInputStream bin = new BufferedInputStream(in);
                                            int iread
= -1;
                                           
log.debug("[submitPrepNodeDocuments] setup input and
output stream successfully");
                                           
log.debug("[submitPrepNodeDocuments] reading the data
source into the temp file");
                                            while(
(iread = bin.read()) > -1 ) {
                                               
bout.write(iread);
                                            }
                                           
bout.flush();
                                           
log.debug("[submitPrepNodeDocuments] read the full
data source successfully");
                                           
NodeDatabase.closeNoThrow(out);
                                           
NodeDatabase.closeNoThrow(in);
                                           
log.debug("[submitPrepNodeDocuments] closed streams");
                                           
log.debug("[submitPrepNodeDocuments] setting up
FileDataSource to temp file");
                                           
FileDataSource fileDataSource = new
FileDataSource(file);
                                           
log.debug("[submitPrepNodeDocuments] file data source
created to '"+fileName+"' successfully.");
                                           
log.debug("[submitPrepNodeDocuments] creating data
handler");
                                           
DataHandler handler = new DataHandler(fileDataSource);
                                           
log.debug("[submitPrepNodeDocuments] created data
handler successfully");
                                           
doc.setContent(handler);
                                           
log.debug("[submitPrepNodeDocuments] set file data
source for document with name '"+doc.getName()+"' to
match file '"+fileName+"'." );
                                        }//end if in
null
                                    }//end if content
instanceof mm data source
                                }//end if content as
data source not null
                            }//end if content as data
handler not null
                        }//end if content instance of
data handler
                    }//end if content not null
                }//end if doc not null
            }//end for loop
        }//end if there are docs
        log.debug("[submitPrepNodeDocuments] exiting
method");
    }

> 
> Thanks for your help 
> 
> Diana 
> 
> 
The way I'm showing you how to do this allows you to
basically inline attachments, and I find it simpler in
that it lets you operate directly on your objects and
access the attachments from your own object model. 
You can add attachments in other ways.  See the wiki
at http://wiki.apache.org/ws/FrontPage/Axis for more
information.  Remember too that there are two
attachment formats MIME and DIME, and to interop with
.Net you have to use DIME attachments if using
attachments and .Net.

The AXIS documentation could be much better in this
regard dealing with attachments and serializers.  For
the most part you have to figure it out by the source
code and statements about other parts of the code
a.k.a (reading wikis and how-tos).

Wade