@Test public void http1006ForErrorNotHandled() throws Exception { JsonRpcServer server = new JsonRpcServer( mapper, mockService, JsonRpcErrorsTest.ServiceInterfaceWithoutAnnotation.class); server.setHttpStatusCodeProvider(httpStatusCodeProvider); assertHttpStatusCodeForJsonRpcRequest( messageWithListParamsStream(1, "testMethod"), 1006, server); }
@Before public void setUp() throws Exception { jsonRpcServer = new JsonRpcServer(mapper, mockService, JsonRpcServerTest.ServiceInterface.class); httpStatusCodeProvider = new HttpStatusCodeProvider() { @Override public int getHttpStatusCode(int resultCode) { switch (resultCode) { case -32600: return 1001; case -32700: return 1002; case -32601: return 1003; case -32602: return 1004; case -32002: return 1005; case -32001: return 1006; default: return 1000; } } }; jsonRpcServer.setHttpStatusCodeProvider(httpStatusCodeProvider); }
/** {@inheritDoc} */ public final void afterPropertiesSet() throws Exception { // find the ObjectMapper if (objectMapper == null && applicationContext != null && applicationContext.containsBean("objectMapper")) { objectMapper = (ObjectMapper) applicationContext.getBean("objectMapper"); } if (objectMapper == null && applicationContext != null) { try { objectMapper = (ObjectMapper) BeanFactoryUtils.beanOfTypeIncludingAncestors( applicationContext, ObjectMapper.class); } catch (Exception e) { /* no-op */ } } if (objectMapper == null) { objectMapper = new ObjectMapper(); } // create the service Object service = ProxyUtil.createCompositeServiceProxy( getClass().getClassLoader(), services, serviceInterfaces, allowMultipleInheritance); // create the server jsonRpcServer = new JsonRpcServer(objectMapper, service); jsonRpcServer.setErrorResolver(errorResolver); jsonRpcServer.setBackwardsComaptible(backwardsComaptible); jsonRpcServer.setRethrowExceptions(rethrowExceptions); jsonRpcServer.setAllowExtraParams(allowExtraParams); jsonRpcServer.setAllowLessParams(allowLessParams); // export exportService(); }