当前位置: 首页>>代码示例>>Java>>正文


Java JsonRpcServer.handle方法代码示例

本文整理汇总了Java中com.googlecode.jsonrpc4j.JsonRpcServer.handle方法的典型用法代码示例。如果您正苦于以下问题:Java JsonRpcServer.handle方法的具体用法?Java JsonRpcServer.handle怎么用?Java JsonRpcServer.handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.googlecode.jsonrpc4j.JsonRpcServer的用法示例。


在下文中一共展示了JsonRpcServer.handle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import com.googlecode.jsonrpc4j.JsonRpcServer; //导入方法依赖的package包/类
public void handle(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String uri = request.getRequestURI();
    JsonRpcServer skeleton = skeletonMap.get(uri);
    if (cors) {
        response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
        response.setHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER, "POST");
        response.setHeader(ACCESS_CONTROL_ALLOW_HEADERS_HEADER, "*");
    }
    if (request.getMethod().equalsIgnoreCase("OPTIONS")) {
        response.setStatus(200);
    } else if (request.getMethod().equalsIgnoreCase("POST")) {

        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
        try {
            skeleton.handle(request.getInputStream(), response.getOutputStream());
        } catch (Throwable e) {
            throw new ServletException(e);
        }
    } else {
        response.setStatus(500);
    }
}
 
开发者ID:dubbo,项目名称:dubbo-rpc-jsonrpc,代码行数:24,代码来源:JsonRpcProtocol.java

示例2: testGzipResponse

import com.googlecode.jsonrpc4j.JsonRpcServer; //导入方法依赖的package包/类
@Test
public void testGzipResponse() throws IOException {
	MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test-post");
	request.addHeader(ACCEPT_ENCODING, "gzip");
	request.setContentType("application/json");
	request.setContent("{\"jsonrpc\":\"2.0\",\"id\":123,\"method\":\"testMethod\",\"params\":[\"Whir?inaki\"]}".getBytes(StandardCharsets.UTF_8));

	MockHttpServletResponse response = new MockHttpServletResponse();

	jsonRpcServer = new JsonRpcServer(Util.mapper, mockService, ServiceInterface.class, true);
	jsonRpcServer.handle(request, response);

	byte[] compressed = response.getContentAsByteArray();
	String sb = getCompressedResponseContent(compressed);

	Assert.assertEquals(sb, "{\"jsonrpc\":\"2.0\",\"id\":123,\"result\":null}");
	Assert.assertEquals("gzip", response.getHeader(CONTENT_ENCODING));
}
 
开发者ID:briandilley,项目名称:jsonrpc4j,代码行数:19,代码来源:JsonRpcServerTest.java

示例3: testCorruptRequest

import com.googlecode.jsonrpc4j.JsonRpcServer; //导入方法依赖的package包/类
@Test
public void testCorruptRequest() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test-post");
	request.setContentType("application/json");
	request.setContent("{NOT JSON}".getBytes(StandardCharsets.UTF_8));

	MockHttpServletResponse response = new MockHttpServletResponse();

	jsonRpcServer = new JsonRpcServer(Util.mapper, mockService, ServiceInterface.class, true);
	jsonRpcServer.handle(request, response);

	String content = response.getContentAsString();

	Assert.assertEquals(content, "{\"jsonrpc\":\"2.0\",\"id\":\"null\"," +
			"\"error\":{\"code\":-32700,\"message\":\"JSON parse error\"}}\n");
}
 
开发者ID:briandilley,项目名称:jsonrpc4j,代码行数:17,代码来源:JsonRpcServerTest.java

示例4: testGzipRequest

import com.googlecode.jsonrpc4j.JsonRpcServer; //导入方法依赖的package包/类
@Test
public void testGzipRequest() throws IOException {
	MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test-post");
	request.addHeader(CONTENT_ENCODING, "gzip");
	request.setContentType("application/json");
	byte[] bytes = "{\"jsonrpc\":\"2.0\",\"id\":123,\"method\":\"testMethod\",\"params\":[\"Whir?inaki\"]}".getBytes(StandardCharsets.UTF_8);

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	GZIPOutputStream gos = new GZIPOutputStream(baos);
	gos.write(bytes);
	gos.close();

	request.setContent(baos.toByteArray());

	MockHttpServletResponse response = new MockHttpServletResponse();
	jsonRpcServer = new JsonRpcServer(Util.mapper, mockService, ServiceInterface.class, true);
	jsonRpcServer.handle(request, response);

	String responseContent = new String(response.getContentAsByteArray(), StandardCharsets.UTF_8);
	Assert.assertEquals(responseContent, "{\"jsonrpc\":\"2.0\",\"id\":123,\"result\":null}\n");
	Assert.assertNull(response.getHeader(CONTENT_ENCODING));
}
 
开发者ID:briandilley,项目名称:jsonrpc4j,代码行数:23,代码来源:JsonRpcServerTest.java

示例5: testGzipRequestAndResponse

import com.googlecode.jsonrpc4j.JsonRpcServer; //导入方法依赖的package包/类
@Test
public void testGzipRequestAndResponse() throws IOException {
	MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test-post");
	request.addHeader(CONTENT_ENCODING, "gzip");
	request.addHeader(ACCEPT_ENCODING, "gzip");
	request.setContentType("application/json");
	byte[] bytes = "{\"jsonrpc\":\"2.0\",\"id\":123,\"method\":\"testMethod\",\"params\":[\"Whir?inaki\"]}".getBytes(StandardCharsets.UTF_8);

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	GZIPOutputStream gos = new GZIPOutputStream(baos);
	gos.write(bytes);
	gos.close();

	request.setContent(baos.toByteArray());

	MockHttpServletResponse response = new MockHttpServletResponse();
	jsonRpcServer = new JsonRpcServer(Util.mapper, mockService, ServiceInterface.class, true);
	jsonRpcServer.handle(request, response);

	byte[] compressed = response.getContentAsByteArray();
	String sb = getCompressedResponseContent(compressed);

	Assert.assertEquals(sb, "{\"jsonrpc\":\"2.0\",\"id\":123,\"result\":null}");
	Assert.assertEquals("gzip", response.getHeader(CONTENT_ENCODING));
}
 
开发者ID:briandilley,项目名称:jsonrpc4j,代码行数:26,代码来源:JsonRpcServerTest.java

示例6: assertHttpStatusCodeForJsonRpcRequest

import com.googlecode.jsonrpc4j.JsonRpcServer; //导入方法依赖的package包/类
public static void assertHttpStatusCodeForJsonRpcRequest(InputStream message, int expectedCode, JsonRpcServer server) throws Exception {
	MockHttpServletRequest req = new MockHttpServletRequest();
	MockHttpServletResponse res = new MockHttpServletResponse();
	req.setMethod(HttpMethod.POST.name());
	req.setContent(convertInputStreamToByteArray(message));
	server.handle(req, res);
	Assert.assertEquals(expectedCode, res.getStatus());
}
 
开发者ID:briandilley,项目名称:jsonrpc4j,代码行数:9,代码来源:DefaultHttpStatusCodeProviderTest.java


注:本文中的com.googlecode.jsonrpc4j.JsonRpcServer.handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。