|
Axis 2 example source code file (SOAPPart.java)
This example Axis 2 source code file (SOAPPart.java) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The Axis 2 SOAPPart.java source code
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package javax.xml.soap;
import javax.xml.transform.Source;
import java.util.Iterator;
/**
* <P>The container for the SOAP-specific portion of a SOAPMessage object. All
* messages are required to have a SOAP part, so when a <CODE>SOAPMessage object is created,
* it will automatically have a <CODE>SOAPPart object.
* <p/>
* <P>A SOAPPart object is a MIME part and has the MIME headers Content-Id,
* Content-Location, and Content-Type. Because the value of Content-Type must be "text/xml", a
* <CODE> SOAPPart object automatically has a MIME header of Content-Type with its value set
* to "text/xml". The value must be "text/xml" because content in the SOAP part of a message must be
* in XML format. Content that is not of type "text/xml" must be in an <CODE>AttachmentPart
* object rather than in the <CODE>SOAPPart object.
* <p/>
* <P>When a message is sent, its SOAP part must have the MIME header Content-Type set to
* "text/xml". Or, from the other perspective, the SOAP part of any message that is received must
* have the MIME header Content-Type with a value of "text/xml".</P>
* <p/>
* <P>A client can access the SOAPPart object of a SOAPMessage object by
* calling the method <CODE> SOAPMessage.getSOAPPart. The following line of code, in which
* <CODE>message is a SOAPMessage object, retrieves the SOAP part of a
* message.</P> SOAPPart soapPart = message.getSOAPPart();
* <p/>
* <P>A SOAPPart object contains a SOAPEnvelope object, which in turn
* contains a <CODE> SOAPBody object and a SOAPHeader object. The
* <CODE>SOAPPart method getEnvelope can be used to retrieve the
* <CODE>SOAPEnvelope object.
*/
public abstract class SOAPPart implements javax.xml.soap.Node, org.w3c.dom.Document {
public SOAPPart() {
}
/**
* Gets the <CODE>SOAPEnvelope object associated with this SOAPPart object.
* Once the SOAP envelope is obtained, it can be used to get its contents.
*
* @return the <CODE>SOAPEnvelope object for this SOAPPart object
* @throws SOAPException if there is a SOAP error
*/
public abstract SOAPEnvelope getEnvelope() throws SOAPException;
/**
* Retrieves the value of the MIME header whose name is "Content-Id".
*
* @return a <CODE>String giving the value of the MIME header named "Content-Id"
* @see #setContentId(String) setContentId(java.lang.String)
*/
public String getContentId() {
String as[] = getMimeHeader("Content-Id");
if (as != null && as.length > 0) {
return as[0];
} else {
return null;
}
}
/**
* Retrieves the value of the MIME header whose name is "Content-Location".
*
* @return a <CODE>String giving the value of the MIME header whose name is
* "Content-Location"
* @see #setContentLocation(String) setContentLocation(java.lang.String)
*/
public String getContentLocation() {
String as[] = getMimeHeader("Content-Location");
if (as != null && as.length > 0) {
return as[0];
} else {
return null;
}
}
/**
* Sets the value of the MIME header named "Content-Id" to the given <CODE>String.
*
* @param contentId a <CODE>String giving the value of the MIME header "Content-Id"
* @throws IllegalArgumentException
* if there is a problem in setting the content id
* @see #getContentId() getContentId()
*/
public void setContentId(String contentId) {
setMimeHeader("Content-Id", contentId);
}
/**
* Sets the value of the MIME header "Content-Location" to the given <CODE>String.
*
* @param contentLocation a <CODE>String giving the value of the MIME header
* "Content-Location"
* @throws IllegalArgumentException
* if there is a problem in setting the content location.
* @see #getContentLocation() getContentLocation()
*/
public void setContentLocation(String contentLocation) {
setMimeHeader("Content-Location", contentLocation);
}
/**
* Removes all MIME headers that match the given name.
*
* @param header a <CODE>String giving the name of the MIME header(s) to be removed
*/
public abstract void removeMimeHeader(String header);
/** Removes all the <CODE>MimeHeader objects for this SOAPEnvelope object. */
public abstract void removeAllMimeHeaders();
/**
* Gets all the values of the <CODE>MimeHeader object in this SOAPPart
* object that is identified by the given <CODE>String.
*
* @param name the name of the header; example: "Content-Type"
* @return a <CODE>String array giving all the values for the specified header
* @see #setMimeHeader(String, String) setMimeHeader(java.lang.String,
* java.lang.String)
*/
public abstract String[] getMimeHeader(String name);
/**
* 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/>
* <P>Note that RFC822 headers can contain only US-ASCII characters.
*
* @param name a <CODE>String giving the header name for which to search
* @param value a <CODE>String 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 object.
* @throws IllegalArgumentException
* if there was a problem with the specified mime header name or value
* @throws IllegalArgumentException
* if there was a problem with the specified mime header name or value
* @see #getMimeHeader(String) getMimeHeader(java.lang.String)
*/
public abstract void setMimeHeader(String name, String value);
/**
* Creates a <CODE>MimeHeader object with the specified name and value and adds it to
* this <CODE>SOAPPart object. If a MimeHeader with the specified name
* already exists, this method adds the specified value to the already existing value(s).
* <p/>
* <P>Note that RFC822 headers can contain only US-ASCII characters.
*
* @param name a <CODE>String giving the header name
* @param value a <CODE>String giving the value to be set or added
* @throws IllegalArgumentException
* if there was a problem with the specified mime header name or value
*/
public abstract void addMimeHeader(String name, String value);
/**
* Retrieves all the headers for this <CODE>SOAPPart object as an iterator over the
* <CODE>MimeHeader objects.
*
* @return an <CODE>Iterator object with all of the Mime headers for this
* <CODE>SOAPPart object
*/
public abstract Iterator getAllMimeHeaders();
/**
* Retrieves all <CODE>MimeHeader objects that match a name in the given array.
*
* @param names a <CODE>String array with the name(s) of the MIME headers to be returned
* @return all of the MIME headers that match one of the names in the given array, returned as
* an <CODE>Iterator object
*/
public abstract Iterator getMatchingMimeHeaders(String names[]);
/**
* Retrieves all <CODE>MimeHeader objects whose name does not match a name in the given
* array.
*
* @param names a <CODE>String array with the name(s) of the MIME headers not to be
* returned
* @return all of the MIME headers in this <CODE>SOAPPart object except those that match
* one of the names in the given array. The nonmatching MIME headers are returned as an
* <CODE>Iterator object.
*/
public abstract Iterator getNonMatchingMimeHeaders(String names[]);
/**
* Sets the content of the <CODE>SOAPEnvelope object with the data from the given
* <CODE>Source 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 abstract void setContent(Source source) throws SOAPException;
/**
* Returns the content of the SOAPEnvelope as a JAXP <CODE> Source object.
*
* @return the content as a <CODE> javax.xml.transform.Source object
* @throws SOAPException if the implementation cannot convert the specified <CODE>Source
* object
* @see #setContent(javax.xml.transform.Source) setContent(javax.xml.transform.Source)
*/
public abstract Source getContent() throws SOAPException;
}
Other Axis 2 examples (source code examples)
Here is a short list of links related to this Axis 2 SOAPPart.java source code file:
|