/** * Takes a {@link SoapCall} object and invokes the method by reflection. * * @param soapCall contains the SOAP method, SOAP client, and args to be * called * @return the response from the SOAP web service * @throws Exception thrown if calling the operation on the remote service * fails */ protected Object invoke(SoapCall<T> soapCall) throws Exception { Method soapClientMethod = soapCall.getSoapClientMethod(); Object[] soapArgs = soapCall.getSoapArgs(); soapArgs = processSoapArguments(soapClientMethod, soapArgs); return soapClientMethod.invoke(soapCall.getSoapClient(), soapArgs); } }
/** * Creates the {@link SoapCall} from the {@code soapClientMethod} and its * {@code args}. */ protected SoapCall<T> createSoapCall(Method soapClientMethod, Object[] args) { return new SoapCall<T>(soapClientMethod, soapClient, args); }
/** * Invoke a SOAP call. * * @param soapCall the call to make to a SOAP web service * @return information about the SOAP response */ @Override public RemoteCallReturn invokeSoapCall(SoapCall<BindingProvider> soapCall) { BindingProvider webService = soapCall.getSoapClient(); RemoteCallReturn.Builder builder = new RemoteCallReturn.Builder(); synchronized (webService) { Object result = null; try { result = invoke(soapCall); } catch (InvocationTargetException e) { builder.withException(e.getTargetException()); } catch (Exception e) { builder.withException(e); } finally { JaxWsSoapContextHandler contextHandler = getContextHandlerFromClient(webService); String url = getEndpointAddress(webService); builder.withRequestInfo(contextHandler.getLastRequestInfoBuilder().withUrl(url).build()); builder.withResponseInfo(contextHandler.getLastResponseInfoBuilder().build()); } return builder.withReturnValue(result).build(); } }
@Test public void testHashCode() throws Exception { Method method1 = Object.class.getDeclaredMethod("equals", Object.class); Method method2 = Object.class.getDeclaredMethod("toString"); Object commonObject = new Object(); SoapCall<Object> soapCall1 = new SoapCall<Object>(method1, commonObject, new Integer[] {5}); SoapCall<Object> soapCall2 = new SoapCall<Object>(method2, commonObject, new Integer[] {5}); SoapCall<Object> soapCall3 = new SoapCall<Object>(method1, commonObject, new Integer[] {42}); SoapCall<Object> soapCall4 = new SoapCall<Object>(method1, new Object(), new Integer[] {42}); assertTrue("Hash code is not stable", soapCall1.hashCode() == soapCall1.hashCode()); assertFalse( "Hash code unaffected by method change", soapCall1.hashCode() == soapCall2.hashCode()); assertFalse( "Hash code unaffected by array change", soapCall1.hashCode() == soapCall3.hashCode()); assertFalse( "Hash code unaffected by array change", soapCall1.hashCode() == soapCall3.hashCode()); assertFalse( "Hash code unaffected by client change", soapCall1.hashCode() == soapCall4.hashCode()); } }
@Test public void testEquals() throws Exception { Method method1 = Object.class.getDeclaredMethod("equals", Object.class); Method method2 = Object.class.getDeclaredMethod("toString"); Object object1 = new Object(); Object[] objectArray = new Object[] {new Object()}; SoapCall<Object> soapCall1 = new SoapCall<Object>(method1, object1, objectArray); SoapCall<Object> soapCall2 = new SoapCall<Object>(method1, object1, objectArray); assertTrue(soapCall1.equals(soapCall2)); assertTrue(soapCall2.equals(soapCall1)); SoapCall<Object> soapCall3 = new SoapCall<Object>(method1, new Object(), objectArray); assertFalse(soapCall1.equals(soapCall3)); assertFalse(soapCall3.equals(soapCall1)); SoapCall<Object> soapCall4 = new SoapCall<Object>(method1, object1, new Object[] {}); assertFalse(soapCall1.equals(soapCall4)); assertFalse(soapCall4.equals(soapCall1)); SoapCall<Object> soapCall5 = new SoapCall<Object>(method2, object1, objectArray); assertFalse(soapCall1.equals(soapCall5)); assertFalse(soapCall5.equals(soapCall1)); }
/** * Invoke a SOAP call. * * @param soapCall the call to make to a SOAP web service * @return information about the SOAP response */ @Override public RemoteCallReturn invokeSoapCall(SoapCall<BindingProvider> soapCall) { BindingProvider webService = soapCall.getSoapClient(); RemoteCallReturn.Builder builder = new RemoteCallReturn.Builder(); synchronized (webService) { Object result = null; try { result = invoke(soapCall); } catch (InvocationTargetException e) { builder.withException(e.getTargetException()); } catch (Exception e) { builder.withException(e); } finally { JaxWsSoapContextHandler contextHandler = getContextHandlerFromClient(webService); String url = getEndpointAddress(webService); builder.withRequestInfo(contextHandler.getLastRequestInfoBuilder().withUrl(url).build()); builder.withResponseInfo(contextHandler.getLastResponseInfoBuilder().build()); } return builder.withReturnValue(result).build(); } }
/** * Takes a {@link SoapCall} object and invokes the method by reflection. * * @param soapCall contains the SOAP method, SOAP client, and args to be * called * @return the response from the SOAP web service * @throws Exception thrown if calling the operation on the remote service * fails */ protected Object invoke(SoapCall<T> soapCall) throws Exception { Method soapClientMethod = soapCall.getSoapClientMethod(); Object[] soapArgs = soapCall.getSoapArgs(); soapArgs = processSoapArguments(soapClientMethod, soapArgs); return soapClientMethod.invoke(soapCall.getSoapClient(), soapArgs); } }
Stub stub = soapCall.getSoapClient(); RemoteCallReturn.Builder builder = new RemoteCallReturn.Builder(); synchronized (stub) {
/** * Creates the {@link SoapCall} from the {@code soapClientMethod} and its * {@code args}. */ protected SoapCall<T> createSoapCall(Method soapClientMethod, Object[] args) { return new SoapCall<T>(soapClientMethod, soapClient, args); }
@Test public void testInvoke_lotsOfArgs() throws Exception { Object firstArg = new Object(); Object[] args = new Object[] {firstArg, new Object[] {}, new Object(), new Object()}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("lotsOfArgsCall", Object.class, Object[].class, Object.class, Object.class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(args); Object result = soapClientHandler.invoke(soapCall); assertSame(firstArg, result); }
Stub stub = soapCall.getSoapClient(); RemoteCallReturn.Builder builder = new RemoteCallReturn.Builder(); synchronized (stub) {
@Test public void testCreateSoapCall() throws SecurityException, NoSuchMethodException { Method indentityCallMethod = MockSoapClient.class.getMethod("identityCall", Object[].class); Object[] args = new String[] {"arg1", "arg2"}; SoapCall<Object> expectedSoapCall = new SoapCall<Object>(indentityCallMethod, soapClient, args); SoapCall<Object> soapCall = soapServiceClient.createSoapCall(indentityCallMethod, args); assertEquals(expectedSoapCall, soapCall); }
@Test public void testInvoke_emptyCall() throws Exception { Object[] args = null; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("emptyCall")); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(args); Object result = soapClientHandler.invoke(soapCall); assertNull(result); }
@Test public void testInvoke_soapClientMethod() throws Throwable { Object returnValue = new Object(); RemoteCallReturn callReturn = new RemoteCallReturn.Builder().withReturnValue(returnValue).build(); Method identityCallMethod = MockSoapClient.class.getMethod("identityCall", Object[].class); Object[] arg = new String[] {"arg1", "arg2"}; Object[] args = new Object[] {arg}; SoapCall<Object> soapCall = new SoapCall<Object>(identityCallMethod, soapClient, args); when(soapClientHandler.getSoapClientMethod(soapClient, identityCallMethod)) .thenReturn(identityCallMethod); when(soapClientHandler.invokeSoapCall(soapCall)).thenReturn(callReturn); Object result = soapServiceClient.invoke(null, identityCallMethod, args); assertEquals(returnValue, result); }
@Test public void testCall_identityCall() throws Throwable { Object[] args = new Object[] {1L, "2", 3.0d}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("identityCall", Object[].class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(new Object[] {args}); Object result = soapClientHandler.invoke(soapCall); assertSame(args, result); }
@Test public void testCall_exception() throws Throwable { Object[] args = new Object[] {1L, "2", 3.0d}; MockSoapClient mockSoapClient = new MockSoapClient(); when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("throwException", Object[].class)); when(soapCall.getSoapClient()).thenReturn(mockSoapClient); when(soapCall.getSoapArgs()).thenReturn(new Object[] {args}); thrown.expect(InvocationTargetException.class); thrown.expectCause(Matchers.<Exception>is(MockSoapClient.EXCEPTION)); soapClientHandler.invoke(soapCall); }
@Test public void testInvoke_voidCall() throws Exception { Object[] args = new Object[] {"2", 1}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("voidCall", Object[].class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(new Object[] {args}); Object result = soapClientHandler.invoke(soapCall); assertNull(result); }
@Test public void testInvoke_overloadedOneParam() throws Exception { Object[] args = new Object[] {1}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("testOverloaded", int.class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(args); Object result = soapClientHandler.invoke(soapCall); assertSame(1, result); }
@Test public void testInvoke_overloadedTwoParams() throws Exception { Object[] args = new Object[] {"moo", "cow"}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("testOverloaded", String.class, String.class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(args); Object result = soapClientHandler.invoke(soapCall); assertSame("moo", result); }
@Test public void testCall_null() throws Throwable { when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("identityCall", Object[].class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(new Object[] {null}); Object result = soapClientHandler.invoke(soapCall); assertNull(result); }