Search in sources :

Example 16 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class ServiceImpl method getPortTypeName.

private QName getPortTypeName(Class<?> serviceEndpointInterface) {
    Class<?> seiClass = serviceEndpointInterface;
    if (!serviceEndpointInterface.isAnnotationPresent(WebService.class)) {
        Message msg = new Message("SEI_NO_WEBSERVICE_ANNOTATION", BUNDLE, serviceEndpointInterface.getCanonicalName());
        throw new WebServiceException(msg.toString());
    }
    if (!serviceEndpointInterface.isInterface()) {
        WebService webService = serviceEndpointInterface.getAnnotation(WebService.class);
        String epi = webService.endpointInterface();
        if (epi.length() > 0) {
            try {
                seiClass = Thread.currentThread().getContextClassLoader().loadClass(epi);
            } catch (ClassNotFoundException e) {
                Message msg = new Message("COULD_NOT_LOAD_CLASS", BUNDLE, epi);
                throw new WebServiceException(msg.toString());
            }
            if (!seiClass.isAnnotationPresent(javax.jws.WebService.class)) {
                Message msg = new Message("SEI_NO_WEBSERVICE_ANNOTATION", BUNDLE, seiClass.getCanonicalName());
                throw new WebServiceException(msg.toString());
            }
        }
    }
    WebService webService = seiClass.getAnnotation(WebService.class);
    String name = webService.name();
    if (name.length() == 0) {
        name = seiClass.getSimpleName();
    }
    String tns = webService.targetNamespace();
    if (tns.isEmpty()) {
        tns = PackageUtils.getNamespace(PackageUtils.getPackageName(seiClass));
    }
    return new QName(tns, name);
}
Also used : Message(org.apache.cxf.common.i18n.Message) WebServiceException(javax.xml.ws.WebServiceException) WebService(javax.jws.WebService) QName(javax.xml.namespace.QName)

Example 17 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class AnnotationHandlerChainBuilder method buildHandlerChainFromClass.

/**
 * @param clz
 * @param existingHandlers
 * @return
 */
public List<Handler> buildHandlerChainFromClass(Class<?> clz, List<Handler> existingHandlers, QName portQName, QName serviceQName, String bindingID) {
    LOG.fine("building handler chain");
    HandlerChainAnnotation hcAnn = findHandlerChainAnnotation(clz, true);
    final List<Handler> chain;
    if (hcAnn == null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("no HandlerChain annotation on " + clz);
        }
        chain = new ArrayList<>();
    } else {
        hcAnn.validate();
        try {
            URL handlerFileURL = resolveHandlerChainFile(clz, hcAnn.getFileName());
            if (handlerFileURL == null) {
                throw new WebServiceException(new Message("HANDLER_CFG_FILE_NOT_FOUND_EXC", BUNDLE, hcAnn.getFileName()).toString());
            }
            Document doc = StaxUtils.read(handlerFileURL.openStream());
            Element el = doc.getDocumentElement();
            boolean isJavaEENamespace = JavaeeHandlerChainBuilder.JAVAEE_NS.equals(el.getNamespaceURI());
            boolean isJakartaEENamespace = JakartaeeHandlerChainBuilder.JAKARTAEE_NS.equals(el.getNamespaceURI());
            if (!isJavaEENamespace && !isJakartaEENamespace) {
                throw new WebServiceException(BundleUtils.getFormattedString(BUNDLE, "NOT_VALID_NAMESPACE", el.getNamespaceURI()));
            }
            final ClassLoader classLoader = getClassLoader(clz);
            final DelegatingHandlerChainBuilder delegate = ht -> buildHandlerChain(ht, classLoader);
            if (isJavaEENamespace) {
                chain = new JavaeeHandlerChainBuilder(BUNDLE, handlerFileURL, delegate).build(el, portQName, serviceQName, bindingID);
            } else {
                chain = new JakartaeeHandlerChainBuilder(BUNDLE, handlerFileURL, delegate).build(el, portQName, serviceQName, bindingID);
            }
        } catch (WebServiceException e) {
            throw e;
        } catch (Exception e) {
            throw new WebServiceException(BUNDLE.getString("CHAIN_NOT_SPECIFIED_EXC"), e);
        }
    }
    assert chain != null;
    if (existingHandlers != null) {
        chain.addAll(existingHandlers);
    }
    return sortHandlers(chain);
}
Also used : WebService(javax.jws.WebService) Bus(org.apache.cxf.Bus) URL(java.net.URL) StringUtils(org.apache.cxf.common.util.StringUtils) PrivilegedAction(java.security.PrivilegedAction) Logger(java.util.logging.Logger) ClassLoaderUtils(org.apache.cxf.common.classloader.ClassLoaderUtils) Message(org.apache.cxf.common.i18n.Message) HandlerChain(javax.jws.HandlerChain) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) List(java.util.List) Handler(javax.xml.ws.handler.Handler) BundleUtils(org.apache.cxf.common.i18n.BundleUtils) WebServiceException(javax.xml.ws.WebServiceException) Element(org.w3c.dom.Element) ResourceBundle(java.util.ResourceBundle) LogUtils(org.apache.cxf.common.logging.LogUtils) Document(org.w3c.dom.Document) QName(javax.xml.namespace.QName) AccessController(java.security.AccessController) StaxUtils(org.apache.cxf.staxutils.StaxUtils) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.common.i18n.Message) Element(org.w3c.dom.Element) Handler(javax.xml.ws.handler.Handler) Document(org.w3c.dom.Document) URL(java.net.URL) WebServiceException(javax.xml.ws.WebServiceException)

Example 18 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class JAXWSMethodDispatcher method bind.

public void bind(OperationInfo o, Method... methods) {
    Method[] newMethods = new Method[methods.length];
    int i = 0;
    for (Method m : methods) {
        try {
            newMethods[i] = getImplementationMethod(m);
            i++;
        } catch (NoSuchMethodException e) {
            if (m.getName().endsWith("Async") && (Future.class.equals(m.getReturnType()) || Response.class.equals(m.getReturnType()))) {
                newMethods[i] = m;
                i++;
                continue;
            }
            Class<?> endpointClass = implInfo.getImplementorClass();
            Message msg = new Message("SEI_METHOD_NOT_FOUND", LOG, m.getName(), endpointClass.getName());
            throw new ServiceConstructionException(msg, e);
        }
    }
    super.bind(o, newMethods);
}
Also used : Message(org.apache.cxf.common.i18n.Message) Method(java.lang.reflect.Method) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 19 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class AbstractInvoker method createFault.

protected Fault createFault(Throwable ex, Method m, List<Object> params, boolean checked) {
    if (checked) {
        return new Fault(ex);
    }
    String message = (ex == null) ? "" : ex.getMessage();
    String method = (m == null) ? "<null>" : m.toString();
    return new Fault(new Message("EXCEPTION_INVOKING_OBJECT", LOG, message, method, params), ex);
}
Also used : Message(org.apache.cxf.common.i18n.Message) Fault(org.apache.cxf.interceptor.Fault)

Example 20 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class AbstractInvoker method invoke.

public Object invoke(Exchange exchange, Object o) {
    final Object serviceObject = getServiceObject(exchange);
    try {
        BindingOperationInfo bop = exchange.getBindingOperationInfo();
        MethodDispatcher md = (MethodDispatcher) exchange.getService().get(MethodDispatcher.class.getName());
        Method m = bop == null ? null : md.getMethod(bop);
        if (m == null && bop == null) {
            LOG.severe(new Message("MISSING_BINDING_OPERATION", LOG).toString());
            throw new Fault(new Message("EXCEPTION_INVOKING_OBJECT", LOG, "No binding operation info", "unknown method", "unknown"));
        }
        List<Object> params = null;
        if (o instanceof List) {
            params = CastUtils.cast((List<?>) o);
        } else if (o != null) {
            params = new MessageContentsList(o);
        }
        m = adjustMethodAndParams(m, exchange, params, serviceObject.getClass());
        // Method m = (Method)bop.getOperationInfo().getProperty(Method.class.getName());
        m = matchMethod(m, serviceObject);
        return invoke(exchange, serviceObject, m, params);
    } finally {
        releaseServiceObject(exchange, serviceObject);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) Fault(org.apache.cxf.interceptor.Fault) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) Method(java.lang.reflect.Method)

Aggregations

Message (org.apache.cxf.common.i18n.Message)201 ToolException (org.apache.cxf.tools.common.ToolException)69 IOException (java.io.IOException)45 QName (javax.xml.namespace.QName)42 Fault (org.apache.cxf.interceptor.Fault)34 XMLStreamException (javax.xml.stream.XMLStreamException)27 JAXBException (javax.xml.bind.JAXBException)23 ArrayList (java.util.ArrayList)19 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)17 Element (org.w3c.dom.Element)17 File (java.io.File)16 WSDLException (javax.wsdl.WSDLException)15 Method (java.lang.reflect.Method)14 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)13 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)12 InputStream (java.io.InputStream)11 HashMap (java.util.HashMap)11 List (java.util.List)11 Map (java.util.Map)11 ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)11