Search in sources :

Example 21 with Message

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

the class PerRequestFactory method create.

public Object create(Exchange ex) throws Throwable {
    try {
        if (svcClass.isInterface()) {
            throw new Fault(new Message("SVC_CLASS_IS_INTERFACE", BUNDLE, svcClass.getName()));
        }
        if (Modifier.isAbstract(svcClass.getModifiers())) {
            throw new Fault(new Message("SVC_CLASS_IS_ABSTRACT", BUNDLE, svcClass.getName()));
        }
        Object o = svcClass.newInstance();
        Bus b = ex.getBus();
        ResourceManager resourceManager = b.getExtension(ResourceManager.class);
        if (resourceManager != null) {
            ResourceInjector injector = new ResourceInjector(resourceManager);
            injector.inject(o);
            injector.construct(o);
        }
        return o;
    } catch (InstantiationException e) {
        throw new Fault(new Message("COULD_NOT_INSTANTIATE", BUNDLE), e);
    } catch (IllegalAccessException e) {
        throw new Fault(new Message("ILLEGAL_ACCESS", BUNDLE), e);
    }
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.cxf.common.i18n.Message) Fault(org.apache.cxf.interceptor.Fault) ResourceManager(org.apache.cxf.resource.ResourceManager) ResourceInjector(org.apache.cxf.common.injection.ResourceInjector)

Example 22 with Message

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

the class SoapFault method createFault.

public static SoapFault createFault(Fault f, SoapVersion v) {
    if (f instanceof SoapFault) {
        // if it's one of our internal codes, map it to the proper soap code
        if (f.getFaultCode().getNamespaceURI().equals(Fault.FAULT_CODE_CLIENT.getNamespaceURI())) {
            QName fc = f.getFaultCode();
            if (Fault.FAULT_CODE_CLIENT.equals(fc)) {
                fc = v.getSender();
            } else if (Fault.FAULT_CODE_SERVER.equals(fc)) {
                fc = v.getReceiver();
            }
            f.setFaultCode(fc);
        }
        if (v == Soap12.getInstance()) {
            updateSoap12FaultCodes((SoapFault) f);
        }
        return (SoapFault) f;
    }
    QName fc = f.getFaultCode();
    if (Fault.FAULT_CODE_CLIENT.equals(fc)) {
        fc = v.getSender();
    } else if (Fault.FAULT_CODE_SERVER.equals(fc)) {
        fc = v.getReceiver();
    }
    SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle) null), f.getCause(), fc);
    if (v == Soap12.getInstance()) {
        updateSoap12FaultCodes(soapFault);
    }
    soapFault.setDetail(f.getDetail());
    return soapFault;
}
Also used : Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) ResourceBundle(java.util.ResourceBundle)

Example 23 with Message

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

the class MustUnderstandInterceptor method handleMessage.

public void handleMessage(SoapMessage soapMessage) {
    Set<QName> paramHeaders = HeaderUtil.getHeaderQNameInOperationParam(soapMessage);
    if (soapMessage.getHeaders().isEmpty() && paramHeaders.isEmpty()) {
        return;
    }
    SoapVersion soapVersion = soapMessage.getVersion();
    Set<Header> mustUnderstandHeaders = new HashSet<>();
    Set<URI> serviceRoles = new HashSet<>();
    Set<QName> notUnderstandHeaders = new HashSet<>();
    Set<Header> ultimateReceiverHeaders = new HashSet<>();
    Set<QName> mustUnderstandQNames = new HashSet<>();
    initServiceSideInfo(mustUnderstandQNames, soapMessage, serviceRoles, paramHeaders);
    buildMustUnderstandHeaders(mustUnderstandHeaders, soapMessage, serviceRoles, ultimateReceiverHeaders);
    checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames, notUnderstandHeaders);
    if (!notUnderstandHeaders.isEmpty()) {
        if (!isRequestor(soapMessage)) {
            soapMessage.put(MustUnderstandInterceptor.UNKNOWNS, notUnderstandHeaders);
            soapMessage.getInterceptorChain().add(ending);
        } else {
            throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders), soapVersion.getMustUnderstand());
        }
    }
    if (!ultimateReceiverHeaders.isEmpty() && !isRequestor(soapMessage)) {
        checkUltimateReceiverHeaders(ultimateReceiverHeaders, mustUnderstandQNames, soapMessage);
    }
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) SoapFault(org.apache.cxf.binding.soap.SoapFault) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Header(org.apache.cxf.headers.Header) Message(org.apache.cxf.common.i18n.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) QName(javax.xml.namespace.QName) URI(java.net.URI) HashSet(java.util.HashSet)

Example 24 with Message

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

the class JaxWsServiceFactoryBean method initializeWSDLOperationsForProvider.

protected void initializeWSDLOperationsForProvider() {
    Class<?> c = getProviderParameterType(getServiceClass());
    if (c == null) {
        throw new ServiceConstructionException(new Message("INVALID_PROVIDER_EXC", LOG));
    }
    if (getEndpointInfo() == null && isFromWsdl()) {
        // most likely, they specified a WSDL, but for some reason
        // did not give a valid ServiceName/PortName.  For provider,
        // we'll allow this since everything is bound directly to
        // the invoke method, however, this CAN cause other problems
        // such as addresses in the wsdl not getting updated and such
        // so we'll WARN about it.....
        List<QName> enames = new ArrayList<>();
        for (ServiceInfo si : getService().getServiceInfos()) {
            for (EndpointInfo ep : si.getEndpoints()) {
                enames.add(ep.getName());
            }
        }
        LOG.log(Level.WARNING, "COULD_NOT_FIND_ENDPOINT", new Object[] { getEndpointName(), enames });
    }
    try {
        Method invoke = getServiceClass().getMethod("invoke", c);
        QName catchAll = new QName("http://cxf.apache.org/jaxws/provider", "invoke");
        // Bind every operation to the invoke method.
        for (ServiceInfo si : getService().getServiceInfos()) {
            si.setProperty("soap.force.doclit.bare", Boolean.TRUE);
            if (!isFromWsdl()) {
                for (EndpointInfo ei : si.getEndpoints()) {
                    ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
                }
            }
            for (BindingInfo bind : si.getBindings()) {
                for (BindingOperationInfo bop : bind.getOperations()) {
                    OperationInfo o = bop.getOperationInfo();
                    if (bop.isUnwrappedCapable()) {
                        // force to bare, no unwrapping
                        bop.getOperationInfo().setUnwrappedOperation(null);
                        bop.setUnwrappedOperation(null);
                    }
                    if (o.getInput() != null) {
                        final List<MessagePartInfo> messageParts;
                        if (o.getInput().getMessagePartsNumber() == 0) {
                            MessagePartInfo inf = o.getInput().addMessagePart(o.getName());
                            inf.setConcreteName(o.getName());
                            messageParts = o.getInput().getMessageParts();
                            bop.getInput().setMessageParts(messageParts);
                        } else {
                            messageParts = o.getInput().getMessageParts();
                        }
                        for (MessagePartInfo inf : messageParts) {
                            inf.setTypeClass(c);
                            break;
                        }
                    }
                    if (o.getOutput() != null) {
                        final List<MessagePartInfo> messageParts;
                        if (o.getOutput().getMessagePartsNumber() == 0) {
                            MessagePartInfo inf = o.getOutput().addMessagePart(o.getName());
                            inf.setConcreteName(new QName(o.getName().getNamespaceURI(), o.getName().getLocalPart() + "Response"));
                            messageParts = o.getOutput().getMessageParts();
                            bop.getOutput().setMessageParts(messageParts);
                        } else {
                            messageParts = o.getOutput().getMessageParts();
                        }
                        for (MessagePartInfo inf : messageParts) {
                            inf.setTypeClass(c);
                            break;
                        }
                    }
                    getMethodDispatcher().bind(o, invoke);
                }
                BindingOperationInfo bop = bind.getOperation(catchAll);
                if (bop == null) {
                    OperationInfo op = bind.getInterface().getOperation(catchAll);
                    if (op == null) {
                        op = bind.getInterface().addOperation(catchAll);
                        String name = catchAll.getLocalPart();
                        MessageInfo mInfo = op.createMessage(new QName(catchAll.getNamespaceURI(), name + "Request"), MessageInfo.Type.INPUT);
                        op.setInput(catchAll.getLocalPart() + "Request", mInfo);
                        MessagePartInfo mpi = mInfo.addMessagePart("parameters");
                        mpi.setElement(true);
                        mpi.setTypeClass(c);
                        mpi.setTypeQName(Constants.XSD_ANYTYPE);
                        mInfo = op.createMessage(new QName(catchAll.getNamespaceURI(), name + "Response"), MessageInfo.Type.OUTPUT);
                        op.setOutput(name + "Response", mInfo);
                        mpi = mInfo.addMessagePart("parameters");
                        mpi.setElement(true);
                        mpi.setTypeClass(c);
                        mpi.setTypeQName(Constants.XSD_ANYTYPE);
                        BindingOperationInfo bo = new BindingOperationInfo(bind, op);
                        op.setProperty("operation.is.synthetic", Boolean.TRUE);
                        bo.setProperty("operation.is.synthetic", Boolean.TRUE);
                        bind.addOperation(bo);
                    }
                }
            }
        }
    } catch (SecurityException | NoSuchMethodException e) {
        throw new ServiceConstructionException(e);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo)

Example 25 with Message

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

the class ProviderImpl method createEndpoint.

// new in 2.2
public Endpoint createEndpoint(String bindingId, Class<?> implementorClass, Invoker invoker, WebServiceFeature... features) {
    if (EndpointUtils.isValidImplementor(implementorClass)) {
        Bus bus = BusFactory.getThreadDefaultBus();
        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
        if (features != null) {
            factory.getJaxWsServiceFactory().setWsFeatures(Arrays.asList(features));
        }
        if (invoker != null) {
            factory.setInvoker(new JAXWSMethodInvoker(invoker));
            try {
                invoker.inject(new WebServiceContextImpl());
            } catch (Exception e) {
                throw new WebServiceException(new Message("ENDPOINT_CREATION_FAILED_MSG", LOG).toString(), e);
            }
        }
        EndpointImpl ep = new EndpointImpl(bus, null, factory);
        ep.setImplementorClass(implementorClass);
        return ep;
    }
    throw new WebServiceException(new Message("INVALID_IMPLEMENTOR_EXC", LOG).toString());
}
Also used : Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.common.i18n.Message) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) JAXWSMethodInvoker(org.apache.cxf.jaxws.JAXWSMethodInvoker) WebServiceContextImpl(org.apache.cxf.jaxws.context.WebServiceContextImpl) XMLStreamException(javax.xml.stream.XMLStreamException) PrivilegedActionException(java.security.PrivilegedActionException) JAXBException(javax.xml.bind.JAXBException) WebServiceException(javax.xml.ws.WebServiceException)

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