Package org.apache.tuscany.sca.binding.jsonrpc.protocol

Examples of org.apache.tuscany.sca.binding.jsonrpc.protocol.JsonRpc10Response


                sb.append("\"id\":" + request.getParameter("id"));
                sb.append("}");

                root = JacksonHelper.MAPPER.readTree(sb.toString());
            } catch (Throwable e) {
                JsonRpc10Response error =
                    new JsonRpc10Response(JsonNodeFactory.instance.textNode(request.getParameter("id")), e);
                error.write(response.getWriter());
                return;
            }
        } else {
            root = JacksonHelper.MAPPER.readTree(request.getReader());
        }

        try {
            if (root.isArray()) {
                ArrayNode input = (ArrayNode)root;
                JsonRpc20BatchRequest batchReq = new JsonRpc20BatchRequest(input);
                for (int i = 0; i < batchReq.getRequests().size(); i++) {
                    JsonRpcResponse result = batchReq.getBatchResponse().getResponses().get(i);
                    if (result == null) {
                        result = invoke(batchReq.getRequests().get(i));
                        batchReq.getBatchResponse().getResponses().set(i, result);
                    }
                }
                ArrayNode responses = batchReq.getBatchResponse().toJSONArray();
                JacksonHelper.MAPPER.writeValue(response.getWriter(), responses);
            } else {
                if (root.has("jsonrpc")) {
                    JsonRpc20Request jsonReq = new JsonRpc20Request((ObjectNode)root);
                    JsonRpcResponse jsonResult = invoke(jsonReq);
                    if (jsonResult != null) {
                        jsonResult.write(response.getWriter());
                    }
                } else {
                    JsonRpc10Request jsonReq = new JsonRpc10Request((ObjectNode)root);
                    JsonRpc10Response jsonResult = invoke(jsonReq);
                    if (jsonResult != null) {
                        jsonResult.write(response.getWriter());
                    }
                }
            }
        } catch (Throwable e) {
            throw new ServletException(e);
View Full Code Here


            responseMessage = endpoint.getInvocationChain(jsonOperation).getHeadInvoker().invoke(requestMessage);
        } catch (RuntimeException e) {
            if (e.getCause() instanceof LoginException) {
                throw e;
            } else {
                JsonRpc10Response error = new JsonRpc10Response(request.getId(), e);
                return error;
            }
        }

        if (!responseMessage.isFault()) {
            if (jsonOperation.getOutputWrapper().getDataBinding().equals(JSONDataBinding.NAME)) {
                result = responseMessage.getBody();
                return new JsonRpc10Response((ObjectNode)JacksonHelper.MAPPER.readTree(result.toString()));
            } else {
                if (jsonOperation.getOutputType().getLogical().size() == 0) {
                    // void operation (json-rpc notification)
                    JsonRpc10Response response =
                        new JsonRpc10Response(request.getId(), JsonNodeFactory.instance.nullNode());
                    return response;

                } else {
                    // regular operation returning some value
                    result = responseMessage.getBody();
                    JsonRpc10Response response = new JsonRpc10Response(request.getId(), (JsonNode)result);
                    //get response to send to client
                    return response;
                }
            }

        } else {
            //exception thrown while executing the invocation
            Throwable exception = (Throwable)responseMessage.getBody();

            JsonRpc10Response error = new JsonRpc10Response(request.getId(), exception);
            return error;
        }

    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.binding.jsonrpc.protocol.JsonRpc10Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.