Search in sources :

Example 1 with TypeMapping

use of org.apache.axis.encoding.TypeMapping in project tomee by apache.

the class SeiFactoryImpl method initialize.

void initialize(Object serviceImpl, ClassLoader classLoader) throws ClassNotFoundException {
    this.serviceImpl = serviceImpl;
    Class serviceEndpointBaseClass = classLoader.loadClass(serviceEndpointClassName);
    serviceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointBaseClass, classLoader);
    Class[] constructorTypes = new Class[] { classLoader.loadClass(GenericServiceEndpoint.class.getName()) };
    this.constructor = FastClass.create(serviceEndpointClass).getConstructor(constructorTypes);
    this.handlerInfoChainFactory = new HandlerInfoChainFactory(handlerInfos);
    sortedOperationInfos = new OperationInfo[FastClass.create(serviceEndpointClass).getMaxIndex() + 1];
    String encodingStyle = "";
    for (int i = 0; i < operationInfos.length; i++) {
        OperationInfo operationInfo = operationInfos[i];
        Signature signature = operationInfo.getSignature();
        MethodProxy methodProxy = MethodProxy.find(serviceEndpointClass, signature);
        if (methodProxy == null) {
            throw new ServerRuntimeException("No method proxy for operationInfo " + signature);
        }
        int index = methodProxy.getSuperIndex();
        sortedOperationInfos[index] = operationInfo;
        if (operationInfo.getOperationDesc().getUse() == Use.ENCODED) {
            encodingStyle = org.apache.axis.Constants.URI_SOAP11_ENC;
        }
    }
    // register our type descriptors
    Service service = ((ServiceImpl) serviceImpl).getService();
    AxisEngine axisEngine = service.getEngine();
    TypeMappingRegistry typeMappingRegistry = axisEngine.getTypeMappingRegistry();
    TypeMapping typeMapping = typeMappingRegistry.getOrMakeTypeMapping(encodingStyle);
    typeMapping.register(BigInteger.class, Constants.XSD_UNSIGNEDLONG, new SimpleSerializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG), new SimpleDeserializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG));
    typeMapping.register(URI.class, Constants.XSD_ANYURI, new SimpleSerializerFactory(URI.class, Constants.XSD_ANYURI), new SimpleDeserializerFactory(URI.class, Constants.XSD_ANYURI));
    // It is essential that the types be registered before the typeInfos create the serializer/deserializers.
    for (Iterator iter = typeInfo.iterator(); iter.hasNext(); ) {
        TypeInfo info = (TypeInfo) iter.next();
        TypeDesc.registerTypeDescForClass(info.getClazz(), info.buildTypeDesc());
    }
    TypeInfo.register(typeInfo, typeMapping);
}
Also used : SimpleSerializerFactory(org.apache.axis.encoding.ser.SimpleSerializerFactory) HandlerInfoChainFactory(org.apache.axis.handlers.HandlerInfoChainFactory) Service(org.apache.axis.client.Service) URI(java.net.URI) SimpleDeserializerFactory(org.apache.axis.encoding.ser.SimpleDeserializerFactory) Signature(net.sf.cglib.core.Signature) MethodProxy(net.sf.cglib.proxy.MethodProxy) Iterator(java.util.Iterator) TypeMappingRegistry(org.apache.axis.encoding.TypeMappingRegistry) TypeMapping(org.apache.axis.encoding.TypeMapping) BigInteger(java.math.BigInteger) FastClass(net.sf.cglib.reflect.FastClass) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) AxisEngine(org.apache.axis.AxisEngine)

Example 2 with TypeMapping

use of org.apache.axis.encoding.TypeMapping in project Lucee by lucee.

the class BeanDeserializer method getDeserializer.

/**
 * Get the Deserializer for the attribute or child element.
 * @param xmlType QName of the attribute/child element or null if not known.
 * @param javaType Class of the corresponding property
 * @param href String is the value of the href attribute, which is used
 *             to determine whether the child element is complete or an
 *             href to another element.
 * @param context DeserializationContext
 * @return Deserializer or null if not found.
 */
protected Deserializer getDeserializer(QName xmlType, Class javaType, String href, DeserializationContext context) {
    if (javaType.isArray()) {
        context.setDestinationClass(javaType);
    }
    // See if we have a cached deserializer
    if (cacheStringDSer != null) {
        if (String.class.equals(javaType) && href == null && (cacheXMLType == null && xmlType == null || cacheXMLType != null && cacheXMLType.equals(xmlType))) {
            cacheStringDSer.reset();
            return cacheStringDSer;
        }
    }
    Deserializer dSer = null;
    if (xmlType != null && href == null) {
        // Use the xmlType to get the deserializer.
        dSer = context.getDeserializerForType(xmlType);
    } else {
        // If the xmlType is not set, get a default xmlType
        TypeMapping tm = context.getTypeMapping();
        QName defaultXMLType = tm.getTypeQName(javaType);
        // not have an xsi:type.
        if (href == null) {
            dSer = context.getDeserializer(javaType, defaultXMLType);
        } else {
            dSer = new DeserializerImpl();
            context.setDestinationClass(javaType);
            dSer.setDefaultType(defaultXMLType);
        }
    }
    if (javaType.equals(String.class) && dSer instanceof SimpleDeserializer) {
        cacheStringDSer = (SimpleDeserializer) dSer;
        cacheXMLType = xmlType;
    }
    return dSer;
}
Also used : Deserializer(org.apache.axis.encoding.Deserializer) QName(javax.xml.namespace.QName) DeserializerImpl(org.apache.axis.encoding.DeserializerImpl) TypeMapping(org.apache.axis.encoding.TypeMapping)

Example 3 with TypeMapping

use of org.apache.axis.encoding.TypeMapping in project tomee by apache.

the class JavaServiceDescBuilder method createServiceDesc.

public JavaServiceDesc createServiceDesc() throws OpenEJBException {
    Class serviceEndpointInterface;
    try {
        serviceEndpointInterface = classLoader.loadClass(serviceInfo.serviceEndpointInterface);
    } catch (ClassNotFoundException e) {
        throw new OpenEJBException("Unable to load the service endpoint interface " + serviceInfo.serviceEndpointInterface, e);
    }
    JavaServiceDesc serviceDesc = new JavaServiceDesc();
    serviceDesc.setName(serviceInfo.name);
    serviceDesc.setEndpointURL(serviceInfo.endpointURL);
    serviceDesc.setWSDLFile(serviceInfo.wsdlFile);
    BindingStyle bindingStyle = serviceInfo.defaultBindingStyle;
    switch(bindingStyle) {
        case RPC_ENCODED:
            serviceDesc.setStyle(Style.RPC);
            serviceDesc.setUse(Use.ENCODED);
            break;
        case RPC_LITERAL:
            serviceDesc.setStyle(Style.RPC);
            serviceDesc.setUse(Use.LITERAL);
            break;
        case DOCUMENT_ENCODED:
            serviceDesc.setStyle(Style.DOCUMENT);
            serviceDesc.setUse(Use.ENCODED);
            break;
        case DOCUMENT_LITERAL:
            serviceDesc.setStyle(Style.DOCUMENT);
            serviceDesc.setUse(Use.LITERAL);
            break;
        case DOCUMENT_LITERAL_WRAPPED:
            serviceDesc.setStyle(Style.WRAPPED);
            serviceDesc.setUse(Use.LITERAL);
            break;
    }
    // Operations
    for (JaxRpcOperationInfo operationInfo : serviceInfo.operations) {
        OperationDesc operationDesc = buildOperationDesc(operationInfo, serviceEndpointInterface);
        serviceDesc.addOperationDesc(operationDesc);
    }
    // Type mapping registry
    TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl();
    typeMappingRegistry.doRegisterFromVersion("1.3");
    serviceDesc.setTypeMappingRegistry(typeMappingRegistry);
    // Type mapping
    TypeMapping typeMapping = typeMappingRegistry.getOrMakeTypeMapping(serviceDesc.getUse().getEncoding());
    serviceDesc.setTypeMapping(typeMapping);
    // Types
    for (JaxRpcTypeInfo type : serviceInfo.types) {
        registerType(type, typeMapping);
    }
    return new ReadOnlyServiceDesc(serviceDesc);
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) BindingStyle(org.apache.openejb.server.axis.assembler.BindingStyle) JavaServiceDesc(org.apache.axis.description.JavaServiceDesc) JaxRpcOperationInfo(org.apache.openejb.server.axis.assembler.JaxRpcOperationInfo) TypeMappingRegistryImpl(org.apache.axis.encoding.TypeMappingRegistryImpl) TypeMapping(org.apache.axis.encoding.TypeMapping) JaxRpcTypeInfo(org.apache.openejb.server.axis.assembler.JaxRpcTypeInfo) OperationDesc(org.apache.axis.description.OperationDesc)

Example 4 with TypeMapping

use of org.apache.axis.encoding.TypeMapping in project tomee by apache.

the class AxisWsContainerTest method testInvokeSOAP.

public void testInvokeSOAP() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    JavaServiceDesc serviceDesc = new JavaServiceDesc();
    serviceDesc.setEndpointURL("http://127.0.0.1:8080/axis/services/echo");
    // serviceDesc.setWSDLFile(portInfo.getWsdlURL().toExternalForm());
    serviceDesc.setStyle(Style.RPC);
    serviceDesc.setUse(Use.ENCODED);
    TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
    tmr.doRegisterFromVersion("1.3");
    TypeMapping typeMapping = tmr.getOrMakeTypeMapping(serviceDesc.getUse().getEncoding());
    serviceDesc.setTypeMappingRegistry(tmr);
    serviceDesc.setTypeMapping(typeMapping);
    OperationDesc op = new OperationDesc();
    op.setName("echoString");
    op.setStyle(Style.RPC);
    op.setUse(Use.ENCODED);
    Class beanClass = EchoBean.class;
    op.setMethod(beanClass.getMethod("echoString", String.class));
    ParameterDesc parameter = new ParameterDesc(new QName("http://ws.apache.org/echosample", "in0"), ParameterDesc.IN, typeMapping.getTypeQName(String.class), String.class, false, false);
    op.addParameter(parameter);
    serviceDesc.addOperationDesc(op);
    serviceDesc.getOperations();
    ReadOnlyServiceDesc sd = new ReadOnlyServiceDesc(serviceDesc);
    Class pojoClass = cl.loadClass("org.apache.openejb.server.axis.EchoBean");
    RPCProvider provider = new PojoProvider();
    SOAPService service = new SOAPService(null, provider, null);
    service.setServiceDescription(sd);
    service.setOption("className", "org.apache.openejb.server.axis.EchoBean");
    URL wsdlURL = new URL("http://fake/echo.wsdl");
    URI location = new URI(serviceDesc.getEndpointURL());
    Map wsdlMap = new HashMap();
    AxisWsContainer container = new AxisWsContainer(wsdlURL, service, wsdlMap, cl);
    InputStream in = cl.getResourceAsStream("echoString-req.txt");
    try {
        AxisRequest req = new AxisRequest(504, "text/xml; charset=utf-8", new ServletIntputStreamAdapter(in), HttpRequest.Method.GET, new HashMap<String, String>(), location, new HashMap<String, String>(), "127.0.0.1");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        AxisResponse res = new AxisResponse("text/xml; charset=utf-8", "127.0.0.1", null, null, 8080, new ServletOutputStreamAdapter(out));
        req.setAttribute(WsConstants.POJO_INSTANCE, pojoClass.newInstance());
        container.onMessage(req, res);
        out.flush();
    // log.debug(new String(out.toByteArray()));
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ignore) {
            // ignore
            }
        }
    }
}
Also used : ParameterDesc(org.apache.axis.description.ParameterDesc) HashMap(java.util.HashMap) TypeMappingRegistryImpl(org.apache.axis.encoding.TypeMappingRegistryImpl) RPCProvider(org.apache.axis.providers.java.RPCProvider) URI(java.net.URI) URL(java.net.URL) ServletIntputStreamAdapter(org.apache.openejb.server.httpd.ServletIntputStreamAdapter) JavaServiceDesc(org.apache.axis.description.JavaServiceDesc) SOAPService(org.apache.axis.handlers.soap.SOAPService) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) OperationDesc(org.apache.axis.description.OperationDesc) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ServletOutputStreamAdapter(org.apache.openejb.server.httpd.ServletOutputStreamAdapter) TypeMapping(org.apache.axis.encoding.TypeMapping) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TypeMapping (org.apache.axis.encoding.TypeMapping)4 URI (java.net.URI)2 QName (javax.xml.namespace.QName)2 JavaServiceDesc (org.apache.axis.description.JavaServiceDesc)2 OperationDesc (org.apache.axis.description.OperationDesc)2 TypeMappingRegistryImpl (org.apache.axis.encoding.TypeMappingRegistryImpl)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Signature (net.sf.cglib.core.Signature)1 MethodProxy (net.sf.cglib.proxy.MethodProxy)1 FastClass (net.sf.cglib.reflect.FastClass)1 AxisEngine (org.apache.axis.AxisEngine)1 Service (org.apache.axis.client.Service)1 ParameterDesc (org.apache.axis.description.ParameterDesc)1