📄 soappart.java
字号:
StringBuffer sb = new StringBuffer(); try { while((line = br.readLine()) != null) { sb.append(line); } } catch (IOException e) { throw new SOAPException(Messages.getMessage("couldNotReadFromCharStream"), e); } setCurrentMessage(sb.toString(), FORM_STRING); } } /** * Returns the content of the SOAPEnvelope as a JAXP <CODE> * Source</CODE> object. * @return the content as a <CODE> * javax.xml.transform.Source</CODE> object * @throws SOAPException if the implementation cannot * convert the specified <CODE>Source</CODE> object * @see #setContent(javax.xml.transform.Source) setContent(javax.xml.transform.Source) */ public Source getContent() throws SOAPException { if(contentSource == null) { switch(currentForm) { case FORM_STRING: String s = (String) currentMessage; contentSource = new StreamSource(new StringReader(s)); break; case FORM_INPUTSTREAM: contentSource = new StreamSource((InputStream) currentMessage); break; case FORM_SOAPENVELOPE: SOAPEnvelope se = (SOAPEnvelope) currentMessage; try { contentSource = new DOMSource(se.getAsDocument()); } catch (Exception e) { throw new SOAPException(Messages.getMessage("errorGetDocFromSOAPEnvelope"), e); } break; case FORM_OPTIMIZED: try { ByteArrayInputStream baos = new ByteArrayInputStream(((ByteArray) currentMessage).toByteArray()); contentSource = new StreamSource(baos); } catch (IOException e) { throw new SOAPException(Messages.getMessage("errorGetDocFromSOAPEnvelope"), e); } break; case FORM_BYTES: byte[] bytes = (byte[]) currentMessage; contentSource = new StreamSource(new ByteArrayInputStream(bytes)); break; case FORM_BODYINSTREAM: contentSource = new StreamSource((InputStream) currentMessage); break; } } return contentSource; } /** * Retrieves all the headers for this <CODE>SOAPPart</CODE> * object as an iterator over the <CODE>MimeHeader</CODE> * objects. * @return an <CODE>Iterator</CODE> object with all of the Mime * headers for this <CODE>SOAPPart</CODE> object */ public Iterator getAllMimeHeaders() { return mimeHeaders.getAllHeaders(); } /** * Changes the first header entry that matches the given * header name so that its value is the given value, adding a * new header with the given name and value if no existing * header is a match. If there is a match, this method clears * all existing values for the first header that matches and * sets the given value instead. If more than one header has * the given name, this method removes all of the matching * headers after the first one. * * <P>Note that RFC822 headers can contain only US-ASCII * characters.</P> * @param name a <CODE>String</CODE> giving the * header name for which to search * @param value a <CODE>String</CODE> giving the * value to be set. This value will be substituted for the * current value(s) of the first header that is a match if * there is one. If there is no match, this value will be * the value for a new <CODE>MimeHeader</CODE> object. * @ throws java.lang.IllegalArgumentException if * there was a problem with the specified mime header name * or value * @see #getMimeHeader(java.lang.String) getMimeHeader(java.lang.String) */ public void setMimeHeader(String name, String value) { mimeHeaders.setHeader(name,value); } /** * Gets all the values of the <CODE>MimeHeader</CODE> object * in this <CODE>SOAPPart</CODE> object that is identified by * the given <CODE>String</CODE>. * @param name the name of the header; example: * "Content-Type" * @return a <CODE>String</CODE> array giving all the values for * the specified header * @see #setMimeHeader(java.lang.String, java.lang.String) setMimeHeader(java.lang.String, java.lang.String) */ public String[] getMimeHeader(String name) { return mimeHeaders.getHeader(name); } /** * Removes all the <CODE>MimeHeader</CODE> objects for this * <CODE>SOAPEnvelope</CODE> object. */ public void removeAllMimeHeaders() { mimeHeaders.removeAllHeaders(); } /** * Removes all MIME headers that match the given name. * @param header a <CODE>String</CODE> giving * the name of the MIME header(s) to be removed */ public void removeMimeHeader(String header) { mimeHeaders.removeHeader(header); } /** * Gets the <CODE>SOAPEnvelope</CODE> object associated with * this <CODE>SOAPPart</CODE> object. Once the SOAP envelope is * obtained, it can be used to get its contents. * @return the <CODE>SOAPEnvelope</CODE> object for this <CODE> * SOAPPart</CODE> object * @throws SOAPException if there is a SOAP error */ public javax.xml.soap.SOAPEnvelope getEnvelope() throws SOAPException { try { return getAsSOAPEnvelope(); } catch (AxisFault af) { throw new SOAPException(af); } } /** * Implementation of org.w3c.Document * Most of methods will be implemented using the delgate * instance of SOAPDocumentImpl * This is for two reasons: * - possible change of message classes, by extenstion of xerces implementation * - we cannot extends SOAPPart (multiple inheritance), * since it is defined as Abstract class * *********************************************************** */ private Document document = new SOAPDocumentImpl(this); /** * @since SAAJ 1.2 */ public Document getSOAPDocument(){ if(document == null){ document = new SOAPDocumentImpl(this); } return document; } /** * @return */ public DocumentType getDoctype(){ return document.getDoctype(); } /** * @return */ public DOMImplementation getImplementation(){ return document.getImplementation(); } /** * SOAPEnvelope is the Document Elements of this XML docuement */ protected Document mDocument; public Element getDocumentElement() { try{ return getEnvelope(); }catch(SOAPException se){ return null; } } /** * * @param tagName * @return * @throws DOMException */ public Element createElement(String tagName) throws DOMException { return document.createElement(tagName); } public DocumentFragment createDocumentFragment() { return document.createDocumentFragment(); } public Text createTextNode(String data) { return document.createTextNode(data); } public Comment createComment(String data){ return document.createComment(data); } public CDATASection createCDATASection(String data) throws DOMException { return document.createCDATASection(data); } public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException { return document.createProcessingInstruction(target,data); } public Attr createAttribute(String name)throws DOMException { return document.createAttribute(name); } public EntityReference createEntityReference(String name) throws DOMException { return document.createEntityReference(name); } public NodeList getElementsByTagName(String tagname) { return document.getElementsByTagName(tagname); } public Node importNode(Node importedNode, boolean deep) throws DOMException { return document.importNode(importedNode, deep); } public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException { return document.createElementNS(namespaceURI, qualifiedName); } public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException { return document.createAttributeNS(namespaceURI, qualifiedName); } public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { return document.getElementsByTagNameNS(namespaceURI,localName); } public Element getElementById(String elementId){ return document.getElementById(elementId); } ///////////////////////////////////////////////////////////// public String getEncoding() { return currentEncoding; } public void setEncoding(String s) { currentEncoding = s; } public boolean getStandalone() { throw new UnsupportedOperationException("Not yet implemented.71"); } public void setStandalone(boolean flag) { throw new UnsupportedOperationException("Not yet implemented.72"); } public boolean getStrictErrorChecking() { throw new UnsupportedOperationException("Not yet implemented.73"); } public void setStrictErrorChecking(boolean flag) { throw new UnsupportedOperationException("Not yet implemented. 74"); } public String getVersion() { throw new UnsupportedOperationException("Not yet implemented. 75"); } public void setVersion(String s) { throw new UnsupportedOperationException("Not yet implemented.76"); } public Node adoptNode(Node node) throws DOMException { throw new UnsupportedOperationException("Not yet implemented.77"); } /** * Node Implementation */ public String getNodeName(){ return document.getNodeName(); } public String getNodeValue() throws DOMException { return document.getNodeValue(); } public void setNodeValue(String nodeValue) throws DOMException{ document.setNodeValue(nodeValue); } public short getNodeType() { return document.getNodeType(); } public Node getParentNode(){ return document.getParentNode(); } public NodeList getChildNodes() { return document.getChildNodes(); } public Node getFirstChild() { return document.getFirstChild(); } public Node getLastChild(){ return document.getLastChild(); } public Node getPreviousSibling(){ return document.getPreviousSibling(); } public Node getNextSibling(){ return document.getNextSibling(); } public NamedNodeMap getAttributes(){ return document.getAttributes(); } public Document getOwnerDocument(){ return document.getOwnerDocument(); } public Node insertBefore(Node newChild, Node refChild) throws DOMException { return document.insertBefore(newChild, refChild); } public Node replaceChild(Node newChild, Node oldChild) throws DOMException { return document.replaceChild(newChild, oldChild); } public Node removeChild(Node oldChild) throws DOMException { return document.removeChild(oldChild); } public Node appendChild(Node newChild) throws DOMException { return document.appendChild(newChild); } public boolean hasChildNodes(){ return document.hasChildNodes(); } public Node cloneNode(boolean deep) { return document.cloneNode(deep); } public void normalize(){ document.normalize(); } public boolean isSupported(String feature, String version){ return document.isSupported(feature, version); } public String getNamespaceURI() { return document.getNamespaceURI(); } public String getPrefix() { return document.getPrefix(); } public void setPrefix(String prefix) throws DOMException { document.setPrefix(prefix); } public String getLocalName() { return document.getLocalName(); } public boolean hasAttributes(){ return document.hasAttributes(); } public boolean isBodyStream() { return (currentForm == SOAPPart.FORM_INPUTSTREAM || currentForm == SOAPPart.FORM_BODYINSTREAM); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -