Search in sources :

Example 1 with Message

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

the class EndpointReferenceUtils method setMetadata.

/**
 * Sets the metadata on the provided endpoint reference.
 * @param ref the endpoint reference.
 * @param metadata the list of metadata source.
 */
public static void setMetadata(EndpointReferenceType ref, List<Source> metadata) throws EndpointUtilsException {
    if (null != ref) {
        MetadataType mt = getSetMetadata(ref);
        List<Object> anyList = mt.getAny();
        try {
            for (Source source : metadata) {
                Node node = null;
                boolean doTransform = true;
                if (source instanceof StreamSource) {
                    StreamSource ss = (StreamSource) source;
                    if (null == ss.getInputStream() && null == ss.getReader()) {
                        setWSDLLocation(ref, ss.getSystemId());
                        doTransform = false;
                    }
                } else if (source instanceof DOMSource) {
                    node = ((DOMSource) source).getNode();
                    doTransform = false;
                }
                if (doTransform) {
                    DOMResult domResult = new DOMResult();
                    domResult.setSystemId(source.getSystemId());
                    node = StaxUtils.read(source);
                    node = domResult.getNode();
                }
                if (null != node) {
                    if (node instanceof Document) {
                        try {
                            ((Document) node).setDocumentURI(source.getSystemId());
                        } catch (Exception ex) {
                        // ignore - not DOM level 3
                        }
                        node = node.getFirstChild();
                    }
                    while (node.getNodeType() != Node.ELEMENT_NODE) {
                        node = node.getNextSibling();
                    }
                    anyList.add(node);
                }
            }
        } catch (XMLStreamException te) {
            throw new EndpointUtilsException(new Message("COULD_NOT_POPULATE_EPR", LOG), te);
        }
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMResult(javax.xml.transform.dom.DOMResult) Message(org.apache.cxf.common.i18n.Message) Node(org.w3c.dom.Node) StreamSource(javax.xml.transform.stream.StreamSource) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) MalformedURLException(java.net.MalformedURLException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 2 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, Object implementor, WebServiceFeature... features) {
    EndpointImpl ep = null;
    if (EndpointUtils.isValidImplementor(implementor)) {
        Bus bus = BusFactory.getThreadDefaultBus();
        ep = createEndpointImpl(bus, bindingId, implementor, features);
        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)

Example 3 with Message

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

the class JMSConfigFeature method initialize.

@Override
public void initialize(Client client, Bus bus) {
    checkJmsConfig();
    Conduit conduit = client.getConduit();
    if (!(conduit instanceof JMSConduit)) {
        throw new ConfigurationException(new Message("JMSCONFIGFEATURE_ONLY_JMS", LOG));
    }
    JMSConduit jmsConduit = (JMSConduit) conduit;
    jmsConduit.setJmsConfig(jmsConfig);
    super.initialize(client, bus);
}
Also used : Message(org.apache.cxf.common.i18n.Message) ConfigurationException(org.apache.cxf.configuration.ConfigurationException) Conduit(org.apache.cxf.transport.Conduit)

Example 4 with Message

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

the class JAXBSchemaInitializer method createBridgeXsElement.

private void createBridgeXsElement(MessagePartInfo part, QName qn, QName typeName) {
    SchemaInfo schemaInfo = serviceInfo.getSchema(qn.getNamespaceURI());
    if (schemaInfo != null) {
        XmlSchemaElement el = schemaInfo.getElementByQName(qn);
        if (el == null) {
            createXsElement(schemaInfo.getSchema(), part, typeName, schemaInfo);
        } else if (!typeName.equals(el.getSchemaTypeName())) {
            throw new Fault(new Message("CANNOT_CREATE_ELEMENT", LOG, qn, typeName, el.getSchemaTypeName()));
        }
        return;
    }
    XmlSchema schema = schemas.newXmlSchemaInCollection(qn.getNamespaceURI());
    if (qualifiedSchemas) {
        schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    }
    schemaInfo = new SchemaInfo(qn.getNamespaceURI(), qualifiedSchemas, false);
    schemaInfo.setSchema(schema);
    createXsElement(schema, part, typeName, schemaInfo);
    NamespaceMap nsMap = new NamespaceMap();
    nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, schema.getTargetNamespace());
    nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
    schema.setNamespaceContext(nsMap);
    serviceInfo.addSchema(schemaInfo);
}
Also used : Message(org.apache.cxf.common.i18n.Message) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) Fault(org.apache.cxf.interceptor.Fault) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 5 with Message

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

the class JAXBEncoderDecoder method doUnmarshal.

private static Object doUnmarshal(final Unmarshaller u, final Object source, final QName elName, final Class<?> clazz, final boolean unwrap) throws Exception {
    final Object obj;
    boolean unmarshalWithClass = true;
    if (clazz == null || (!clazz.isPrimitive() && !clazz.isArray() && !clazz.isEnum() && !clazz.equals(Calendar.class) && (Modifier.isAbstract(clazz.getModifiers()) || Modifier.isInterface(clazz.getModifiers())))) {
        unmarshalWithClass = false;
    }
    if (clazz != null && ("javax.xml.datatype.XMLGregorianCalendar".equals(clazz.getName()) || "javax.xml.datatype.Duration".equals(clazz.getName()))) {
        // special treat two jaxb defined built-in abstract types
        unmarshalWithClass = true;
    }
    if (source instanceof Node) {
        obj = unmarshalWithClass ? u.unmarshal((Node) source, clazz) : u.unmarshal((Node) source);
    } else if (source instanceof DepthXMLStreamReader) {
        // JAXB optimizes a ton of stuff depending on the StreamReader impl. Thus,
        // we REALLY want to pass the original reader in.   This is OK with JAXB
        // as it doesn't read beyond the end so the DepthXMLStreamReader state
        // would be OK when it returns.   The main winner is FastInfoset where parsing
        // a testcase I have goes from about 300/sec to well over 1000.
        DepthXMLStreamReader dr = (DepthXMLStreamReader) source;
        XMLStreamReader reader = dr.getReader();
        // allows the XML Stream Reader to adjust it's behaviour based on the state of the unmarshaller
        if (reader instanceof UnmarshallerAwareXMLReader) {
            ((UnmarshallerAwareXMLReader) reader).setUnmarshaller(u);
        }
        if (u.getSchema() != null) {
            // validating, but we may need more namespaces
            reader = findExtraNamespaces(reader);
        }
        obj = unmarshalWithClass ? u.unmarshal(reader, clazz) : u.unmarshal(dr.getReader());
    } else if (source instanceof XMLStreamReader) {
        XMLStreamReader reader = (XMLStreamReader) source;
        // allows the XML Stream Reader to adjust it's behaviour based on the state of the unmarshaller
        if (reader instanceof UnmarshallerAwareXMLReader) {
            ((UnmarshallerAwareXMLReader) reader).setUnmarshaller(u);
        }
        if (u.getSchema() != null) {
            // validating, but we may need more namespaces
            reader = findExtraNamespaces(reader);
        }
        obj = unmarshalWithClass ? u.unmarshal(reader, clazz) : u.unmarshal(reader);
    } else if (source instanceof XMLEventReader) {
        // allows the XML Event Reader to adjust it's behaviour based on the state of the unmarshaller
        if (source instanceof UnmarshallerAwareXMLReader) {
            ((UnmarshallerAwareXMLReader) source).setUnmarshaller(u);
        }
        obj = unmarshalWithClass ? u.unmarshal((XMLEventReader) source, clazz) : u.unmarshal((XMLEventReader) source);
    } else if (source == null) {
        throw new Fault(new Message("UNKNOWN_SOURCE", LOG, "null"));
    } else {
        throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
    }
    return unwrap ? getElementValue(obj) : obj;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) Message(org.apache.cxf.common.i18n.Message) Calendar(java.util.Calendar) Node(org.w3c.dom.Node) XMLEventReader(javax.xml.stream.XMLEventReader) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader)

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