开发者

How can I throw exception from webservice?

I am using netbeans to make webservices, I want to make composite webservice using PBEL, I face a problem in throwing exception in each service, I define complex Type in the schema of the exception I want to throw, and I make it in WSDL too , but inside the service I don't know how can I throw the exception , Here's the example I am working on :

@WebService(serviceName = "CreditCardService", portName = "CreditCardPort", endpointInterface = "org.netbeans.j2ee.wsdl.creditcard.CreditCardPortType", targetNamespace = "http://j2ee.netbeans.org/wsdl/CreditCard", wsdlLocation = "WEB-INF/wsdl/NewWebServiceFromWSDL/CreditCard.wsdl")
public class NewWebServiceFromWSDL implements CreditCardPortType {

public org.netbeans.xml.schema.creditcard.CreditCardResponseType isCreditCardValid(org.netbeans.xml.schema.creditcard.CreditCardType creditCardInfoReq) throws IsCreditCardValidFault {

    List<CreditCardType> creditCards = parseCreditCardsFile();
开发者_运维问答    CreditCardResponseType creditCardResponseElement = new CreditCardResponseType();

    for (CreditCardType aCreditCard : creditCards) {

        if (creditCardInfoReq.getCreditCardNo() == Long.parseLong(String.valueOf(aCreditCard.getCreditCardNo())) {
            creditCardResponseElement.setValid(true);
            return creditCardResponseElement;
        }
    }
    throws  IsCreditCardValidFault();   //here I want to throw an exception .
}

Please can Someone help?


throws  IsCreditCardValidFault();   //here I want to throw an exception .

needs to be written as

throw new IsCreditCardValidFault();

throws is used in your declaration of the method, where the throw keyword is used inside the method to indicate where you will throw the exception.

so as an example

try {
   //do something which generates an exception
}catch(Exception e){
   throw e;
}

but in your case, you want to initiate the exception yourself so you have to create a new object of that exception type. You will create the exception yourself, so no need to enclose in a try/catch block.

throw new IsCreditCardValidFault();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜