Examples of StringOutputStream


Examples of org.nutz.lang.stream.StringOutputStream

         *            显示 HTTP 头信息的模式: MODE.ALL or MODE.HEADER_ONLY
         * @return 一个文本字符串表示 HTTP 的全部内容
         */
        public static String http(HttpServletRequest req, MODE mode) {
            StringBuilder sb = new StringBuilder();
            OutputStream ops = new StringOutputStream(sb, req.getCharacterEncoding());
            http(req, ops, mode);
            return sb.toString();
        }
View Full Code Here

Examples of org.nutz.lang.stream.StringOutputStream

    @Test
    public void testPersonObject() throws Exception {
        Person p = Json.fromJson(Person.class,
                                 getFileAsInputStreamReader("org/nutz/json/person.txt"));
        StringBuilder sb = new StringBuilder();
        Writer w = new OutputStreamWriter(new StringOutputStream(sb));
        w.write(p.dump());
        w.write("\n");
        w.write(p.getFather().dump());
        w.write("\n");
        w.write(p.getCompany().getName());
View Full Code Here

Examples of org.ofbiz.base.util.StringOutputStream

        }

        // log the request message
        if (Debug.verboseOn()) {
            try {
                StringOutputStream out = new StringOutputStream();
                msg.writeTo(out);
                Debug.logInfo("Request Message:\n" + out.toString() + "\n", module);
            } catch (Throwable t) {
            }
        }

        mctx.setRequestMessage(msg);

        // new envelopes
        SOAPEnvelope resEnv = new SOAPEnvelope();
        SOAPEnvelope reqEnv = null;

        // get the service name and parameters
        try {
            reqEnv = (SOAPEnvelope) msg.getSOAPPart().getEnvelope();                   
        } catch (SOAPException e) {
            sendError(response, "Problem processing the service");
            throw new EventHandlerException("Cannot get the envelope", e);
        }
       
        List bodies = null;

        try {
            bodies = reqEnv.getBodyElements();
        } catch (AxisFault e) {
            sendError(response, e);
            throw new EventHandlerException(e.getMessage(), e);
        }

        Debug.logVerbose("[Processing]: SOAP Event", module);

        // each is a different service call
        Iterator i = bodies.iterator();

        while (i.hasNext()) {
            Object o = i.next();

            if (o instanceof RPCElement) {
                RPCElement body = (RPCElement) o;
                String serviceName = body.getMethodName();
                List params = null;

                try {
                    params = body.getParams();
                } catch (Exception e) {
                    sendError(response, e);
                    throw new EventHandlerException(e.getMessage(), e);
                }
                Map serviceContext = new HashMap();
                Iterator p = params.iterator();

                while (p.hasNext()) {
                    RPCParam param = (RPCParam) p.next();

                    if (Debug.verboseOn()) Debug.logVerbose("[Reading Param]: " + param.getName(), module);
                    serviceContext.put(param.getName(), param.getObjectValue());
                }
                try {
                    // verify the service is exported for remote execution and invoke it
                    ModelService model = dispatcher.getDispatchContext().getModelService(serviceName);

                    if (model != null && model.export) {
                        Map result = dispatcher.runSync(serviceName, serviceContext);

                        Debug.logVerbose("[EventHandler] : Service invoked", module);
                        RPCElement resBody = new RPCElement(serviceName + "Response");

                        resBody.setPrefix(body.getPrefix());
                        resBody.setNamespaceURI(body.getNamespaceURI());
                        Set keySet = result.keySet();
                        Iterator ri = keySet.iterator();

                        while (ri.hasNext()) {
                            Object key = ri.next();
                            RPCParam par = new RPCParam(((String) key), result.get(key));

                            resBody.addParam(par);
                        }
                        resEnv.addBodyElement(resBody);
                        resEnv.setEncodingStyle(Constants.URI_LITERAL_ENC);
                    } else {
                        sendError(response, "Requested service not available");
                        throw new EventHandlerException("Service is not exported");
                    }
                } catch (GenericServiceException e) {
                    sendError(response, "Problem processing the service");
                    throw new EventHandlerException(e.getMessage(), e);
                } catch (javax.xml.soap.SOAPException e) {
                    sendError(response, "Problem processing the service");
                    throw new EventHandlerException(e.getMessage(), e);
                }
            }
        }

        // setup the response
        Debug.logVerbose("[EventHandler] : Setting up response message", module);
        msg = new Message(resEnv);
        mctx.setResponseMessage(msg);
        if (msg == null) {
            sendError(response, "No response message available");
            throw new EventHandlerException("No response message available");
        }

        // log the response message
        if (Debug.verboseOn()) {
            try {
                StringOutputStream out = new StringOutputStream();
                msg.writeTo(out);
                Debug.log("Response Message:\n" + out.toString() + "\n", module);
            } catch (Throwable t) {
            }
        }

        try {           
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.