ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to throw a custom exception from a WMB6 web service?

Post new topic  Reply to topic
 How to throw a custom exception from a WMB6 web service? « View previous topic :: View next topic » 
Author Message
simon.starkie
PostPosted: Mon Dec 03, 2007 2:03 pm    Post subject: How to throw a custom exception from a WMB6 web service? Reply with quote

Disciple

Joined: 24 Mar 2002
Posts: 180

I have a WBM6 message flow exposed as a web service.
When something goes wrong, I need to throw an exception with a custom message, so I used this:
THROW USER EXCEPTION
MESSAGE 2950
VALUES
(
'patientMRN:',InputLocalEnvironment.Variables.MRN
,'regionCode:',InputLocalEnvironment.Variables.IDTYPE
,'errorMessage:',OutputRoot.XMLNSC.ns:KPChartException.ns:errorMessage
)
;

The intent is to allow the web service client code running in WAS to catch the exception and retrieve the custom message:
// instantiate config file (singleton) and check if loaded
ConfigFile cfg = ConfigFile.getConfigFile();

// create KPChartRequest instance
GetKPChartRequestType KPChartRequest = buildKPChartRequest(MRN1, REGION1, DOB1, MRN2, REGION2, DOB2);

// Invoke KPChartService web service to get the Medications
try
{
URL URL = new java.net.URL(ConfigFile.url);
KPChartServiceBindingStub ws = new KPChartServiceBindingStub(URL,svc);
i = Integer.parseInt(ConfigFile.timeout);
ws.setTimeout(i * 1000); // milliseconds
MedicationResponse = ws.getMedication(KPChartRequest);
}
catch (KPChartExceptionType e) {
System.out.println("KPChartException in Medication processing"
+"\nPatientMRN="+e.getPatientMRN().toString()
+"\nRegion="+e.getRegion()
+"\nErrorMessage="+e.getErrorMessage()
);
throw new RuntimeException(e);
}
catch (MalformedURLException e)
{
System.out.println("MalformedURLException in ConfigFile"
+ "/nurl"
);
throw new RuntimeException(e);
}
catch (WebServicesFault e) {
System.out.println("WebServicesFault in Medication processing");
if (e.getFaultDetails() != null)
{
int i = e.getFaultDetails().length;
int j = 0;
while (i > j)
{
System.out.println("\n" + e.getFaultDetails()[j]
);
j++;
}
}
else
System.out.println("WebServicesFault in Medication processing"
+ "\n" + e.getMessage());

throw new RuntimeException(e);
}
catch (RemoteException e)
{
System.out.println("RemoteException in Medication processing"
);
throw new RuntimeException(e);
}

return MedicationResponse;


But this only results in a WebServicesFault being caught in my client.
I never get the KPChartExceptionType so I can't get at the KPChartExceptionType elements.

I looked into writing my own Java Compute Node with code to throw my own KPChartException, but evidently "throws MbException" is the only allowable choice on the Java method "public void evaluate(MbMessageAssembly assembly)" and even when I did change it, the deployment failed but I don't recall the exact error.

So how do I throw a custom exception from a WMB6 web service?
Or is there a limitation in WMB6 that precludes doing this.
Thanks.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Dec 03, 2007 2:49 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

So, why can't you return a SOAP error message?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
simon.starkie
PostPosted: Mon Dec 03, 2007 3:15 pm    Post subject: Reply with quote

Disciple

Joined: 24 Mar 2002
Posts: 180

jefflowrey wrote:
So, why can't you return a SOAP error message?


Good idea. But...
The code to invoke the web service:
MedicationResponse = ws.getMedication(KPChartRequest);
expects to receive the MedicationResponse message and nothing else
so I'm not sure how returning a SOAP error message would work with that.

But this does suggest an alternative of having the service append the KPChartExceptionType as an optional node at the end of the MedicationResponse message so that the Client can check and if present, look to see what kind of error occurred. Doesn't seem very elegant though...
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Dec 03, 2007 3:26 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Right, so somewhere behind that webservice exception is the HTTP fault or SOAP fault that is supposed to actually pass over the wire to create it.

Because remember that, pretty much, web services are HTTP+SOAP...

So you can maybe generate something that throws that exception, intercept the HTTP traffic, and see what's supposed to be sent.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
simon.starkie
PostPosted: Tue Dec 04, 2007 5:01 pm    Post subject: Reply with quote

Disciple

Joined: 24 Mar 2002
Posts: 180

So I tried adding the following to my ESQL:
SET OutputRoot.XMLNSC.null6:Fault.faultcode = 'SOAP-ENV:org.kp.svc.KPChartExceptionType';
SET OutputRoot.XMLNSC.null6:Fault.faultstring = 'org.kp.svc.KPChartExceptionType';
SET OutputRoot.XMLNSC.null6:Fault.faultactor = 'org.kp.svc.KPChartExceptionType';
SET OutputRoot.XMLNSC.null6:Fault.detail = 'org.kp.svc.KPChartExceptionType';

(yes a bit of an overkill since I set all of the available Fault elements to my fully qualified org.kp.svc.KPChartExceptionType)

but over on the Java client side, the emitted code:

public org.kp.svc.GetProblemListResponseType getProblemList(org.kp.svc.GetKPChartRequestType body) throws java.rmi.RemoteException, org.kp.svc.KPChartExceptionType {
if (super.cachedEndpoint == null) {
throw new com.ibm.ws.webservices.engine.NoEndPointException();
}
java.util.Vector _resp = null;
try {
_resp = _getgetProblemListInvoke0(new java.lang.Object[] {body}).invoke();

} catch (com.ibm.ws.webservices.engine.WebServicesFault wsf) {
Exception e = wsf.getUserException();
if (e != null) {
if (e instanceof org.kp.svc.KPChartExceptionType) {
throw (org.kp.svc.KPChartExceptionType) e;
}
}
throw wsf;


never made it to the highlighted throw (org.kp.svc.KPChartExceptionType) e;
because the instance of e was a SOAPFaultException instead of the org.kp.svc.KPChartExceptionType

So I think it's more involved than just setting a SOAP fault ...
It looks like the Broker just has to throw a org.kp.svc.KPChartExceptionType ...
But I can't see a way of doing that ...

This is a problem since a Broker hosted web service cannot, apparently, throw a custom exception like a typical Java or .NET service can. I hope that's wrong.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Dec 04, 2007 5:16 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

You're not connected to Broker in a way that a Java exception can pass across the wire.

It's HTTP!

It's not Java RMI, even though the web client makes it look that way.

Among other things, it's possible that this exception is not throwable from anything other than an error on the client side (not the server side, where broker is).
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
simon.starkie
PostPosted: Wed Dec 05, 2007 11:40 am    Post subject: Reply with quote

Disciple

Joined: 24 Mar 2002
Posts: 180

I was able to get it working the way I wanted.
The trick is to get the Broker to create an appropriate SOAP Fault.
Here is the ESQL code that worked (it's just a test):
-- setup a SOAP fault
SET OutputRoot.XMLNSC.null6:Fault.faultcode = 'FaultCode'; --'SOAP-ENV:Server';
SET OutputRoot.XMLNSC.null6:Fault.faultstring = 'KPChartException';
SET OutputRoot.XMLNSC.null6:Fault.faultactor = 'FaultActor';
SET OutputRoot.XMLNSC.null6:Fault.detail.ns1:KPChartException.ns1:region.ns1:code
= 'NCA';
SET OutputRoot.XMLNSC.null6:Fault.detail.ns1:KPChartException.ns1:patientMRN
= '123456790';
SET OutputRoot.XMLNSC.null6:Fault.detail.ns1:KPChartException.ns1:errorMessage
= 'you loose sucker';


This result in the necessary KPChartException instanceof being thrown on the client side in the Java code emitted from WSDL.

public org.kp.svc.GetProblemListResponseType getProblemList(org.kp.svc.GetKPChartRequestType body) throws java.rmi.RemoteException, org.kp.svc.KPChartExceptionType {
if (super.cachedEndpoint == null) {
throw new com.ibm.ws.webservices.engine.NoEndPointException();
}
java.util.Vector _resp = null;
try {
_resp = _getgetProblemListInvoke0(new java.lang.Object[] {body}).invoke();

} catch (com.ibm.ws.webservices.engine.WebServicesFault wsf) {
Exception e = wsf.getUserException();
if (e != null) {
if (e instanceof org.kp.svc.KPChartExceptionType) { throw (org.kp.svc.KPChartExceptionType) e;
}
}
throw wsf;


Then, the rest of the Java client code able to catch the KPChartExceptionType and display the elements contained in the KPChartExceptionType:

catch (KPChartExceptionType e)
{
System.out.println("KPChartException in ProblemList processing"
+"\nPatientMRN="+e.getPatientMRN().toString()
+"\nRegion="+e.getRegion()
+"\nErrorMessage="+e.getErrorMessage()
);
throw new RuntimeException(e);

Cheers!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to throw a custom exception from a WMB6 web service?
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.