endpointreference.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 742 行 · 第 1/2 页
JAVA
742 行
addExtensibleElement(eprChildElement);
}
}
}
/**
* @param nsurl
* @param localName
* @param prefix
* @throws AxisFault
* @deprecated use {@link EndpointReferenceHelper#toOM(EndpointReference, QName, String)} instead.
*/
public OMElement toOM(String nsurl, String localName, String prefix) throws AxisFault {
OMFactory fac = OMAbstractFactory.getOMFactory();
if (prefix != null) {
OMNamespace wrapNs = fac.createOMNamespace(nsurl, prefix);
OMElement epr = fac.createOMElement(localName, wrapNs);
OMNamespace wsaNS = fac.createOMNamespace(AddressingConstants.Final.WSA_NAMESPACE,
AddressingConstants.WSA_DEFAULT_PREFIX);
OMElement addressE = fac.createOMElement(AddressingConstants.EPR_ADDRESS, wsaNS, epr);
addressE.setText(address);
if (addressAttributes != null) {
Iterator attrIter = addressAttributes.iterator();
while (attrIter.hasNext()) {
OMAttribute omAttributes = (OMAttribute) attrIter.next();
addressE.addAttribute(omAttributes);
}
}
if (this.metaData != null) {
OMElement metadataE =
fac.createOMElement(AddressingConstants.Final.WSA_METADATA, wsaNS, epr);
Iterator metadata = this.metaData.iterator();
while (metadata.hasNext()) {
metadataE.addChild((OMNode) metadata.next());
}
}
if (this.referenceParameters != null) {
OMElement refParameterElement =
fac.createOMElement(AddressingConstants.EPR_REFERENCE_PARAMETERS,
wsaNS,
epr);
Iterator refParms = referenceParameters.values().iterator();
while (refParms.hasNext()) {
refParameterElement.addChild((OMNode) refParms.next());
}
}
if (attributes != null) {
Iterator attrIter = attributes.iterator();
while (attrIter.hasNext()) {
OMAttribute omAttributes = (OMAttribute) attrIter.next();
epr.addAttribute(omAttributes);
}
}
// add xs:any
ArrayList omElements = extensibleElements;
if (omElements != null) {
for (int i = 0; i < omElements.size(); i++) {
epr.addChild((OMElement) omElements.get(i));
}
}
return epr;
} else {
throw new AxisFault("prefix must be specified");
}
}
/**
* Compares key parts of the state from the current instance of
* this class with the specified instance to see if they are
* equivalent.
* <p/>
* This differs from the java.lang.Object.equals() method in
* that the equals() method generally looks at both the
* object identity (location in memory) and the object state
* (data).
* <p/>
*
* @param epr The object to compare with
* @return TRUE if this object is equivalent with the specified object
* that is, key fields match
* FALSE, otherwise
*/
public boolean isEquivalent(EndpointReference epr) {
// NOTE: the input object is expected to exist (ie, be non-null)
if ((this.name != null) && (epr.getName() != null)) {
if (!this.name.equals(epr.getName())) {
return false;
}
} else if ((this.name == null) && (epr.getName() == null)) {
// continue
} else {
// mismatch
return false;
}
if ((this.address != null) && (epr.getAddress() != null)) {
if (!this.address.equals(epr.getAddress())) {
return false;
}
} else if ((this.address == null) && (epr.getAddress() == null)) {
// continue
} else {
// mismatch
return false;
}
// TODO: is a strict test ok to use?
ArrayList eprMetaData = epr.getMetaData();
if ((this.metaData != null) && (eprMetaData != null)) {
if (!this.metaData.equals(eprMetaData)) {
// This is a strict test
// Returns true if and only if the specified object
// is also a list, both lists have the same size, and
// all corresponding pairs of elements in the two lists
// are equal, ie, two lists are defined to be equal if
// they contain the same elements in the same order.
return false;
}
} else if ((this.metaData == null) && (eprMetaData == null)) {
// keep going
} else {
// one of the lists is null
return false;
}
ArrayList eprExtensibleElements = epr.getExtensibleElements();
if ((this.extensibleElements != null) && (eprExtensibleElements != null)) {
if (!this.extensibleElements.equals(eprExtensibleElements)) {
// This is a strict test
// Returns true if and only if the specified object
// is also a list, both lists have the same size, and
// all corresponding pairs of elements in the two lists
// are equal, ie, two lists are defined to be equal if
// they contain the same elements in the same order.
return false;
}
} else if ((this.extensibleElements == null) && (eprExtensibleElements == null)) {
// keep going
} else {
// one of the lists is null
return false;
}
ArrayList eprAttributes = epr.getAttributes();
if ((this.attributes != null) && (eprAttributes != null)) {
if (!this.attributes.equals(eprAttributes)) {
// This is a strict test
// Returns true if and only if the specified object
// is also a list, both lists have the same size, and
// all corresponding pairs of elements in the two lists
// are equal, ie, two lists are defined to be equal if
// they contain the same elements in the same order.
return false;
}
} else if ((this.attributes == null) && (eprAttributes == null)) {
// keep going
} else {
// one of the lists is null
return false;
}
// TODO: check the Map referenceParameters for equivalency
return true;
}
//REVIEW: The following code is rather heavyweight, because we have to build
// the OM tree -- it would probably be better to have two serialization/deserialization
// paths and therefore, for trivial EPRs, store a smaller amount of info
/**
* Write the EPR to the specified OutputStream. Because of potential
* OMElements/Attributes, we need to actually serialize the OM structures
* (at least in some cases.)
*/
private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
String logCorrelationIDString = getLogCorrelationIDString();
// String object id
ObjectStateUtils.writeString(out, logCorrelationIDString, logCorrelationIDString
+ ".logCorrelationIDString");
OMElement om =
EndpointReferenceHelper.toOM(OMAbstractFactory.getOMFactory(),
this,
new QName("urn:axis2", "omepr", "ser"),
AddressingConstants.Final.WSA_NAMESPACE);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
om.serialize(baos);
} catch (Exception e) {
IOException ioe = new IOException("Unable to serialize the EndpointReference with logCorrelationID ["
+logCorrelationIDString+"]");
ioe.initCause(e);
if (log.isDebugEnabled()) {
log.debug("writeObject(): Unable to serialize the EPR with logCorrelationID ["
+logCorrelationIDString+"] original error ["+e.getClass().getName()
+"] message ["+e.getMessage()+"]",e);
}
throw ioe;
}
out.writeInt(baos.size());
out.write(baos.toByteArray());
if (log.isDebugEnabled()) {
byte[] buffer = baos.toByteArray();
String content = new String(buffer);
log.debug("writeObject(): EPR logCorrelationID ["+logCorrelationIDString+"] "
+" EPR content size ["+baos.size()+"]"
+" EPR content ["+content+"]");
}
}
/**
* Read the EPR to the specified InputStream.
*/
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
// String object id
logCorrelationIDString = ObjectStateUtils.readString(in, "EndpointReference.logCorrelationIDString");
int numBytes = in.readInt();
byte[] serBytes = new byte[numBytes];
// read the data from the input stream
int bytesRead = 0;
int numberOfBytesLastRead;
while (bytesRead < numBytes) {
numberOfBytesLastRead = in.read(serBytes, bytesRead, numBytes - bytesRead);
if (numberOfBytesLastRead == -1) {
// TODO: What should we do if the reconstitution fails?
// For now, log the event and throw an exception
if (log.isDebugEnabled()) {
log.debug("readObject(): EPR logCorrelationID ["+logCorrelationIDString+"] "
+ " ***WARNING*** unexpected end to data: data read from input stream ["
+ bytesRead + "] expected data size [" + numBytes + "]");
}
IOException ioe = new IOException("Unable to deserialize the EndpointReference with logCorrelationID ["
+logCorrelationIDString+"]"
+" Cause: Unexpected end to data from input stream");
throw ioe;
}
bytesRead += numberOfBytesLastRead;
}
if (bytesRead == 0) {
IOException ioe = new IOException("Unable to deserialize the EndpointReference with logCorrelationID ["
+logCorrelationIDString+"]"
+" Cause: No data from input stream");
throw ioe;
}
ByteArrayInputStream bais = new ByteArrayInputStream(serBytes);
if (log.isDebugEnabled()) {
String content = new String(serBytes);
log.debug("readObject(): EPR logCorrelationID ["+logCorrelationIDString+"] "
+" expected content size ["+numBytes+"]"
+" content size ["+content.length()+"]"
+" EPR buffered content ["+content+"]");
}
XMLStreamReader xmlReader = null;
try {
xmlReader = StAXUtils.createXMLStreamReader(bais);
StAXOMBuilder builder = new StAXOMBuilder(xmlReader);
OMElement om = builder.getDocumentElement();
// expand the OM so we can close the stream reader
om.build();
// trace point
if (log.isDebugEnabled()) {
log.debug(myClassName + ":readObject(): "
+ " EPR ["+logCorrelationIDString + "]"
+ " EPR OM content ["+om.toString()+ "]");
}
EndpointReferenceHelper.fromOM(this, om, AddressingConstants.Final.WSA_NAMESPACE);
} catch (Exception e) {
IOException ioe = new IOException("Unable to deserialize the EndpointReference with logCorrelationID ["
+logCorrelationIDString+"]");
ioe.initCause(e);
if (log.isDebugEnabled()) {
log.debug("readObject(): Unable to deserialize the EPR with logCorrelationID ["
+logCorrelationIDString+"] original error ["+e.getClass().getName()
+"] message ["+e.getMessage()+"]",e);
}
throw ioe;
} finally {
// Make sure that the reader is properly closed
// Note that closing a ByteArrayInputStream has no effect
if (xmlReader != null) {
try {
xmlReader.close();
} catch (Exception e2) {
IOException ioe2 = new IOException("Unable to close the XMLStreamReader for the EndpointReference with logCorrelationID ["
+logCorrelationIDString+"]");
ioe2.initCause(e2);
if (log.isDebugEnabled()) {
log.debug("readObject(): Unable to close the XMLStreamReader for the EPR with logCorrelationID ["
+logCorrelationIDString+"] original error ["+e2.getClass().getName()
+"] message ["+e2.getMessage()+"]",e2);
}
throw ioe2;
}
}
}
}
/**
* Get the ID associated with this object instance.
*
* @return A string that can be output to a log file as an identifier
* for this object instance. It is suitable for matching related log
* entries.
*/
public String getLogCorrelationIDString() {
if (logCorrelationIDString == null) {
logCorrelationIDString = myClassName + "@" + UUIDGenerator.getUUID();
}
return logCorrelationIDString;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?