XPathParamMethodArgumentResolver implements MethodArgumentResolver { @Override public Object resolveArgument(MessageContext messageContext, MethodParameter parameter) throws TransformerException, XPathExpressionException { Class<?> parameterType = parameter.getParameterType(); QName evaluationReturnType = getReturnType(parameterType); boolean useConversionService = false; if (evaluationReturnType == null) { evaluationReturnType = XPathConstants.STRING; useConversionService = true; } XPath xpath = createXPath(); xpath.setNamespaceContext(NamespaceUtils.getNamespaceContext(parameter.getMethod())); Element rootElement = getRootElement(messageContext.getRequest().getPayloadSource()); String expression = parameter.getParameterAnnotation(XPathParam.class).value(); Object result = xpath.evaluate(expression, rootElement, evaluationReturnType); return useConversionService ? conversionService.convert(result, parameterType) : result; }  void setConversionService(ConversionService conversionService); void setTransformerHelper(TransformerHelper transformerHelper); @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MessageContext messageContext, MethodParameter parameter);  }
@Test public void resolveBoolean() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage(CONTENTS); MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); Object result = resolver.resolveArgument(messageContext, booleanParameter); assertTrue("resolver does not return boolean", result instanceof Boolean); Boolean b = (Boolean) result; assertTrue("Invalid boolean value", b); }
@Test public void resolveDouble() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage(CONTENTS); MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); Object result = resolver.resolveArgument(messageContext, doubleParameter); assertTrue("resolver does not return double", result instanceof Double); Double d = (Double) result; assertEquals("Invalid double value", 42D, d, 0D); }
@Test public void resolveNode() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage(CONTENTS); MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); Object result = resolver.resolveArgument(messageContext, nodeParameter); assertTrue("resolver does not return Node", result instanceof Node); Node node = (Node) result; assertEquals("Invalid node value", "child", node.getLocalName()); }
@Test public void resolveNodeList() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage(CONTENTS); MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); Object result = resolver.resolveArgument(messageContext, nodeListParameter); assertTrue("resolver does not return NodeList", result instanceof NodeList); NodeList nodeList = (NodeList) result; assertEquals("Invalid NodeList value", 1, nodeList.getLength()); assertEquals("Invalid Node value", "child", nodeList.item(0).getLocalName()); }
@Test public void resolveString() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage(CONTENTS); MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); Object result = resolver.resolveArgument(messageContext, stringParameter); assertTrue("resolver does not return String", result instanceof String); String s = (String) result; assertEquals("Invalid string value", "text", s); }
@Test public void resolveConvertedType() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage(CONTENTS); MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); Object result = resolver.resolveArgument(messageContext, convertedParameter); assertTrue("resolver does not return String", result instanceof Integer); Integer i = (Integer) result; assertEquals("Invalid integer value", new Integer(42), i); }
@Test public void resolveNamespacesMethod() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage( "<root xmlns=\"http: MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); Object result = resolver.resolveArgument(messageContext, namespaceMethodParameter); assertTrue("resolver does not return String", result instanceof String); String s = (String) result; assertEquals("Invalid string value", "text", s); }
@Test public void resolveNamespacesClass() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage( "<root xmlns=\"http: MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); Object result = resolver.resolveArgument(messageContext, namespaceClassParameter); assertTrue("resolver does not return String", result instanceof String); String s = (String) result; assertEquals("Invalid string value", "text", s); }