當前位置: 首頁>>代碼示例>>Java>>正文


Java WebFault類代碼示例

本文整理匯總了Java中javax.xml.ws.WebFault的典型用法代碼示例。如果您正苦於以下問題:Java WebFault類的具體用法?Java WebFault怎麽用?Java WebFault使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebFault類屬於javax.xml.ws包,在下文中一共展示了WebFault類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testForWebFaultAnnotationInExceptions

import javax.xml.ws.WebFault; //導入依賴的package包/類
@Test
public void testForWebFaultAnnotationInExceptions() throws Exception {
    StringBuffer errors = new StringBuffer();
    List<Class<?>> classes = PackageClassReader.getClasses(
            CurrencyException.class, Throwable.class,
            ClassFilter.CLASSES_ONLY);
    for (Class<?> clazz : getApplicationExceptions(classes)) {
        WebFault annotation = clazz.getAnnotation(WebFault.class);
        if (annotation == null) {
            errors.append("Class ").append(clazz.getName())
                    .append(" misses WebFault annotation\n");
            continue;
        }
        String name = annotation.name();
        if (!name.equals(clazz.getSimpleName())) {
            errors.append("Class ").append(clazz.getName())
                    .append(" uses a WebFault name annotation that ")
                    .append("does not match the class name.\n");
        }
    }
    if (errors.length() > 0) {
        fail("Exceptions without constructor(String):\n"
                + errors.toString());
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:26,代碼來源:ExceptionClassTest.java

示例2: createFaultFromException

import javax.xml.ws.WebFault; //導入依賴的package包/類
/**
 * Creates a SOAP fault from the exception and populates the message as well
 * as the detail. The detail object is read from the method getFaultInfo of
 * the throwable if present
 * 
 * @param exception the cause exception
 * @return SOAP fault from given Throwable
 */
@SuppressWarnings("unchecked")
private JAXBElement<Fault> createFaultFromException(final Throwable exception) {
    WebFault webFault = exception.getClass().getAnnotation(WebFault.class);
    if (webFault == null || webFault.targetNamespace() == null) {
        throw new RuntimeException("The exception " + exception.getClass().getName()
                + " needs to have an WebFault annotation with name and targetNamespace", exception);
    }
    QName name = new QName(webFault.targetNamespace(), webFault.name());
    Object faultObject;
    try {
        Method method = exception.getClass().getMethod("getFaultInfo");
        faultObject = method.invoke(exception);
    } catch (Exception e) {
        throw new RuntimeCamelException("Exception while trying to get fault details", e);
    }
    Fault fault = new Fault();
    fault.setFaultcode(FAULT_CODE_SERVER);
    fault.setFaultstring(exception.getMessage());
    Detail detailEl = new ObjectFactory().createDetail();
    @SuppressWarnings("rawtypes")
    JAXBElement<?> faultDetailContent = new JAXBElement(name, faultObject.getClass(), faultObject);
    detailEl.getAny().add(faultDetailContent);
    fault.setDetail(detailEl);
    return new ObjectFactory().createFault(fault);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:34,代碼來源:Soap11DataFormatAdapter.java

示例3: getFaultBean

import javax.xml.ws.WebFault; //導入依賴的package包/類
public String getFaultBean() {
    if (faultBean != null && faultBean.length() > 0) {
        // Return the faultBean if it was already calculated
        return faultBean;
    } else {
        // Load up the WebFault annotation and get the faultBean.
        // @WebFault may not be present
        WebFault annotation = getAnnoWebFault();

        if (annotation != null && annotation.faultBean() != null &&
                annotation.faultBean().length() > 0) {
            faultBean = annotation.faultBean();
        } else {
            // There is no default.  But it seems reasonable to return
            // the fault info type.
            faultBean = getFaultInfo();

            // The faultBean still may be "" at this point.  The JAXWS runtime
            // is responsible for finding/buildin a representative fault bean.
        }
    }
    return faultBean;
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:24,代碼來源:FaultDescriptionImpl.java

示例4: getName

import javax.xml.ws.WebFault; //導入依賴的package包/類
public String getName() {
    if (name.length() > 0) {
        return name;
    } else {
        // Load the annotation. The annotation may not be present in WSGen cases
        WebFault annotation = this.getAnnoWebFault();
        if (annotation != null &&
                annotation.name().length() > 0) {
            name = annotation.name();
        } else {
            // The default is undefined.
            // The JAX-WS layer may use the fault bean information to determine the name
        }
    }
    return name;
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:17,代碼來源:FaultDescriptionImpl.java

示例5: getTargetNamespace

import javax.xml.ws.WebFault; //導入依賴的package包/類
public String getTargetNamespace() {
    if (targetNamespace.length() > 0) {
        return targetNamespace;
    } else {
        // Load the annotation. The annotation may not be present in WSGen cases
        WebFault annotation = this.getAnnoWebFault();
        if (annotation != null &&
                annotation.targetNamespace().length() > 0) {
            targetNamespace = annotation.targetNamespace();
        } else {
            // The default is undefined
            // The JAX-WS layer may use the fault bean information to determine the name
        }
    }
    return targetNamespace;
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:17,代碼來源:FaultDescriptionImpl.java

示例6: createFaultFromException

import javax.xml.ws.WebFault; //導入依賴的package包/類
/**
 * Creates a SOAP fault from the exception and populates the message as well
 * as the detail. The detail object is read from the method getFaultInfo of
 * the throwable if present
 * 
 * @param exception the cause exception
 * @return SOAP fault from given Throwable
 */
@SuppressWarnings("unchecked")
private JAXBElement<Fault> createFaultFromException(final Throwable exception) {
    WebFault webFault = exception.getClass().getAnnotation(WebFault.class);
    if (webFault == null || webFault.targetNamespace() == null) {
        throw new RuntimeException("The exception " + exception.getClass().getName()
                + " needs to have an WebFault annotation with name and targetNamespace", exception);
    }
    QName name = new QName(webFault.targetNamespace(), webFault.name());
    Object faultObject;
    try {
        Method method = exception.getClass().getMethod("getFaultInfo");
        faultObject = method.invoke(exception);
    } catch (Exception e) {
        throw new RuntimeCamelException("Exception while trying to get fault details", e);
    }

    Fault fault = new Fault();
    Faultcode code = new Faultcode();
    code.setValue(FAULT_CODE_SERVER);
    fault.setCode(code);

    Reasontext text = new Reasontext();
    text.setValue(exception.getMessage());
    text.setLang("en");
    fault.setReason(new Faultreason().withText(text));

    Detail detailEl = new ObjectFactory().createDetail();
    @SuppressWarnings("rawtypes")
    JAXBElement<?> faultDetailContent = new JAXBElement(name, faultObject.getClass(), faultObject);
    detailEl.getAny().add(faultDetailContent);
    fault.setDetail(detailEl);
    return new ObjectFactory().createFault(fault);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:42,代碼來源:Soap12DataFormatAdapter.java

示例7: addExceptions

import javax.xml.ws.WebFault; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void addExceptions(Method method) {
    Class<?>[] exTypes = method.getExceptionTypes();
    for (Class<?> exType : exTypes) {
        WebFault webFault = exType.getAnnotation(WebFault.class);
        if (webFault != null) {
            QName faultName = new QName(webFault.targetNamespace(), webFault.name());
            faultNameToException.put(faultName, (Class<? extends Exception>) exType);
        }
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:12,代碼來源:ServiceInterfaceStrategy.java

示例8: getAnnoWebFault

import javax.xml.ws.WebFault; //導入依賴的package包/類
public WebFault getAnnoWebFault() {

        if (annotation == null) {
            if (isDBC()) {
                annotation = this.composite.getWebFaultAnnot();
            }
        }

        return annotation;
    }
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:11,代碼來源:FaultDescriptionImpl.java

示例9: getMessageName

import javax.xml.ws.WebFault; //導入依賴的package包/類
public String getMessageName(){
	if(messageName.length()>0){
		return name;
	}else{
		WebFault annotation= this.getAnnoWebFault();
		if(annotation!=null && annotation.messageName().length()>0){
			messageName=annotation.messageName();
		}else{
			// The default is undefined.
            // The JAX-WS layer may use the fault bean information to determine the name
		}
	}
	return messageName;
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:15,代碼來源:FaultDescriptionImpl.java

示例10: attachWebFaultAnnotation

import javax.xml.ws.WebFault; //導入依賴的package包/類
/**
 * This method will be used to attach @WebFault annotation data to the
 * <code>DescriptionBuilderComposite</code>
 *
 * @param composite - <code>DescriptionBuilderComposite</code>
 */
private void attachWebFaultAnnotation(DescriptionBuilderComposite composite) {
    WebFault webFault = (WebFault)ConverterUtils.getAnnotation(
            WebFault.class, serviceClass);
    if (webFault != null) {
        WebFaultAnnot webFaultAnnot = WebFaultAnnot.createWebFaultAnnotImpl();
        webFaultAnnot.setFaultBean(webFault.faultBean());
        webFaultAnnot.setName(webFault.name());
        webFaultAnnot.setTargetNamespace(webFault.targetNamespace());
        webFaultAnnot.setMessageName(webFault.messageName());
        composite.setWebFaultAnnot(webFaultAnnot);
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:19,代碼來源:JavaClassToDBCConverter.java

示例11: write

import javax.xml.ws.WebFault; //導入依賴的package包/類
private void write(Fault fault) throws JClassAlreadyExistsException {
    String className = Names.customExceptionClassName(fault);

    JDefinedClass cls = cm._class(className, ClassType.CLASS);
    JDocComment comment = cls.javadoc();
    if(fault.getJavaDoc() != null){
        comment.add(fault.getJavaDoc());
        comment.add("\n\n");
    }

    for (String doc : getJAXWSClassComment()) {
        comment.add(doc);
    }

    cls._extends(java.lang.Exception.class);

    //@WebFault
    JAnnotationUse faultAnn = cls.annotate(WebFault.class);
    faultAnn.param("name", fault.getBlock().getName().getLocalPart());
    faultAnn.param("targetNamespace", fault.getBlock().getName().getNamespaceURI());

    JType faultBean = fault.getBlock().getType().getJavaType().getType().getType();

    //faultInfo filed
    JFieldVar fi = cls.field(JMod.PRIVATE, faultBean, "faultInfo");

    //add jaxb annotations
    fault.getBlock().getType().getJavaType().getType().annotate(fi);

    fi.javadoc().add("Java type that goes as soapenv:Fault detail element.");
    JFieldRef fr = JExpr.ref(JExpr._this(), fi);

    //Constructor
    JMethod constrc1 = cls.constructor(JMod.PUBLIC);
    JVar var1 = constrc1.param(String.class, "message");
    JVar var2 = constrc1.param(faultBean, "faultInfo");
    constrc1.javadoc().addParam(var1);
    constrc1.javadoc().addParam(var2);
    JBlock cb1 = constrc1.body();
    cb1.invoke("super").arg(var1);

    cb1.assign(fr, var2);

    //constructor with Throwable
    JMethod constrc2 = cls.constructor(JMod.PUBLIC);
    var1 = constrc2.param(String.class, "message");
    var2 = constrc2.param(faultBean, "faultInfo");
    JVar var3 = constrc2.param(Throwable.class, "cause");
    constrc2.javadoc().addParam(var1);
    constrc2.javadoc().addParam(var2);
    constrc2.javadoc().addParam(var3);
    JBlock cb2 = constrc2.body();
    cb2.invoke("super").arg(var1).arg(var3);
    cb2.assign(fr, var2);


    //getFaultInfo() method
    JMethod fim = cls.method(JMod.PUBLIC, faultBean, "getFaultInfo");
    fim.javadoc().addReturn().add("returns fault bean: "+faultBean.fullName());
    JBlock fib = fim.body();
    fib._return(fi);
    fault.setExceptionClass(cls);

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:65,代碼來源:CustomExceptionGenerator.java

示例12: generateExceptionBean

import javax.xml.ws.WebFault; //導入依賴的package包/類
private boolean generateExceptionBean(TypeElement thrownDecl, String beanPackage) {
    if (!builder.isServiceException(thrownDecl.asType()))
        return false;

    String exceptionName = ClassNameInfo.getName(thrownDecl.getQualifiedName().toString());
    if (processedExceptions.contains(exceptionName))
        return false;
    processedExceptions.add(exceptionName);
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    String className = beanPackage+ exceptionName + BEAN.getValue();

    Collection<MemberInfo> members = ap_generator.collectExceptionBeanMembers(thrownDecl);
    boolean isWSDLException = isWSDLException(members, thrownDecl);
    String namespace = typeNamespace;
    String name = exceptionName;
    FaultInfo faultInfo;
    if (isWSDLException) {
        TypeMirror beanType =  getFaultInfoMember(members).getParamType();
        faultInfo = new FaultInfo(TypeMonikerFactory.getTypeMoniker(beanType), true);
        namespace = webFault.targetNamespace().length()>0 ?
                           webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
                      webFault.name() : name;
        faultInfo.setElementName(new QName(namespace, name));
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (webFault != null) {
        namespace = webFault.targetNamespace().length()>0 ?
                    webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
               webFault.name() : name;
        className = webFault.faultBean().length()>0 ?
                    webFault.faultBean() : className;

    }
    JDefinedClass cls = getCMClass(className, CLASS);
    faultInfo = new FaultInfo(className, false);

    if (duplicateName(className)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_EXCEPTION_BEAN_NAME_NOT_UNIQUE(
                typeElement.getQualifiedName(), thrownDecl.getQualifiedName()));
    }

    boolean canOverWriteBean = builder.canOverWriteClass(className);
    if (!canOverWriteBean) {
        builder.log("Class " + className + " exists. Not overwriting.");
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (seiContext.getExceptionBeanName(thrownDecl.getQualifiedName()) != null)
        return false;

    //write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    for (String doc : GeneratorBase.getJAXWSClassComment(ToolVersion.VERSION.MAJOR_VERSION)) {
        comment.add(doc);
    }

    // XmlElement Declarations
    writeXmlElementDeclaration(cls, name, namespace);

    // XmlType Declaration
    //members = sortMembers(members);
    XmlType xmlType = thrownDecl.getAnnotation(XmlType.class);
    String xmlTypeName = (xmlType != null && !xmlType.name().equals("##default")) ? xmlType.name() : exceptionName;
    String xmlTypeNamespace = (xmlType != null && !xmlType.namespace().equals("##default")) ? xmlType.namespace() : typeNamespace;
    writeXmlTypeDeclaration(cls, xmlTypeName, xmlTypeNamespace, members);

    writeMembers(cls, members);

    seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:75,代碼來源:WebServiceWrapperGenerator.java

示例13: isWSDLException

import javax.xml.ws.WebFault; //導入依賴的package包/類
protected boolean isWSDLException(Collection<MemberInfo> members, TypeElement thrownDecl) {
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    return webFault != null && members.size() == 2 && getFaultInfoMember(members) != null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:5,代碼來源:WebServiceWrapperGenerator.java

示例14: generateExceptionBean

import javax.xml.ws.WebFault; //導入依賴的package包/類
private boolean generateExceptionBean(TypeElement thrownDecl, String beanPackage) {
    if (!builder.isServiceException(thrownDecl.asType()))
        return false;

    String exceptionName = ClassNameInfo.getName(thrownDecl.getQualifiedName().toString());
    if (processedExceptions.contains(exceptionName))
        return false;
    processedExceptions.add(exceptionName);
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    String className = beanPackage+ exceptionName + BEAN.getValue();

    Collection<MemberInfo> members = ap_generator.collectExceptionBeanMembers(thrownDecl);
    boolean isWSDLException = isWSDLException(members, thrownDecl);
    String namespace = typeNamespace;
    String name = exceptionName;
    FaultInfo faultInfo;
    if (isWSDLException) {
        TypeMirror beanType =  getFaultInfoMember(members).getParamType();
        faultInfo = new FaultInfo(TypeMonikerFactory.getTypeMoniker(beanType), true);
        namespace = webFault.targetNamespace().length()>0 ?
                           webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
                      webFault.name() : name;
        faultInfo.setElementName(new QName(namespace, name));
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (webFault != null) {
        namespace = webFault.targetNamespace().length()>0 ?
                    webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
               webFault.name() : name;
        className = webFault.faultBean().length()>0 ?
                    webFault.faultBean() : className;

    }
    JDefinedClass cls = getCMClass(className, CLASS);
    faultInfo = new FaultInfo(className, false);

    if (duplicateName(className)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_EXCEPTION_BEAN_NAME_NOT_UNIQUE(
                typeElement.getQualifiedName(), thrownDecl.getQualifiedName()));
    }

    boolean canOverWriteBean = builder.canOverWriteClass(className);
    if (!canOverWriteBean) {
        builder.log("Class " + className + " exists. Not overwriting.");
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (seiContext.getExceptionBeanName(thrownDecl.getQualifiedName()) != null) {
        return false;
    }

    addGeneratedFile(className);

    //write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    for (String doc : GeneratorBase.getJAXWSClassComment(ToolVersion.VERSION.MAJOR_VERSION)) {
        comment.add(doc);
    }

    // XmlElement Declarations
    writeXmlElementDeclaration(cls, name, namespace);

    // XmlType Declaration
    //members = sortMembers(members);
    XmlType xmlType = thrownDecl.getAnnotation(XmlType.class);
    String xmlTypeName = (xmlType != null && !xmlType.name().equals("##default")) ? xmlType.name() : exceptionName;
    String xmlTypeNamespace = (xmlType != null && !xmlType.namespace().equals("##default")) ? xmlType.namespace() : typeNamespace;
    writeXmlTypeDeclaration(cls, xmlTypeName, xmlTypeNamespace, members);

    writeMembers(cls, members);

    seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:78,代碼來源:WebServiceWrapperGenerator.java

示例15: checkFailure

import javax.xml.ws.WebFault; //導入依賴的package包/類
private void checkFailure(org.apache.camel.Exchange camelExchange, Exchange cxfExchange) throws Fault {
    final Throwable t;
    if (camelExchange.isFailed()) {
        org.apache.camel.Message camelMsg = camelExchange.hasOut() ? camelExchange.getOut() : camelExchange.getIn();
        if (camelMsg.isFault()) {
            t = camelMsg.getBody(Throwable.class);
        } else {
            t = camelExchange.getException();
        }
        cxfExchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
        if (t instanceof Fault) {
            cxfExchange.getInMessage().put(FaultMode.class, FaultMode.CHECKED_APPLICATION_FAULT);
            throw (Fault)t;
        } else if (t != null) {
            // This is not a CXF Fault. Build the CXF Fault manually.
            Fault fault = new Fault(t);
            if (fault.getMessage() == null) {
                // The Fault has no Message. This is the case if it has
                // no message, for example was a NullPointerException.
                fault.setMessage(t.getClass().getSimpleName());
            }
            WebFault faultAnnotation = t.getClass().getAnnotation(WebFault.class);
            Object faultInfo = null;
            try {
                Method method = t.getClass().getMethod("getFaultInfo");
                faultInfo = method.invoke(t, new Object[0]);
            } catch (Exception e) {
                // do nothing here
            }
            if (faultAnnotation != null && faultInfo == null) {
                // t has a JAX-WS WebFault annotation, which describes
                // in detail the Web Service Fault that should be thrown. Add the
                // detail.
                Element detail = fault.getOrCreateDetail();
                Element faultDetails = detail.getOwnerDocument()
                    .createElementNS(faultAnnotation.targetNamespace(), faultAnnotation.name());
                detail.appendChild(faultDetails);
            }

            throw fault;
        }

    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:45,代碼來源:CxfConsumer.java


注:本文中的javax.xml.ws.WebFault類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。