org.apache.axis.encoding.TypeMapping Java Examples

The following examples show how to use org.apache.axis.encoding.TypeMapping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AxisDeserializer.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/** Adds the type mappings in the list to {@code registryTypeMapping}. */
private void registerTypeMappings(
    TypeMapping registryTypeMapping, List<TypeMapping> typeMappings) {
  Preconditions.checkNotNull(registryTypeMapping, "Null registry type mapping");
  Preconditions.checkNotNull(typeMappings, "Null type mappings");
  Preconditions.checkArgument(!typeMappings.isEmpty(), "Empty type mappings");
  for (TypeMapping typeMapping : typeMappings) {
    for (Class<?> mappingClass : typeMapping.getAllClasses()) {
      QName classQName = typeMapping.getTypeQName(mappingClass);
      DeserializerFactory deserializer = typeMapping.getDeserializer(mappingClass, classQName);
      if (deserializer != null && !registryTypeMapping.isRegistered(mappingClass, classQName)) {
        registryTypeMapping.register(
            mappingClass, classQName, (SerializerFactory) null, deserializer);
      }
    }
  }
}
 
Example #2
Source File: ContextRegistrar.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Registers the specified Class with the current MessageContext's TypeMapping
 * for use by Axis. This method will remove any existing entries for the same
 * class type (QName equivalence) before adding new Bean
 * serializer/deserializer entries.
 * 
 * @param kls
 */
public void registerClass(Class<?> kls) {
	// Add ser/deser pairs for these classes
	TypeMapping tm = msgContext.getTypeMapping();
	QName xmlType = convertToQName(kls, this.scheme);
	if (!tm.isRegistered(kls, xmlType)) {
		SerializerFactory sf = new BeanSerializerFactory(kls, xmlType);
		DeserializerFactory dsf = new BeanDeserializerFactory(kls, xmlType);
		tm.register(kls, xmlType, sf, dsf);
	}
}
 
Example #3
Source File: ContextRegistrar.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Unregisters the specified Class from the current MessageContext's
 * TypeMapping for use by Axis. This method will remove all existing entries
 * for the class type (QName equivalence).
 * 
 * @param kls
 */
public void unregisterClass(Class<?> kls) {
	TypeMapping tm = msgContext.getTypeMapping();
	QName xmlType = convertToQName(kls, this.scheme);
	if (tm.isRegistered(kls, xmlType)) {
		tm.removeDeserializer(kls, xmlType);
		tm.removeSerializer(kls, xmlType);
	}
}
 
Example #4
Source File: SeiFactoryImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: BatchJobMutateRequest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
@Override
public BatchJobUploadBodyProvider createBatchJobUploadBodyProvider() {
  Set<String> namespaceUris = Sets.newHashSet();
  for (TypeMapping typeMapping : BatchJobHelperImpl.getServiceTypeMappings()) {
    for (Class<?> clazz : typeMapping.getAllClasses()) {
      QName qName = typeMapping.getTypeQName(clazz);
      if (qName != null) {
        namespaceUris.add(qName.getNamespaceURI());
      }
    }
  }
  return new AxisBatchJobUploadBodyProvider(namespaceUris);
}
 
Example #6
Source File: AxisDeserializer.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
public <ResultT> List<ResultT> deserializeBatchJobMutateResults(
    URL url, List<TypeMapping> serviceTypeMappings, Class<ResultT> resultClass, QName resultQName)
    throws Exception {

  return deserializeBatchJobMutateResults(
      url, serviceTypeMappings, resultClass, resultQName, 0, Integer.MAX_VALUE);
}
 
Example #7
Source File: ReadOnlyServiceDesc.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @return TypeMapping
 */
@Override
public TypeMapping getTypeMapping() {
    return serviceDesc.getTypeMapping();
}
 
Example #8
Source File: JavaServiceDescBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #9
Source File: JavaServiceDescBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
private void registerType(JaxRpcTypeInfo type, TypeMapping typeMapping) throws OpenEJBException {
    Class javaType;
    try {
        javaType = classLoader.loadClass(type.javaType);
    } catch (ClassNotFoundException e) {
        throw new OpenEJBException("Could not load class for JaxRpc mapping " + type.javaType);
    }

    // Default uses the generic Java Beans serializer/deserializer
    Class serializerFactoryClass = BeanSerializerFactory.class;
    Class deserializerFactoryClass = BeanDeserializerFactory.class;
    switch (type.serializerType) {
        case ARRAY:
            serializerFactoryClass = ArraySerializerFactory.class;
            deserializerFactoryClass = ArrayDeserializerFactory.class;
            break;
        case ENUM:
            serializerFactoryClass = EnumSerializerFactory.class;
            deserializerFactoryClass = EnumDeserializerFactory.class;
            break;
        case LIST:
            serializerFactoryClass = SimpleListSerializerFactory.class;
            deserializerFactoryClass = SimpleListDeserializerFactory.class;
            break;
        default:
            if (type.simpleBaseType != null) {
                Class clazz = SOAP_TYPE_MAPPING.getClassForQName(type.simpleBaseType, null, null);
                if (null != clazz) {
                    // Built in SOAP type
                    serializerFactoryClass = SOAP_TYPE_MAPPING.getSerializer(clazz, type.simpleBaseType).getClass();
                    deserializerFactoryClass = SOAP_TYPE_MAPPING.getDeserializer(clazz, type.simpleBaseType, null).getClass();
                } else {
                    clazz = JAXRPC_TYPE_MAPPING.getClassForQName(type.simpleBaseType, null, null);
                    if (null != clazz) {
                        // Built in XML schema type
                        serializerFactoryClass = JAXRPC_TYPE_MAPPING.getSerializer(clazz, type.simpleBaseType).getClass();
                        deserializerFactoryClass = JAXRPC_TYPE_MAPPING.getDeserializer(clazz, type.simpleBaseType, null).getClass();
                    }
                }
            }
            break;
    }

    SerializerFactory serializerFactory = BaseSerializerFactory.createFactory(serializerFactoryClass, javaType, type.qname);
    DeserializerFactory deserializerFactory = BaseDeserializerFactory.createFactory(deserializerFactoryClass, javaType, type.qname);

    typeMapping.register(javaType, type.qname, serializerFactory, deserializerFactory);
}
 
Example #10
Source File: AxisWsContainerTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
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
                }
            }
        }
    }
 
Example #11
Source File: AxisDeserializer.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public <ResultT> List<ResultT> deserializeBatchJobMutateResults(
    URL url,
    List<TypeMapping> serviceTypeMappings,
    Class<ResultT> resultClass,
    QName resultQName,
    int startIndex,
    int numberResults)
    throws Exception {

  List<ResultT> results = Lists.newArrayList();

  // Build a wrapped input stream from the response.
  InputStream wrappedStream =
      ByteSource.concat(
              ByteSource.wrap(SOAP_START_BODY.getBytes(UTF_8)),
              batchJobHelperUtility.buildWrappedByteSource(url, startIndex, numberResults),
              ByteSource.wrap(SOAP_END_BODY.getBytes(UTF_8)))
          .openStream();

  // Create a MessageContext with a new TypeMappingRegistry that will only
  // contain deserializers derived from serviceTypeMappings and the
  // result class/QName pair.
  MessageContext messageContext = new MessageContext(new AxisClient());
  TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl(true);
  messageContext.setTypeMappingRegistry(typeMappingRegistry);

  // Construct an Axis deserialization context.
  DeserializationContext deserializationContext =
      new DeserializationContext(
          new InputSource(wrappedStream), messageContext, Message.RESPONSE);

  // Register all type mappings with the new type mapping registry.
  TypeMapping registryTypeMapping =
      typeMappingRegistry.getOrMakeTypeMapping(messageContext.getEncodingStyle());
  registerTypeMappings(registryTypeMapping, serviceTypeMappings);

  // Parse the wrapped input stream.
  deserializationContext.parse();

  // Read the deserialized mutate results from the parsed stream.
  SOAPEnvelope envelope = deserializationContext.getEnvelope();
  MessageElement body = envelope.getFirstBody();

  for (Iterator<?> iter = body.getChildElements(); iter.hasNext(); ) {
    Object child = iter.next();
    MessageElement childElm = (MessageElement) child;
    @SuppressWarnings("unchecked")
    ResultT mutateResult = (ResultT) childElm.getValueAsType(resultQName, resultClass);
    results.add(mutateResult);
  }
  return results;
}
 
Example #12
Source File: ReadOnlyServiceDesc.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param cls cls
 * @param tm tm
 */
@Override
public void loadServiceDescByIntrospection(Class cls, TypeMapping tm) {
    serviceDesc.loadServiceDescByIntrospection(cls, tm);
}
 
Example #13
Source File: ReadOnlyServiceDesc.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param tm Set TypeMapping
 */
@Override
public void setTypeMapping(TypeMapping tm) {
}