⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soappart.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            return (byte[])currentMessage;        }        if ( currentForm == FORM_BODYINSTREAM ) {            try {                getAsSOAPEnvelope();            } catch (Exception e) {                log.fatal(Messages.getMessage("makeEnvFail00"), e);                log.debug("Exit: SOAPPart::getAsBytes");                return null;            }        }        if ( currentForm == FORM_INPUTSTREAM ) {            // Assumes we don't need a content length            try {                InputStream  inp = null;                byte[]  buf = null;                try{                    inp = (InputStream) currentMessage ;                    ByteArrayOutputStream  baos = new ByteArrayOutputStream();                    buf = new byte[4096];                    int len ;                    while ( (len = inp.read(buf,0,4096)) != -1 )                        baos.write( buf, 0, len );                    buf = baos.toByteArray();                }finally{                  if(inp != null &&                    currentMessage instanceof org.apache.axis.transport.http.SocketInputStream )                    inp.close();                }                setCurrentForm( buf, FORM_BYTES );                log.debug("Exit: SOAPPart::getAsBytes");                return (byte[])currentMessage;            }            catch( Exception e ) {                log.error(Messages.getMessage("exception00"), e);            }            log.debug("Exit: SOAPPart::getAsBytes");            return null;        }        if ( currentForm == FORM_SOAPENVELOPE ||             currentForm == FORM_FAULT ){            currentEncoding = XMLUtils.getEncoding(msgObject, null);            ByteArrayOutputStream baos = new ByteArrayOutputStream();            BufferedOutputStream os = new BufferedOutputStream(baos);            try {                this.writeTo(os);                os.flush();            } catch (Exception e) {                throw AxisFault.makeFault(e);            }            setCurrentForm(baos.toByteArray(), FORM_BYTES);            if (log.isDebugEnabled()) {                log.debug("Exit: SOAPPart::getAsBytes(): " + currentMessage);            }            return (byte[]) currentMessage;        }        if ( currentForm == FORM_STRING ) {            // If the current message was already converted from            // a byte[] to String, return the byte[] representation            // (this is done to avoid unnecessary conversions)            if (currentMessage == currentMessageAsString &&                currentMessageAsBytes != null) {                if (log.isDebugEnabled()) {                    log.debug("Exit: SOAPPart::getAsBytes()");                }                return currentMessageAsBytes;            }            // Save this message in case it is requested later in getAsString            currentMessageAsString = (String) currentMessage;            try{                currentEncoding = XMLUtils.getEncoding(msgObject, null);                setCurrentForm( ((String)currentMessage).getBytes(currentEncoding),                    FORM_BYTES );            }catch(UnsupportedEncodingException ue){               setCurrentForm( ((String)currentMessage).getBytes(),                               FORM_BYTES );            }            currentMessageAsBytes = (byte[]) currentMessage;            log.debug("Exit: SOAPPart::getAsBytes");            return (byte[])currentMessage;        }        log.error(Messages.getMessage("cantConvert00", ""+currentForm));        log.debug("Exit: SOAPPart::getAsBytes");        return null;    }    public void saveChanges() throws AxisFault {        log.debug("Enter: SOAPPart::saveChanges");        if ( currentForm == FORM_SOAPENVELOPE ||             currentForm == FORM_FAULT ){            currentEncoding = XMLUtils.getEncoding(msgObject, null);            ByteArray array = new ByteArray();            try {            	writeTo(array);                array.flush();            } catch (Exception e) {                throw AxisFault.makeFault(e);            }            setCurrentForm( array, FORM_OPTIMIZED );            if (log.isDebugEnabled()) {                log.debug("Exit: SOAPPart::saveChanges(): " + currentMessage);            }        }    }    /**     * Get the contents of this Part (not the headers!), as a String.     * This will force buffering of the message.     *     * @return a <code>String</code> containing the content of this message     * @throws AxisFault  if there is an error serializing this part     */    public String getAsString() throws AxisFault {        log.debug("Enter: SOAPPart::getAsString");        if ( currentForm == FORM_STRING ) {            if (log.isDebugEnabled()) {                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);            }            return (String)currentMessage;        }        if ( currentForm == FORM_INPUTSTREAM ||             currentForm == FORM_BODYINSTREAM ) {            getAsBytes();            // Fall thru to "Bytes"        }        if ( currentForm == FORM_OPTIMIZED) {            try {                currentMessageAsBytes =                        ((ByteArray) currentMessage).toByteArray();            } catch (IOException e) {                throw AxisFault.makeFault(e);            }            try{                setCurrentForm(new String((byte[])currentMessageAsBytes,                                currentEncoding),                        FORM_STRING);            }catch(UnsupportedEncodingException ue){                setCurrentForm( new String((byte[]) currentMessageAsBytes),                                   FORM_STRING );            }            if (log.isDebugEnabled()) {                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);            }            return (String)currentMessage;        }        if ( currentForm == FORM_BYTES ) {            // If the current message was already converted from            // a String to byte[], return the String representation            // (this is done to avoid unnecessary conversions)            if (currentMessage == currentMessageAsBytes &&                currentMessageAsString != null) {                if (log.isDebugEnabled()) {                    log.debug("Exit: SOAPPart::getAsString(): " + currentMessageAsString);                }                return currentMessageAsString;            }                        // Save this message in case it is requested later in getAsBytes            currentMessageAsBytes = (byte[]) currentMessage;            try{                setCurrentForm(new String((byte[])currentMessage,                                currentEncoding),                        FORM_STRING);            }catch(UnsupportedEncodingException ue){                setCurrentForm( new String((byte[]) currentMessage),                                   FORM_STRING );            }            currentMessageAsString = (String) currentMessage;            if (log.isDebugEnabled()) {                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);            }            return (String)currentMessage;        }        if ( currentForm == FORM_FAULT ) {            StringWriter writer = new StringWriter();            try {                this.writeTo(writer);            } catch (Exception e) {                log.error(Messages.getMessage("exception00"), e);                return null;            }            setCurrentForm(writer.getBuffer().toString(), FORM_STRING);            if (log.isDebugEnabled()) {                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);            }            return (String)currentMessage;        }        if ( currentForm == FORM_SOAPENVELOPE ) {            StringWriter writer = new StringWriter();            try {                this.writeTo(writer);            } catch (Exception e) {                throw AxisFault.makeFault(e);            }            setCurrentForm(writer.getBuffer().toString(), FORM_STRING);            if (log.isDebugEnabled()) {                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);            }            return (String)currentMessage;        }        log.error( Messages.getMessage("cantConvert01", ""+currentForm));        log.debug("Exit: SOAPPart::getAsString()");        return null;    }    /**     * Get the contents of this Part (not the MIME headers!), as a     * SOAPEnvelope.  This will force a complete parse of the     * message.     *     * @return a <code>SOAPEnvelope</code> containing the message content     * @throws AxisFault if the envelope could not be constructed     */    public SOAPEnvelope getAsSOAPEnvelope()        throws AxisFault    {        if (log.isDebugEnabled()) {            log.debug("Enter: SOAPPart::getAsSOAPEnvelope()");            log.debug(Messages.getMessage("currForm", formNames[currentForm]));        }        if ( currentForm == FORM_SOAPENVELOPE )            return (SOAPEnvelope)currentMessage;        if (currentForm == FORM_BODYINSTREAM) {            InputStreamBody bodyEl =                             new InputStreamBody((InputStream)currentMessage);            SOAPEnvelope env = new SOAPEnvelope();            env.setOwnerDocument(this);            env.addBodyElement(bodyEl);            setCurrentForm(env, FORM_SOAPENVELOPE);            return env;        }        InputSource is;        if ( currentForm == FORM_INPUTSTREAM ) {            is = new InputSource( (InputStream) currentMessage );            String encoding = XMLUtils.getEncoding(msgObject, null, null);            if (encoding != null) {                currentEncoding = encoding;                is.setEncoding(currentEncoding);            }        } else {            is = new InputSource(new StringReader(getAsString()));        }        DeserializationContext dser = new DeserializationContext(is,                                           getMessage().getMessageContext(),                                           getMessage().getMessageType());        dser.getEnvelope().setOwnerDocument(this);        // This may throw a SAXException        try {            dser.parse();        } catch (SAXException e) {            Exception real = e.getException();            if (real == null)                real = e;            throw AxisFault.makeFault(real);        }        SOAPEnvelope nse= dser.getEnvelope();        if(currentMessageAsEnvelope != null){          //Need to synchronize back processed header info.          Vector newHeaders= nse.getHeaders();          Vector oldHeaders= currentMessageAsEnvelope.getHeaders();          if( null != newHeaders && null != oldHeaders){           Iterator ohi= oldHeaders.iterator();           Iterator nhi= newHeaders.iterator();           while( ohi.hasNext() && nhi.hasNext()){             SOAPHeaderElement nhe= (SOAPHeaderElement)nhi.next();             SOAPHeaderElement ohe= (SOAPHeaderElement)ohi.next();             if(ohe.isProcessed()) nhe.setProcessed(true);           }          }        }        setCurrentForm(nse, FORM_SOAPENVELOPE);        log.debug("Exit: SOAPPart::getAsSOAPEnvelope");        SOAPEnvelope env = (SOAPEnvelope)currentMessage;        env.setOwnerDocument(this);        return env;    }    /**     * Add the specified MIME header, as per JAXM.     *     * @param header  the header to add     * @param value   the value of that header     */    public void addMimeHeader (String header, String value) {        mimeHeaders.addHeader(header, value);    }    /**     * Get the specified MIME header.     *     * @param header  the name of a MIME header     * @return the value of the first header named <code>header</code>     */    private String getFirstMimeHeader (String header) {        String[] values = mimeHeaders.getHeader(header);        if(values != null && values.length>0)            return values[0];        return null;    }    /**     * Total size in bytes (of all content and headers, as encoded).    public abstract int getSize();     */    /**     * Content location.     *     * @return the content location     */    public String getContentLocation() {        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION);    }    /**     * Set content location.     *     * @param loc  the content location     */    public void setContentLocation(String loc) {        setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);    }    /**     * Sets Content-Id of this part.     *  already defined.     * @param newCid new Content-Id     */    public void setContentId(String newCid){        setMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid);    }    /**     * Content ID.     *     * @return the content ID     */    public String getContentId() {        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);    }    /**     * Content ID.     *     * @return the contentId reference value that should be used directly     * as an href in a SOAP element to reference this attachment.     * <B>Not part of JAX-RPC, JAX-M, SAAJ, etc. </B>     */    public String getContentIdRef() {      return org.apache.axis.attachments.Attachments.CIDprefix +         getContentId();    }    /**     * Get all headers that match.     *     * @param match  an array of <code>String</code>s giving mime header names     * @return an <code>Iterator</code> over all values matching these headers     */    public java.util.Iterator getMatchingMimeHeaders( final String[] match){        return mimeHeaders.getMatchingHeaders(match);    }    /**     * Get all headers that do not match.     *     * @param match  an array of <code>String</code>s giving mime header names     * @return an <code>Iterator</code> over all values not matching these     *          headers     */    public java.util.Iterator getNonMatchingMimeHeaders( final String[] match){        return mimeHeaders.getNonMatchingHeaders(match);    }    /**     * Sets the content of the <CODE>SOAPEnvelope</CODE> object     * with the data from the given <CODE>Source</CODE> object.     * @param   source javax.xml.transform.Source</CODE> object with the data to     *     be set     * @throws  SOAPException if there is a problem in     *     setting the source     * @see #getContent() getContent()     */    public void setContent(Source source) throws SOAPException {        if(source == null)            throw new SOAPException(Messages.getMessage("illegalArgumentException00"));        // override the checks in HandlerChainImpl for JAXRPCHandler kludge        MessageContext ctx = getMessage().getMessageContext();        if (ctx != null) {            ctx.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION,                Boolean.TRUE);        }        contentSource = source;        InputSource in = org.apache.axis.utils.XMLUtils.sourceToInputSource(contentSource);        InputStream is = in.getByteStream();        if(is != null) {            setCurrentMessage(is, FORM_INPUTSTREAM);        } else {            Reader r = in.getCharacterStream();            if(r == null) {                throw new SOAPException(Messages.getMessage("noCharacterOrByteStream"));            }            BufferedReader br = new BufferedReader(r);            String line = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -