org.apache.axis.encoding.TypeMappingRegistryImpl Java Examples
The following examples show how to use
org.apache.axis.encoding.TypeMappingRegistryImpl.
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: AxisUtil.java From j-road with Apache License 2.0 | 6 votes |
public static String serialize(Object obj) throws IOException { TypeDesc desc = TypeDesc.getTypeDescForClass(obj.getClass()); BeanSerializer serializer = new BeanSerializer(obj.getClass(), desc.getXmlType(), desc); MessageContext mctx = new MessageContext(null); mctx.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION, true); mctx.setProperty(AxisEngine.PROP_SEND_XSI, true); mctx.setTypeMappingRegistry(new TypeMappingRegistryImpl()); StringWriter writer = new StringWriter(); SerializationContext ctx = new SerializationContext(writer, mctx); ctx.setPretty(false); ctx.setSendDecl(true); ctx.setDoMultiRefs(false); serializer.serialize(new QName("keha"), new AttributesImpl(), obj, ctx); return writer.getBuffer().toString(); }
Example #2
Source File: ServiceImpl.java From tomee with Apache License 2.0 | 5 votes |
public ServiceImpl(Map portToImplementationMap, Map seiClassNameToFactoryMap) { this.portToImplementationMap = portToImplementationMap; this.seiClassNameToFactoryMap = seiClassNameToFactoryMap; TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl(); typeMappingRegistry.doRegisterFromVersion("1.3"); SimpleProvider engineConfiguration = new SimpleProvider(typeMappingRegistry); engineConfiguration.deployTransport("http", new SimpleTargetedChain(new HTTPSender())); AxisClientImpl engine = new AxisClientImpl(engineConfiguration, this.portToImplementationMap); delegate = new Service(engineConfiguration, engine); }
Example #3
Source File: JavaServiceDescBuilder.java From tomee with Apache License 2.0 | 4 votes |
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 #4
Source File: AxisWsContainerTest.java From tomee with Apache License 2.0 | 4 votes |
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 #5
Source File: AxisDeserializer.java From googleads-java-lib with Apache License 2.0 | 4 votes |
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; }