async invocation of service - weblogic.developer.interest.webservices.general(Archived)

I need to make conversational web service A periodically make an async call to web service B. WS A has a TimerControl and I need to call WS B from the timer callback handler.
I tried creating a WS control for service B, but that does not provide the async methods.
Then I stumbled upon the BEA document titled "Programming Web
Services for WebLogic Server" and followed the sample in the section "Writing the Asynchronous JWS File". I followed the example to a point, but it seems to be written from the perspective of someone working at the command line, not in the Workshop IDE. The problem here is that the class with the async flavor of the desired method does not seem to exists.
I am working with Workshop9.2.
Does anyone know if the IDE is supposed to generate all these files for you, or do I have to roll my own build.xml?
Thanks.
FYI: Here is the relevant snippet from the doc referenced above
My question refers to the class used in the line
private StockQuotePortType port;
Writing the Asynchronous JWS File
The following example shows a simple JWS file that implements a Web Service called
StockQuoteClient that has a single method, asyncOperation, that in turn asynchronously
invokes the getQuote method of the StockQuote service. The Java code in bold is described
“Coding Guidelines for Invoking a Web Service Asynchronously” on page 6-23. See “Example
of a Synchronous Invoke” on page 6-25 to see how the asynchronous invoke differs from a
synchronous invoke of the same operation.
package examples.webservices.async_req_res;
import weblogic.jws.WLHttpTransport;
import weblogic.jws.ServiceClient;
import weblogic.jws.AsyncResponse;
import weblogic.jws.AsyncFailure;
import weblogic.wsee.async.AsyncPreCallContext;
import weblogic.wsee.async.AsyncCallContextFactory;
import weblogic.wsee.async.AsyncPostCallContext;
import javax.jws.WebService;
import javax.jws.WebMethod;
import examples.webservices.async_req_res.StockQuotePortType;
import java.rmi.RemoteException;
#WebService(name="StockQuoteClientPortType",
serviceName="StockQuoteClientService",
targetNamespace="http://examples.org/")
#WLHttpTransport(contextPath="asyncClient",
serviceUri="StockQuoteClient",
portName="StockQuoteClientServicePort")
/**
* Client Web Service that invokes the StockQuote Service asynchronously.
*/
public class StockQuoteClientImpl {
#ServiceClient(wsdlLocation="http://localhost:7001/async/StockQuote?WSDL",
serviceName="StockQuoteService", portName="StockQuote")
private StockQuotePortType port;
#WebMethod
public void asyncOperation (String symbol) throws RemoteException {
AsyncPreCallContext apc = AsyncCallContextFactory.getAsyncPreCallContext();
apc.setProperty("symbol", symbol);
try {
port.getQuoteAsync(apc, symbol );
System.out.println("in getQuote method of StockQuoteClient WS");
} catch (RemoteException re) {
System.out.println("RemoteException thrown");
throw new RuntimeException(re);
}
}
#AsyncResponse(target="port", operation="getQuote")
public void onGetQuoteAsyncResponse(AsyncPostCallContext apc, int quote) {
System.out.println("-------------------");
System.out.println("Got quote " + quote );
System.out.println("-------------------");
}
#AsyncFailure(target="port", operation="getQuote")
public void onGetQuoteAsyncFailure(AsyncPostCallContext apc, Throwable e) {
System.out.println("-------------------");
e.printStackTrace();
System.out.println("-------------------");
}
}

Related

JDev: Generating Web Services for Streaming Attachments

Hi,
I am a newbie in this field. I am trying to generate web service code using JDev (10.1.3.3). I have an interface class and the implementation class. When I am trying to generate J2EE Web Service for the implementation class, I am getting the following error:
"The selected class doesn't contain any public method publishable in a web service".
Following is my code:
Interface:
package testing;
import oracle.webservices.attachments.Attachments;
public interface ImageStore extends java.rmi.Remote {
public void storeImage (String name, String desc, Attachments attachments) throws java.rmi.RemoteException;
}
Impl:
package testing;
import java.io.InputStream;
import javax.activation.DataHandler;
import oracle.webservices.attachments.Attachment;
import oracle.webservices.attachments.Attachments;
import oracle.webservices.attachments.IncomingAttachments;
public class ImageStoreImpl {
public static String storeImage(String name, String desc, Attachments attachments) throws Exception {
IncomingAttachments incomingAtts = attachments.getIncomingAttachments();
{
if (incomingAtts == null || !incomingAtts.hasNextAttachment())
throw new Exception("Expected request attachments");
Attachment imageAtt = incomingAtts.nextAttachment();
String id = imageAtt.getId();
DataHandler dataHandler = imageAtt.getDataHandler();
InputStream imageStream = dataHandler.getInputStream();
//-- Store image metadata and stream image bytes
if (incomingAtts.hasNextAttachment())
throw new Exception("Expected only one attachment");
}
return "success";
}
}
Can someone please let me know how can I generate the web service for this code using JDev.
Thanks,
J 
Hi J,
Why is the concrete class not implementing the ImageStore interface? Anyways, I believe the ImageStoreImpl#storeImage method cannot be static if you want to generate a WS.
Furthermore, you should consider posting your question in the JDev 10G (JDeveloper and ADF forum as this one is for 11G.
Olivier

Access a control on server startup

I have created a startup class (StartupImpl), which is successfully being called on server startup. I have made this class a Java Control (i.e., it implements a Control interface and extends ControlSource).
I want this control to contain a timer, which gets started on startup via the T3StartupDef.startup() method. I had tried to drop a Timer Control in StartupImpl and call Timer.start() from T3StartupDef.startup(), but I get a NullPointerException.
I then used an instance of weblogic.management.timer.Timer in StartupImpl. I am able to start this timer on server startup just fine. StartupImpl also implements NotificationListener so that it gets called when the timer fires. This works too.
But now I have another issue. StartupImpl is trying to call another control. This normally works because controls can call other controls, right? So why am I getting a NullPointerException when calling a control (sampleControl) in response to a timer notification? How can I fix this?
The relevant portions of StartupImpl looks something like this:
import weblogic.management.timer.Timer;
//...other imports as necessary
public class StartupImpl implements Startup, ControlSource, T3StartupDef, NotificationListener
{
// This is a java control that I would like to access on timer notification
private SampleControl sampleControl;
private Timer timer = new Timer();
/**
* Called by server on startup, required by T3StartupDef
*/
public String startup(String arg0, Hashtable arg1) throws Exception
{
start();
return null;
}
/**
* This function can also be called by a page flow. I'm just showing the annotation
* here to demonstrate that this class is a control.
* #common:operation
*/
public void start()
{
// starts the timer and sets up the notification handler
}
public void handleNotification(Notification notif, Object handback)
{
// THIS GENERATES A NULL POINTER EXCEPTION
sampleControl.callMe();
}
} 
Hi, have you found the solution for your problem? I am facing the same problem, could you pls let me know the solution or the work around if you have any.
Thanks 
http://e-docs.bea.com/wls/docs81/javadocs/weblogic/application/ApplicationLifecycleListener.html
Prasanna Yalam

Using a Web Service Control from a Struts Action in Workshop for WebLogic10

I've seen the tutorial on how to create a Web Service Control and using it with in Web Service to call another web service, or a JSF controller to call a web service. But what about calling a web service from a Struts action? Is this possible?
Currently, I'm just using axis wsdl2java to create the client code and calling that, but I was wondering if I could use a service control instead. When I try to use it in a struts action I just get a null pointer exception. Obviously it isn't being instantiated correctly.
Has anyone been able to do this? 
it is possible in 9.x where you can do a programmatic instantiation
package poj;
import java.beans.Beans;
import org.apache.beehive.controls.test.container.ControlTestContainerContext;
import foo.serviceServiceControlBean;
import foo.serviceServiceControl;
import org.apache.beehive.controls.api.bean.ControlReferences;
#ControlReferences({foo.serviceServiceControl.class})
public class mypojo {
     private serviceServiceControl ServiceServiceControl_1;
          
     public void useDbControl() {
               
     System.err.println("webservice control invoked starting");
     
     try {
     ControlTestContainerContext containerContext = new ControlTestContainerContext();
     containerContext.beginContext();
     ServiceServiceControl_1 = (serviceServiceControlBean) Beans.instantiate(getClass().getClassLoader(), "foo.serviceServiceControlBean");
     
          ServiceServiceControl_1.hello();
     System.err.println("webservice invoked from pojo" );
     containerContext.endContext();
     } catch (Exception e) {
     System.err.println("useDbControl unexpected exception: " + e);
     }
     }
     public static void main(String a[])
     {
          
          new mypojo().useDbControl();
          }
     
     } 
Hi,
I almost got it... but I need to know what the "foo.serviceServiceControlBean" class contains... that's the only thing I'm missing.
Please help!!
Thanks,
Adrian

[Integrated SOA Gateway] Publish Java based web service

Welcome!
Lately I have been trying to publish Java based web service through Integrated SOA Gateway. The documentation states that:
+"Custom interface definitions can be created for various interface types including custom interface definitions for XML Gateway Map, Business Event, PL/SQL, Concurrent Program, Business Service Object, Java (except for Java APIs for Forms subtype) and Composite Service for BPEL type."+ (Integrated SOA Gateway Developer's Guide Release 12.1, "Creating and Using Custom Integration Interfaces")
After familiarizing myself with $FND_TOP/bin/irep_parser.pl and $FND_TOP/bin/FNDLOAD tools, I have started coding my POJOs. Initially I have come up with three classes - request/response objects and service implementation. Service implementation has been annotated with "#rep:X" descriptors according to "Java Annotations" section of the documentation. While invoking $FND_TOP/bin/irep_parser.pl I have received errors about class resolution. My solution was to transform request and response types to static inner classes. This way I ended up with one *.java source file (see below).
/**
* Sample ISG Service.
*
* #rep:scope public
* #rep:product AP
* #rep:displayname My Custom ISG Service.
*/
public class MyService {
public static class Request {
private String id;
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
}
public static class Response {
private String data;
public void setData(String data) {
this.data = data;
}
public String getData() {
return data;
}
}
/**
* Sample operation.
*
* #param request Request Object.
* #return Return Object.
* #rep:displayname Test operation.
* #rep:category BUSINESS_ENTITY SAMPLE_SERVICE
*/
public MyService.Response testOperation(MyService.Request request) {
MyService.Response response = new MyService.Response();
response.setData("Some Data");
return response;
}
}
ILDT file has been successfully created and uploaded. However, I could not see the "Generate WSDL" button on Integrated Repository website. Is there any particular interface or superclass that my service implementation should extend? I have reviewed "PurchaseOrderSDO" example posted in the developer's guide (page 407), but I couldn't come up with a working solution. Could you provide me with more detailed tutorial/example? Which documentation sections should I read again?
After searching through forum, I have spotted $FND_TOP/bin/soagenerate.sh script, and thought that lack of "Generate WSDL" button was an EBS defect. After running the script, I have received an error:
Error in Service Generation.
ServiceGenerationError: Interface Type (JAVA) Interface SubType (null) is not supported.
oracle.apps.fnd.soa.util.SOAException: ServiceGenerationError: Interface Type (JAVA) Interface SubType (null) is not supported.
     at oracle.apps.fnd.soa.provider.wsdl.ArtifactsFactory.getArtifactsGenerator(ArtifactsFactory.java:55)
     at oracle.apps.fnd.soa.provider.wsdl.WSDLGenerator.generateServiceWSDL(WSDLGenerator.java:128)
     at oracle.apps.fnd.soa.provider.wsdl.ServiceGenerator.generateSOAService(ServiceGenerator.java:75)
     at oracle.apps.fnd.soa.provider.wsdl.ServiceGenerator.generateSingleService(ServiceGenerator.java:88)
     at oracle.apps.fnd.soa.provider.wsdl.ServiceGenerator.main(ServiceGenerator.java:419)
I would be grateful for any suggestions. Has anyone published Java based web service through ISG?
Best regards,
Lukasz

Writing to log file on server

I created a public java class which does some processing. As it does the processing, it also logs information in a file. When I use the "java ClassName" command to run the main() method, the process and logging work. BUT, in my JSP when I import the class and make the same exact calls as main(), I get a NullPointerException in some of my routines that write lines to the log file.
Does anyone have any general ideas about why using my class from a JSP bombs, while using my class from the commandline is fine?
Thanks,
David Frankel
Are there any type of special permissions with the java server in order to create files (on the server) from inside a JSP ?
Thanks,
David Frankel
Well, for some reason the class I was using to log application messages was working great when called from a java program (main() method), but was failing only when invoked from JSP.
So, what I did was to just simply invoke a new PrintWriter(new BufferedWriter(new FileWriter("filename.ext"))) directly inside my javabean, which is used in my JSP. This works fine.
The only thing I can guess as the problem is that the stand-alone classes I was using as a logging agent actually implemented an "interface" defined in a third-party API. Perhaps some underlying code in the interface was causing my problem.
Thanks,
David Frankel
Hi,
Instead of logging messages on to various files, it is better to log in the default log file of the web server. There is a method
called log in ServletContext, which can be acquired from ServletConfig.
There are 2 log implmentations
a. log (String)
b. log (String , Exception)
Hope this helps,
--Rajesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
There is another way out. You can create a class and declare a public static PrintWriter object.
eg. public class ClassX extends HttpServlet {{
public static PrintWriter logError;     // this is used for logging all Error
public void init (ServletConfig config) throws ServletException {
super.init(config);
try{
logError = new PrintWriter(new FileOutputStream(new String("D:/Logs/LogError.log")),true);//initialised logError
}catch (Exception e) {}
}// end if init
Now import this class in the jsp and you can simply write in the log file in the catch block(for e.g)by:
}catch(Exception e){               
java.util.Date d = new java.util.Date();
CLassX.logError.println("Page XXXX.jsp "+e.getMessage()+">> "+s+" "+request.getRemoteAddr()+" "+request.getRemoteHost());
CLassX..logError.flush();
}
Also you can extend this class in any class file and call this class in a similiar fashion.

Categories

Resources