我创建了一个类并将其作为Web服务发布。我创建了一个像这样的Web方法:
public void addNewRow(MyObject cob) {
MyAppModule myAppModule = new MyAppModule();
try {
ViewObjectImpl vo = myAppModule.getMyVewObject1();
================> vo object is now null
Row r = vo.createRow();
r.setAttribute("Param1", cob.getParam1());
r.setAttribute("Param2", cob.getParam2());
vo.executeQuery();
getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
}
}
正如我在代码中编写的那样,myAppModule.getMyVewObject1()返回一个null对象。我不懂为什么!据我所知,当我调用“getMyVewObject1()”时,AppModule必须自己初始化对象,但也许我错了,或者这可能不是Web方法的应用方式。有没有人遇到过这个问题?任何帮助都将非常感激。
答案 0 :(得分:2)
你可以查看好的教程:Building and Using Web Services with JDeveloper 它为您提供了有关如何使用ADF构建Web服务的一般概念。
另一种方法是当你需要从一些没有所需环境的bean(servlet等)调用现有的Application Module时,你可以像这样初始化它:
String appModuleName = "org.my.package.name.model.AppModule";
String appModuleConfig = "AppModuleLocal";
ApplicationModule am = Configuration.createRootApplicationModule(appModuleName, appModuleConfig);
别忘了发布它:
Configuration.releaseRootApplicationModule(am, true);
而且why you shouldn't really do it like this.
And even more...
更好的方法是访问绑定层并从那里进行调用 Here is a nice article.
答案 1 :(得分:1)
Per Per PM:如果您不在ADF应用程序的上下文中使用它,则应使用以下代码(示例代码来自我参与的项目)。请注意在请求结束时释放AM
@WebService(serviceName =“LightViewerSoapService”) 公共类LightViewerSoapService {
private final String amDef = " oracle.demo.lightbox.model.viewer.soap.services.LightBoxViewerService";
private final String config = "LightBoxViewerServiceLocal";
LightBoxViewerServiceImpl service;
public LightViewerSoapService() {
super();
}
@WebMethod
public List<Presentations> getAllUserPresentations(@WebParam(name = "userId") Long userId){
ArrayList<Presentations> al = new ArrayList<Presentations>();
service = (LightBoxViewerServiceImpl)getApplicationModule(amDef,config);
ViewObject vo = service.findViewObject("UserOwnedPresentations");
VariableValueManager vm = vo.ensureVariableManager();
vm.setVariableValue("userIdVariable", userId.toString());
vo.applyViewCriteria(vo.getViewCriteriaManager().getViewCriteria("byUserIdViewCriteria"));
Row rw = vo.first();
if(rw != null){
Presentations p = createPresentationFromRow(rw);
al.add(p);
while(vo.hasNext()){
rw = vo.next();
p = createPresentationFromRow(rw);
al.add(p);
}
}
releaseAm((ApplicationModule)service);
return al;
}
请看这里: