Search in sources :

Example 76 with Message

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

the class PolicyBasedWSS4JInInterceptor method handleMessage.

public void handleMessage(SoapMessage msg) throws Fault {
    AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
    boolean enableStax = MessageUtils.getContextualBoolean(msg, SecurityConstants.ENABLE_STREAMING_SECURITY);
    if (aim != null && !enableStax && !msg.containsKey(SECURITY_PROCESSED) && !isGET(msg) && msg.getExchange() != null) {
        try {
            // First check to see if we have a security header before we apply the SAAJInInterceptor
            // If there is no security header then we can just assert the policies and proceed
            String actor = (String) getOption(ConfigurationConstants.ACTOR);
            if (actor == null) {
                actor = (String) msg.getContextualProperty(SecurityConstants.ACTOR);
            }
            if (!containsSecurityHeader(msg, actor, msg.getVersion().getVersion() != 1.1)) {
                LOG.fine("The request contains no security header, so the SAAJInInterceptor is not applied");
                computeAction(msg, new RequestData());
                boolean utWithCallbacks = MessageUtils.getContextualBoolean(msg, SecurityConstants.VALIDATE_TOKEN, true);
                doResults(msg, actor, null, null, new WSHandlerResult(actor, Collections.emptyList(), Collections.emptyMap()), utWithCallbacks);
                msg.put(SECURITY_PROCESSED, Boolean.TRUE);
                return;
            }
        } catch (WSSecurityException e) {
            throw WSS4JUtils.createSoapFault(msg, msg.getVersion(), e);
        } catch (XMLStreamException e) {
            throw new SoapFault(new Message("STAX_EX", LOG), e, msg.getVersion().getSender());
        } catch (SOAPException e) {
            throw new SoapFault(new Message("SAAJ_EX", LOG), e, msg.getVersion().getSender());
        }
        super.handleMessage(msg);
    }
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) XMLStreamException(javax.xml.stream.XMLStreamException) Message(org.apache.cxf.common.i18n.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) RequestData(org.apache.wss4j.dom.handler.RequestData) SOAPException(javax.xml.soap.SOAPException) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 77 with Message

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

the class ClientGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        if (javaModel.getServiceClasses().isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_CLIENT", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            return;
        }
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
            for (JavaPort jp : js.getPorts()) {
                String interfaceName = jp.getInterfaceClass();
                JavaInterface intf = interfaces.get(interfaceName);
                if (intf == null) {
                    interfaceName = jp.getPortType();
                    intf = interfaces.get(interfaceName);
                }
                String clientClassName = interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Client";
                clientClassName = mapClassName(intf.getPackageName(), clientClassName, penv);
                clearAttributes();
                setAttributes("clientClassName", clientClassName);
                setAttributes("intf", intf);
                setAttributes("service", js);
                setAttributes("port", jp);
                setCommonAttributes();
                doWrite(CLT_TEMPLATE, parseOutputName(intf.getPackageName(), clientClassName));
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaPort(org.apache.cxf.tools.common.model.JavaPort)

Example 78 with Message

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

the class SEIGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        if (interfaces.isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_SEI", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            continue;
        }
        for (JavaInterface intf : interfaces.values()) {
            if (hasHandlerConfig(intf)) {
                HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
                // REVISIT: find a better way to handle Handler gen, should not
                // pass JavaInterface around.
                handlerGen.setJavaInterface(intf);
                handlerGen.generate(getEnvironment());
                JAnnotation annot = handlerGen.getHandlerAnnotation();
                if (handlerGen.getHandlerAnnotation() != null) {
                    boolean existHandlerAnno = false;
                    for (JAnnotation jann : intf.getAnnotations()) {
                        if (jann.getType() == HandlerChain.class) {
                            existHandlerAnno = true;
                        }
                    }
                    if (!existHandlerAnno) {
                        intf.addAnnotation(annot);
                        intf.addImport("javax.jws.HandlerChain");
                    }
                }
            }
            if (penv.containsKey(ToolConstants.RUNTIME_DATABINDING_CLASS)) {
                JAnnotation ann = new JAnnotation(DataBinding.class);
                JAnnotationElement el = new JAnnotationElement(null, penv.get(ToolConstants.RUNTIME_DATABINDING_CLASS), true);
                ann.addElement(el);
                intf.addAnnotation(ann);
            }
            clearAttributes();
            setAttributes("intf", intf);
            String seiSc = "";
            for (String s : intf.getSuperInterfaces()) {
                if (!seiSc.isEmpty()) {
                    seiSc += ", ";
                } else {
                    seiSc = "extends ";
                }
                seiSc += s;
            }
            if (!StringUtils.isEmpty(seiSc)) {
                seiSc += " ";
            }
            setAttributes("seiSuperinterfaceString", seiSc);
            setCommonAttributes();
            doWrite(SEI_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName()));
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement)

Example 79 with Message

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

the class ServiceGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        ClassCollector collector = penv.get(ClassCollector.class);
        Map<String, JavaServiceClass> serviceClasses = javaModel.getServiceClasses();
        if (serviceClasses.isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_SERVICE", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            return;
        }
        for (JavaServiceClass js : serviceClasses.values()) {
            if (js.getHandlerChains() != null) {
                HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
                handlerGen.setJavaInterface(js);
                handlerGen.generate(getEnvironment());
                JAnnotation annot = handlerGen.getHandlerAnnotation();
                if (handlerGen.getHandlerAnnotation() != null) {
                    boolean existHandlerAnno = false;
                    for (JAnnotation jann : js.getAnnotations()) {
                        if (jann.getType() == HandlerChain.class) {
                            existHandlerAnno = true;
                        }
                    }
                    if (!existHandlerAnno) {
                        js.addAnnotation(annot);
                        js.addImport("javax.jws.HandlerChain");
                    }
                }
            }
            Set<String> portNames = new HashSet<>();
            for (JavaPort port : js.getPorts()) {
                if (!port.getPackageName().equals(js.getPackageName()) && !port.getInterfaceClass().equals(js.getName())) {
                    js.addImport(port.getFullClassName());
                }
                portNames.add(port.getInterfaceClass());
            }
            if ("cxf".equals(env.get(ToolConstants.CFG_FRONTEND))) {
                js.addImport(BindingProvider.class.getName());
                js.addImport(Client.class.getName());
            }
            String url = (String) env.get(ToolConstants.CFG_WSDLURL);
            String location = (String) env.get(ToolConstants.CFG_WSDLLOCATION);
            if (location == null) {
                location = url;
            }
            String serviceSuperclass = (String) env.get("service.superclass");
            String simpleServiceName = serviceSuperclass.substring(serviceSuperclass.lastIndexOf('.') + 1);
            for (String s : collector.getGeneratedFileInfo()) {
                if (s.equals(js.getPackageName() + "." + simpleServiceName)) {
                    simpleServiceName = serviceSuperclass;
                    break;
                }
            }
            clearAttributes();
            boolean useGetResource = false;
            try {
                new URL(location);
            } catch (MalformedURLException e) {
                useGetResource = true;
            }
            setAttributes("cxfPortClassnames", portNames.toArray(new String[0]));
            setAttributes("service", js);
            setAttributes("wsdlLocation", location);
            setAttributes("useGetResource", useGetResource);
            setAttributes("serviceSuperclass", simpleServiceName);
            if (!simpleServiceName.equals(serviceSuperclass)) {
                js.addImport(serviceSuperclass);
            }
            setAttributes("wsdlUrl", url);
            setCommonAttributes();
            String target = (String) env.get("service.target");
            setAttributes("serviceTarget", target);
            if ("jaxws22".equals(target)) {
                setAttributes("jaxws22", true);
            }
            doWrite(SERVICE_TEMPLATE, parseOutputName(js.getPackageName(), js.getName()));
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Message(org.apache.cxf.common.i18n.Message) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) ClassCollector(org.apache.cxf.tools.util.ClassCollector) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) JavaPort(org.apache.cxf.tools.common.model.JavaPort) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaModel(org.apache.cxf.tools.common.model.JavaModel) Client(org.apache.cxf.endpoint.Client) HashSet(java.util.HashSet)

Example 80 with Message

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

the class WSDLToSoapProcessor method validate.

private void validate() throws ToolException {
    if (isBindingExisted()) {
        Message msg = new Message("BINDING_ALREADY_EXIST", LOG);
        throw new ToolException(msg);
    }
    if (!isPortTypeExisted()) {
        Message msg = new Message("PORTTYPE_NOT_EXIST", LOG);
        throw new ToolException(msg);
    }
    if (!nameSpaceCheck()) {
        Message msg = new Message("SOAPBINDING_STYLE_NOT_PROVIDED", LOG);
        throw new ToolException(msg);
    }
    if (WSDLConstants.RPC.equalsIgnoreCase((String) env.get(ToolConstants.CFG_STYLE))) {
        Collection<Operation> ops = CastUtils.cast(portType.getOperations());
        for (Operation op : ops) {
            Input input = op.getInput();
            if (input != null && input.getMessage() != null) {
                Collection<Part> parts = CastUtils.cast(input.getMessage().getParts().values());
                for (Part part : parts) {
                    if (part.getTypeName() == null || "".equals(part.getTypeName().toString())) {
                        Message msg = new Message("RPC_PART_ILLEGAL", LOG, new Object[] { part.getName() });
                        throw new ToolException(msg);
                    }
                }
            }
            Output output = op.getOutput();
            if (output != null && output.getMessage() != null) {
                Collection<Part> parts = CastUtils.cast(output.getMessage().getParts().values());
                for (Part part : parts) {
                    if (part.getTypeName() == null || "".equals(part.getTypeName().toString())) {
                        Message msg = new Message("RPC_PART_ILLEGAL", LOG, new Object[] { part.getName() });
                        throw new ToolException(msg);
                    }
                }
            }
        }
    }
}
Also used : BindingInput(javax.wsdl.BindingInput) Input(javax.wsdl.Input) Message(org.apache.cxf.common.i18n.Message) Part(javax.wsdl.Part) BindingOutput(javax.wsdl.BindingOutput) Output(javax.wsdl.Output) ToolException(org.apache.cxf.tools.common.ToolException) Operation(javax.wsdl.Operation) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) BindingOperation(javax.wsdl.BindingOperation)

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