|
| using datasource with streaming api inside a web service |
 |
Thu, 29 Nov 2007 11:30:08 -080 |
[pre]I am using the 9.1 server and accessing a datasource
created with aldsp3.0. When I run the code below as a
standalone java app, everything works fine. When I run it
on the server, I get a class cast exception when trying to cast an object
returned from the stream to MyData type.
When running the java app in the debugger, the objects
[b]dataServiceDoc[/b], [b]dog[/b] , and [b]dObj[/b] all have
the correct type. When running the web service in the debugger, the objects are
all of type
[b]DataObjectGeneral[/b], thus causing the cast error.
Any help will be greatly appreciated!
Thanks.
package services;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import weblogic.jndi.Environment;
import com.bea.dsp.RequestConfig;
import com.bea.dsp.das.DASResult;
import com.bea.dsp.das.DataAccessServiceFactory;
import com.bea.dsp.das.PreparedExpression;
import com.bea.sdo.impl.data.DataObjectGeneral;
import commonj.sdo.DataObject;
@WebService
public class MyService
{
private final static String MY_URL = "t3://localhost:8001";
private final static String DS_URL = "t3://localhost:7001";
@WebMethod
public String testMethod2()
{
StringBuilder result = new StringBuilder();
try
{
// Get the initial context to the WebLogic Server passing in user
credentials
Context ctx = getInitialContext(DS_URL,"weblogic",
"weblogic");
RequestConfig reqConfig = new RequestConfig();
result.append("[created RequestConfig object]");
reqConfig.enableFeature(RequestConfig.RETURN_DATA_SERVICE_AUDIT);
reqConfig.enableFeature(RequestConfig.RETURN_AUDIT_PROPERTIES);
reqConfig.setStringArrayAttribute(RequestConfig.RETURN_AUDIT_PROPERTIES,
new String[] { "common", "query"
});;
String dspDataSpace = "MY_DS";
String adhoc = createQuery();
PreparedExpression pe = DataAccessServiceFactory.prepareExpression(ctx,
dspDataSpace, adhoc);
DASResult<Object> dasResult = pe.executeQuery(reqConfig);
int i = 0;
int N = 100;
Long[] ids = new Long[N];
while (dasResult.hasNext() && i<N)
{
Object dataServiceDoc = dasResult.next();
// Convert Object to a Data Object
DataObjectGeneral dog = (DataObjectGeneral) dataServiceDoc;
DataObject dObj = dog.getRootObject();
// Cast the Data Object to the SDO Type (MyDataType)
MyDataType p = (MyDataType) dObj;
i++;
}
}
catch (Exception e)
{
result.append(e);
}
return result.toString();
}
private static InitialContext getInitialContext(String url, String username,
String password) throws NamingException
{
Environment env = new Environment();
env.setProviderUrl(url);
env.setInitialContextFactory("weblogic.jndi.WLInitialContextFactory");
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
return new InitialContext(env.getInitialContext().getEnvironment());
}
public static void main(String [] args)
{
MyService ms = new MyService();
System.out.println(ms.testMethod2());
}
}
[/pre]
--
Edited by ddruding at 11/29/2007 11:28 AM
--
|
| Post Reply
|
|
|
|
|
|
|
|
|
|