LiteralBodyBuilder extends AbstractBodyBuilder { @Override public SOAPElement build(Map inputMap) throws WSDLException, ParserConfigurationException, SOAPException, IOException, SAXException, UnknownOperationException { SOAPElement body = super.build(inputMap); if (getStyle() == Style.DOCUMENT) { fixTypeAttributes(body); } return body; } LiteralBodyBuilder(String style, WSDLParser parser, String operationName, List<TypeDescriptor> inputDescriptors); @Override SOAPElement build(Map inputMap);  }
@Test public void testUnqualifiedNamespaces() throws Exception { BodyBuilder builder = createBuilder(wsdlResourcePath("whatizit.wsdl"), "queryPmid"); assertTrue("Is is the wrong type, it should be LiteralBodyBuilder",builder instanceof LiteralBodyBuilder); String parameters = "<parameters xmlns=\"http: Map<String,Object> inputMap = new HashMap<String, Object>(); inputMap.put("parameters", parameters); SOAPElement body = builder.build(inputMap); assertTrue("Wrong wrapping element name", "queryPmid".equals(body.getLocalName()) && "http: Iterator<Node> pipelineNames = body.getChildElements(new QName("","pipelineName")); assertTrue("No pipelineName defined", pipelineNames.hasNext()); assertTrue("Wrong pipelineName value (must be 'swissProt')", "swissProt".equals(pipelineNames.next().getTextContent())); Iterator<Node> pmids = body.getChildElements(new QName("","pmid")); assertTrue("No pmid defined", pmids.hasNext()); assertTrue("Wrong pmid value (must be '1234')", "1234".equals(pmids.next().getTextContent())); }
@Test public void testQualifiedUnwrapped() throws Exception { BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countString"); assertTrue("Is is the wrong type, it should be LiteralBodyBuilder",builder instanceof LiteralBodyBuilder); Map<String,Object>inputMap = new HashMap<String, Object>(); inputMap.put("str", "bob"); SOAPElement body = builder.build(inputMap); assertEquals("Wrong localName","str", body.getLocalName()); assertEquals("XML should containe qualifed namespace for str","http: }
@Test public void testUnwrappedSimple() throws Exception { BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countString"); assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); Map<String,Object> inputMap = new HashMap<String, Object>(); inputMap.put("str", "12345"); SOAPElement body = builder.build(inputMap); assertTrue("Input element should be named {http: assertEquals("Value should be 12345:","12345",body.getFirstChild().getNodeValue()); }
@Test public void testUnwrappedArray() throws Exception { BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countStringArray"); assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); Map<String,Object> inputMap = new HashMap<String, Object>(); inputMap.put("array", "<array><item>1</item><item>2</item><item>3</item></array>"); SOAPElement body = builder.build(inputMap); assertTrue("Outer element should be named {http: assertTrue("There must be three child nodes in array", body.getChildNodes().getLength() == 3); Iterator<Node> items = body.getChildElements(new QName("", "item")); assertTrue("Array element should be named item", items.hasNext()); assertTrue("First Array element should have the value '1'", "1".equals(items.next().getTextContent())); }
@Test public void testOperationElementNameEUtils() throws Exception { BodyBuilder builder = createBuilder(wsdlResourcePath("eutils/eutils_lite.wsdl"), "run_eInfo"); assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); Map<String,Object> inputMap = new HashMap<String, Object>(); inputMap.put("parameters", "<parameters xmlns:e='http: + "<e:db>database</e:db>" + "<e:tool>myTool</e:tool>" + "<e:email>nobody@nowhere.net</e:email>" + "</parameters>"); SOAPElement body = builder.build(inputMap); assertEquals("QName of SOAP body's element did not match expected qname ", new QName("http: body.getElementQName()); }
@Test public void testOperationElementNameTAV744() throws Exception { URL tav744Url = getResource( "TAV-744/InstrumentService__.wsdl"); BodyBuilder builder = createBuilder(tav744Url.toExternalForm(), "getList"); assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); Map<String,Object> inputMap = new HashMap<String, Object>(); SOAPElement body = builder.build(inputMap); assertEquals("QName of SOAP body's element did not match expected qname ", new QName("http: body.getElementQName()); }
@Test public void testRPCLiteral() throws Exception { BodyBuilder builder = createBuilder(wsdlResourcePath("MyService-rpc-literal.wsdl"), "countString"); assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); Map<String,Object> inputMap = new HashMap<String, Object>(); inputMap.put("str", "abcdef"); SOAPElement body = builder.build(inputMap); assertTrue("Outer element should be named {http: Node strNode = body.getFirstChild(); assertEquals("Inner element should be called 'str'","str",strNode.getNodeName()); assertEquals("str content should be abcdef","abcdef",strNode.getFirstChild().getNodeValue()); }