Copy link to clipboard
Copied
Hi, I used cfobject to create java object as follow:
<cfobject
type="Java" class="com.as.web.Search" name="myObj" action="create">
<cfdump
var="#myObj#">
Here is the output:
I'm having a hard time accessing these method from coldfusion. If I do:
<cfset x = myObj.getAddress()>
<cfdump var="#x#"> I got this error:
Object Instantiation Exception.
An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. If the class has a constructor that accepts an argument, you must call the constructor explicitly using the init(args) method. Error : com.as.web.Search
If I do:
<cfset y = "1st street skillman NJ 08558">
<cfset x = myObj.getAddress( #y#)>
<cfdump var="#x#"> I got an error :
The getAddress method was not found.
Either there are no methods with the specified method name and argument types, or the getAddress method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that matched the provided arguments. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity.
I have no experience working with java object and don't understand what this mean and what should I do, please help?
Copy link to clipboard
Copied
We need to know a little more about the class. Is there a public API or can you post a screen shot of the API for this class?
Copy link to clipboard
Copied
Hi! here is the java class I used;
/* ----------------------------------------------------------------------------
* Common Classes > Search.java
* The an element of the bulk verification search results
* ----------------------------------------------------------------------------
*/
package com.AS.web;
import com.AS.web.soap.*;
/** Wrapper class to encapsulate a single entry returned by a bulk verification search, with fields for
* the original input address, the verification level and possibly a FormattedAddress
*/
public class Search {
// ------------------------------------------------------------------------
// public constants
// ------------------------------------------------------------------------
/** Verify level indicating that there was no verification upon the search. */
public static final String None = VerifyLevelType._None;
/** Verify level indicating that the search has verified correct. */
public static final String Verified = VerifyLevelType._Verified;
/** Verify level indicating that the search produced a single deliverable match, but user confirmation is advised */
public static final String InteractionRequired = VerifyLevelType._InteractionRequired;
/** Verify level indicating that the address was matched to a partial address at the premise level.
* This implies that there is also a picklist associated with the partial address. */
public static final String PremisesPartial = VerifyLevelType._PremisesPartial;
/** Verify level indicating that the address was matched to a partial address at the street level.
* This implies that there is also a picklist associated with the partial address. */
public static final String StreetPartial = VerifyLevelType._StreetPartial;
/** Verify level indicating that the search was ambiguous and matched multiple separate addresses. */
public static final String Multiple = VerifyLevelType._Multiple;
/** Verify level indicating that the address was matched at the Place Level (Address Dr Specific Matching) */
public static final String VerifiedPlace = VerifyLevelType._VerifiedPlace;
/** Verify level indicating that the address was matched at the Street Level (Address Dr Specific Matching) */
public static final String VerifiedStreet = VerifyLevelType._VerifiedStreet;
// ------------------------------------------------------------------------
// private data
// ------------------------------------------------------------------------
private FormattedAddress m_Address;
private String m_VerifyLevel = null;
private String m_sInputAddress;
/** Construct an instance from a SOAP layer object */
public Search(QASearchType t) {
QAAddressType address = t.getQAAddress();
if (address != null) {
m_Address = new FormattedAddress(address);
} else {
m_Address = null;
}
VerifyLevelType level = t.getVerifyLevel();
if (level != null) {
m_VerifyLevel = level.toString();
}
m_sInputAddress = t.getInputAddress();
}
/** (Verification only) Returns the address, which may be null as this will only ever be returned by the
* verification engine for certain types of results.
*/
public FormattedAddress getAddress() {
return m_Address;
}
/** (Verification only) Returns the input address
*/
public String getInputAddress() {
return m_sInputAddress;
}
/** (Verification only) Returns the verify level, which specifies how well the search has
* been matched, and the appropriate action that can be taken upon the result. */
public String getVerifyLevel() {
return m_VerifyLevel;
}
}
Copy link to clipboard
Copied
Creating java objects is similar to creating an instance of a cfcomponent. Some components require arguments. For example a component that queries a database, might require a datasource name
<cfset MyObject = createObject("component", "MyDatabaseComponent").init(someDatasourceName)>
<cfcomponent>
<cffunction name="init" ....>
<cfargument name="dsn" ...><!---- store the datasource for use in queries --->
<cfset variables.dsn = arguments.dsn>
<cfreturn this />
</cfffunction>
</cfcomponent>
public Search(QASearchType t) {
.....
}
Your Search class seems to require an argument: QASearchType. So you will have to create a QASearchType object first. Then use it to create your Search object. You will have to look at the QASearchType class/API to see what arguments (if any) it requires. (Note, I personally prefer the shorter createObject(..) syntax over cfobject)
<cfset QASearchType = creatObject("java", "path.to.class.QASearchType").init( ....??.. )>
<cfset mySearchObject = creatObject("java", "com.AS.web.Search").init( yourQASearchTypeObject)>
Message was edited by: -==cfSearching==-
Copy link to clipboard
Copied
The only QASearchType Class I have is in SOAP Folder and it is called: QASearchType Class file 3KB. I can't open it either with notepad or other text editor such as the one in eclipse.
If I use CreateObject, the type attribute of CreateObject does not have SOAP, it only has Java,com,corba,component and web service and what is the init(..?...)
<cfset QASearchType = creatObject("...?...", "path.to.class.QASearchType").init( ....??.. )>
Copy link to clipboard
Copied
The only QASearchType Class I have is in SOAP Folder and it is called: QASearchType Class file 3KB. I can't open it either with notepad or other text editor such as the one in eclipse. If I use CreateObject, the type attribute of CreateObject does not have SOAP, it only has Java,com,corba,component and web service
The "type" attribute is the same as you were using for cfobject. It refers to the type of object you are creating. You already know it is a "java" object. The class is most likely located in the same place as you found the "Search" class source code.
BTW, you did not answer my earlier question. Is there a public API for this jar? It would tell you what you need to know about using this jar.
what is the init(..?...)
<cfset QASearchType = createObject("...?...", "path.to.class.QASearchType").init( ....??.. )>
In java you use the keyword "new" to create an instance of a class ie Search obj = new Search(arguments); But that is not allowed in CF. So CF provides a psuedo function called init(). It is used to call the constructor of a java class. So whenever you need to create an instance, you call the init() function, with whatever arguments the class requires.
Copy link to clipboard
Copied
All I have is the java classes and their source code files. See the screen shot below, those are the java class files I have.
When I opened up each of those folder, there are more class files, such as on SOAP folder I found QASearchType class and others. I have the same folder and subfolders for all the .java files
There is one more folder that has executable jar file but I can't open this file either. Is this what you refer as jar file?
I'm embarass to say what is the API. I know what it is stand for and by definition what it is for but not sure where can I find this API.
Copy link to clipboard
Copied
When I opened up each of those folder, there are more class
files, such as on SOAP folder I found QASearchType class and
others. I have the same folder and subfolders for all the
.java files
Okay. Then look for the QASearchType .java file.
but not sure
where can I find this API.
By API I mean the standard java documentation generated from the /* comments */ in the .java source files. But if you have the .java source, we can figure it out by looking at the QASearchType.java file.
Most popular libraries have a public API. For example, the iText java library API can be found here: http://api.itextpdf.com/. But it is entirely possible that yours does not have a public API or that you were not given the generated documentation. But like I said, it is no big deal if you have all of the the source .java files.
Copy link to clipboard
Copied
Hi,
So, I created QASearchType object first:
<CFSET QASearchTypeObj = CreateObject("java","com.as.web.soap.QASearchType").init()>
I may be wrong but looking at QASearchType .java file I don't see I need to pass parameter in init() ....? I may be wrong
Then create the Search Object:
<cfset MySearchObject = CreateObject("java", "com.as.web.Search").init(QASearchTypeObj)>
Looking at QASearch
Here is the QASearchType .java file. It looks like it requires :
1. QAAddressType and
2. VerifyLevelType
There is no other way for me to upload all the needed files for you to see other than upload them all here.
This is the QASearchType file:
/**
* QASearchType.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.2.1 Jun 14, 2005 (09:15:57 EDT) WSDL2Java emitter.
*/
package com.as.web.soap;
public class QASearchType implements java.io.Serializable {
private com.as.web.soap.QAAddressType QAAddress;
private java.lang.String inputAddress;
private com.as.web.soap.VerifyLevelType verifyLevel; // attribute
public QASearchType() {
}
public QASearchType(
com.as.web.soap.QAAddressType QAAddress,
java.lang.String inputAddress,
com.as.web.soap.VerifyLevelType verifyLevel) {
this.QAAddress = QAAddress;
this.inputAddress = inputAddress;
this.verifyLevel = verifyLevel;
}
/**
* Gets the QAAddress value for this QASearchType.
*
* @return QAAddress
*/
public com.as.web.soap.QAAddressType getQAAddress() {
return QAAddress;
}
/**
* Sets the QAAddress value for this QASearchType.
*
* @param QAAddress
*/
public void setQAAddress(com.as.web.soap.QAAddressType QAAddress) {
this.QAAddress = QAAddress;
}
/**
* Gets the inputAddress value for this QASearchType.
*
* @return inputAddress
*/
public java.lang.String getInputAddress() {
return inputAddress;
}
/**
* Sets the inputAddress value for this QASearchType.
*
* @param inputAddress
*/
public void setInputAddress(java.lang.String inputAddress) {
this.inputAddress = inputAddress;
}
/**
* Gets the verifyLevel value for this QASearchType.
*
* @return verifyLevel
*/
public com.as.web.soap.VerifyLevelType getVerifyLevel() {
return verifyLevel;
}
/**
* Sets the verifyLevel value for this QASearchType.
*
* @param verifyLevel
*/
public void setVerifyLevel(com.as.web.soap.VerifyLevelType verifyLevel) {
this.verifyLevel = verifyLevel;
}
private java.lang.Object __equalsCalc = null;
public synchronized boolean equals(java.lang.Object obj) {
if (!(obj instanceof QASearchType)) return false;
QASearchType other = (QASearchType) obj;
if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj);
}
__equalsCalc = obj;
boolean _equals;
_equals = true &&
((this.QAAddress==null && other.getQAAddress()==null) ||
(this.QAAddress!=null &&
this.QAAddress.equals(other.getQAAddress()))) &&
((this.inputAddress==null && other.getInputAddress()==null) ||
(this.inputAddress!=null &&
this.inputAddress.equals(other.getInputAddress()))) &&
((this.verifyLevel==null && other.getVerifyLevel()==null) ||
(this.verifyLevel!=null &&
this.verifyLevel.equals(other.getVerifyLevel())));
__equalsCalc = null;
return _equals;
}
private boolean __hashCodeCalc = false;
public synchronized int hashCode() {
if (__hashCodeCalc) {
return 0;
}
__hashCodeCalc = true;
int _hashCode = 1;
if (getQAAddress() != null) {
_hashCode += getQAAddress().hashCode();
}
if (getInputAddress() != null) {
_hashCode += getInputAddress().hashCode();
}
if (getVerifyLevel() != null) {
_hashCode += getVerifyLevel().hashCode();
}
__hashCodeCalc = false;
return _hashCode;
}
public String getXMLDoc() {
return "<qas:VerifyLevel>" + verifyLevel + "</qas:VerifyLevel>" +
"<qas:QAAddress>" + QAAddress + "</qas:QAAddress>" +
"<qas:InputAddress>" + inputAddress + "</qas:InputAddress>";
}
}
Here is the QAAddressType file:
/* ----------------------------------------------------------------------------
* SOAP Classes > QAAddressType.java
* Data type class for QAAddressType defined in WSDL
* ----------------------------------------------------------------------------
*/
package com.as.web.soap;
/**
* The QAAddressType class defines a Java data type corresponding to the
* QAAddressType definition in the QuickAddress Server WSDL.
* <p>
* This class is based on an file auto-generated from the WSDL by the Apache
* Axis WSDL2Java emitter.
*/
public class QAAddressType implements java.io.Serializable {
// ------------------------------------------------------------------------
// Private variables
// ------------------------------------------------------------------------
private com.as.web.soap.AddressLineType[] addressLine;
private boolean overflow; // attribute
private boolean truncated; // attribute
private com.as.web.soap.DPVStatusType DPVStatus; // attribute
/**
* Constructs default <code>QAAddressType</code>.
*/
public QAAddressType() {
}
public QAAddressType(
com.as.web.soap.AddressLineType[] addressLine,
boolean overflow,
boolean truncated,
com.as.web.soap.DPVStatusType DPVStatus) {
this.addressLine = addressLine;
this.overflow = overflow;
this.truncated = truncated;
this.DPVStatus = DPVStatus;
}
/**
* Sets the address lines from an array of <code>AddressLineTypes</code>.
* @param addressLine the array of <code>AddressLineTypes</code>
*/
public void setAddressLine(
com.as.web.soap.AddressLineType[] addressLine) {
this.addressLine = addressLine;
}
/**
* Gets the address lines in an array of <code>AddressLineTypes</code>.
* @return the array of <code>AddressLineTypes</code>
*/
public com.as.web.soap.AddressLineType[] getAddressLine() {
return addressLine;
}
/**
* Sets an address line at a given index.
* @param i the index of the address line
* @param value the AddressLineType for the line
*/
public void setAddressLine(int i,
com.as.web.soap.AddressLineType value) {
this.addressLine = value;
}
/**
* Gets an address line at a given index.
* @param i the index of the address line
* @return value the AddressLineType for the line
*/
public com.as.web.soap.AddressLineType getAddressLine(int i) {
return addressLine;
}
/**
* Sets the address type overflow attribute.
* @param overflow the overflow value
*/
public void setOverflow(boolean overflow) {
this.overflow = overflow;
}
/**
* Gets the address type overflow attribute.
* @return the overflow value
*/
public boolean isOverflow() {
return overflow;
}
/**
* Sets the address type truncation attribute.
* @param truncated the truncation value
*/
public void setTruncated(boolean truncated) {
this.truncated = truncated;
}
/**
* Gets the address type truncation attribute.
* @return the truncation value
*/
public boolean isTruncated() {
return truncated;
}
/**
* Gets the DPVStatus value for this QAAddressType.
*
* @return DPVStatus
*/
public com.as.web.soap.DPVStatusType getDPVStatus() {
return DPVStatus;
}
/**
* Sets the DPVStatus value for this QAAddressType.
*
* @param DPVStatus
*/
public void setDPVStatus(com.as.web.soap.DPVStatusType DPVStatus) {
this.DPVStatus = DPVStatus;
}
private java.lang.Object __equalsCalc = null;
/**
* Overrides the equals() method for comparing objects.
* @param obj the object to compare against
* @return the equality value
*/
public synchronized boolean equals(java.lang.Object obj) {
if (!(obj instanceof QAAddressType)) return false;
QAAddressType other = (QAAddressType) obj;
if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj);
}
__equalsCalc = obj;
boolean _equals;
_equals = true &&
((addressLine==null && other.getAddressLine()==null) ||
(addressLine!=null &&
java.util.Arrays.equals(addressLine, other.getAddressLine()))) &&
overflow == other.isOverflow() &&
truncated == other.isTruncated()&&
((this.DPVStatus==null && other.getDPVStatus()==null) ||
(this.DPVStatus!=null &&
this.DPVStatus.equals(other.getDPVStatus())));
__equalsCalc = null;
return _equals;
}
private boolean __hashCodeCalc = false;
/**
* Overrides the hashCode() method.
* @return the hash code value for the object
*/
public synchronized int hashCode() {
if (__hashCodeCalc) {
return 0;
}
__hashCodeCalc = true;
int _hashCode = 1;
if (getAddressLine() != null) {
for (int i=0;
i<java.lang.reflect.Array.getLength(getAddressLine());
i++) {
java.lang.Object obj =
java.lang.reflect.Array.get(getAddressLine(), i);
if (obj != null &&
!obj.getClass().isArray()) {
_hashCode += obj.hashCode();
}
}
}
_hashCode += new Boolean(isOverflow()).hashCode();
_hashCode += new Boolean(isTruncated()).hashCode();
if (getDPVStatus() != null) {
_hashCode += getDPVStatus().hashCode();
}
__hashCodeCalc = false;
return _hashCode;
}
}
/* ------------------------------ End of file ------------------------------ */
Here is VerifyLevelType file:
/* ----------------------------------------------------------------------------
*
* SOAP Classes > VerifyLevelType.java
* Data type class for VerifyLevelType defined in WSDL
* ----------------------------------------------------------------------------
*/
package com.as.web.soap;
/**
* The VerifyLevelType class defines a Java data type corresponding to the
* VerifyLevelType definition in the QAddress Server WSDL.
* <p>
* This class is based on an file auto-generated from the WSDL by the Apache
* Axis WSDL2Java emitter.
*/
public class VerifyLevelType implements java.io.Serializable {
// ------------------------------------------------------------------------
// Private variables
// ------------------------------------------------------------------------
private String _value_;
private static java.util.HashMap _table_ = new java.util.HashMap();
/** Verify level type of None */
public static final String _None = "None";
/** Verify level type of Verified */
public static final String _Verified = "Verified";
/** Verify level type of InteractionRequired */
public static final String _InteractionRequired = "InteractionRequired";
/** Verify level type of PremisesPartial */
public static final String _PremisesPartial = "PremisesPartial";
/** Verify level type of StreetPartial */
public static final String _StreetPartial = "StreetPartial";
/** Verify level type of Multiple */
public static final String _Multiple = "Multiple";
/** Verify level indicating that the address was matched at the Place Level (Address Dr Specific Matching) */
public static final String _VerifiedPlace = "VerifiedPlace";
/** Verify level indicating that the address was matched at the Street Level (Address Dr Specific Matching) */
public static final String _VerifiedStreet = "VerifiedStreet";
/**
* Constructs <code>VerifyLevelType</code> from the given value for the
* verify level.
* @param value the value for the verify level
*/
protected VerifyLevelType(String value) {
_value_ = value;
_table_.put(_value_,this);
};
/**
* Creates an <code>VerifyLevelType</code> object using the verify level
* type None.
* @return the verify level type
*/
public static final VerifyLevelType None = new VerifyLevelType(_None);
/**
* Creates an <code> VerifyLevelType</code> object using the verify level
* type Verified.
* @return the verify level type
*/
public static final VerifyLevelType Verified =
new VerifyLevelType(_Verified);
/**
* Creates an <code>VerifyLevelType</code> object using the verify level
* type InteractionRequired.
* @return the verify level type
*/
public static final VerifyLevelType InteractionRequired =
new VerifyLevelType(_InteractionRequired);
/**
* Creates an <code>VerifyLevelType</code> object using the verify level
* type PremisesPartial.
* @return the verify level type
*/
public static final VerifyLevelType PremisesPartial =
new VerifyLevelType(_PremisesPartial);
/**
* Creates an <code>VerifyLevelType</code> object using the verify level
* type StreetPartial.
* @return the verify level type
*/
public static final VerifyLevelType StreetPartial =
new VerifyLevelType(_StreetPartial);
/**
* Creates an <code>VerifyLevelType</code> object using the verify level
* type VerifiedPlace.
* @return the verify level type
*/
public static final VerifyLevelType VerifiedPlace =
new VerifyLevelType(_VerifiedPlace);
/**
* Creates an <code>VerifyLevelType</code> object using the verify level
* type VerfiedStreet.
* @return the verify level type
*/
public static final VerifyLevelType VerifiedStreet =
new VerifyLevelType(_VerifiedStreet);
/**
* Creates an <code>VerifyLevelType</code> object using the verify level
* type Multiple.
* @return the verify level type
*/
public static final VerifyLevelType Multiple =
new VerifyLevelType(_Multiple);
/**
* Gets the value of the verify level
* @return the verify level value
*/
public String getValue() {
return _value_;
}
/**
* Creates an <code>VerifyLevelType</code> object using the value
* specified.
* @param value the value for the verify level type
* @return the verify level type
* @throws java.lang.IllegalStateException if the value doesn't match
* a valid verify level type
*/
public static VerifyLevelType fromValue(String value)
throws java.lang.IllegalStateException {
VerifyLevelType vlType = (VerifyLevelType)
_table_.get(value);
if (vlType == null) {throw new java.lang.IllegalStateException();}
return vlType;
}
/**
* Creates an <code>VerifyLevelType</code> object using the String
* specified.
* @param value the value for the verify level type
* @return the verify level type
* @throws java.lang.IllegalStateException if the value doesn't match
* a valid verify level type
*/
public static VerifyLevelType fromString(String value)
throws java.lang.IllegalStateException {
return fromValue(value);
}
/**
* Overrides the equals() method for comparing objects.
* @param obj the object to compare against
* @return the equality value
*/
public boolean equals(java.lang.Object obj) {
return (obj == this);
}
/**
* Overrides the hashCode() method.
* @return the hash code value for the object
*/
public int hashCode() {
return toString().hashCode();
}
/**
* Overrides the toString() method.
* @return the verify level type value
*/
public String toString() {
return _value_;
}
}
/* ------------------------------ End of file ------------------------------ */
Copy link to clipboard
Copied
I may be wrong but looking at QASearchType .java file I
don't see I need to pass parameter in init() ....? I may be
wrong
It looks like there are two constructors. As you noticed one of them has three arguments (QAAddress, inputAddress, verifyLevel), the other does not. Did you try the simpler one, and if so what happened?
BTW: This looks like a web service. Is there a reason you must call everything from java? ie Is it just too complex to call it the regular way?
(If it would be easier to communicate directly, I just sent you my email in an IM)