Search in sources :

Example 16 with MarshallException

use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.

the class BaseCallMarshaller method marshallOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Marshaller#marshallOutbound(org.directwebremoting.Replies, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
public void marshallOutbound(Replies replies, HttpServletRequest request, HttpServletResponse response) throws IOException {
    // Get the output stream and setup the mimetype
    response.setContentType(getOutboundMimeType());
    PrintWriter out;
    if (log.isDebugEnabled()) {
        // This might be considered evil - altering the program flow
        // depending on the log status, however DebuggingPrintWriter is
        // very thin and only about logging
        out = new DebuggingPrintWriter("", response.getWriter());
    } else {
        out = response.getWriter();
    }
    // The conduit to pass on reverse ajax scripts
    ScriptConduit conduit = new CallScriptConduit(out);
    // Setup a debugging prefix
    if (out instanceof DebuggingPrintWriter) {
        DebuggingPrintWriter dpw = (DebuggingPrintWriter) out;
        dpw.setPrefix("out(" + conduit.hashCode() + "): ");
    }
    // Send the script prefix (if any)
    sendOutboundScriptPrefix(out, replies.getBatchId());
    // From the call to addScriptConduit() there could be 2 threads writing
    // to 'out' so we synchronize on 'out' to make sure there are no
    // clashes
    RealScriptSession scriptSession = (RealScriptSession) WebContextFactory.get().getScriptSession();
    out.println(ProtocolConstants.SCRIPT_CALL_INSERT);
    scriptSession.writeScripts(conduit);
    out.println(ProtocolConstants.SCRIPT_CALL_REPLY);
    String batchId = replies.getBatchId();
    for (int i = 0; i < replies.getReplyCount(); i++) {
        Reply reply = replies.getReply(i);
        String callId = reply.getCallId();
        try {
            // The existance of a throwable indicates that something went wrong
            if (reply.getThrowable() != null) {
                Throwable ex = reply.getThrowable();
                EnginePrivate.remoteHandleException(conduit, batchId, callId, ex);
                log.warn("--Erroring: batchId[" + batchId + "] message[" + ex.toString() + ']');
            } else {
                Object data = reply.getReply();
                EnginePrivate.remoteHandleCallback(conduit, batchId, callId, data);
            }
        } catch (IOException ex) {
            // We're a bit stuck we died half way through writing so
            // we can't be sure the browser can react to the failure.
            // Since we can no longer do output we just log and end
            log.error("--Output Error: batchId[" + batchId + "] message[" + ex.toString() + ']', ex);
        } catch (MarshallException ex) {
            EnginePrivate.remoteHandleMarshallException(conduit, batchId, callId, ex);
            log.warn("--MarshallException: batchId=" + batchId + " class=" + ex.getConversionType().getName(), ex);
        } catch (Exception ex) {
            // This is a bit of a "this can't happen" case so I am a bit
            // nervous about sending the exception to the client, but we
            // want to avoid silently dying so we need to do something.
            EnginePrivate.remoteHandleException(conduit, batchId, callId, ex);
            log.error("--MarshallException: batchId=" + batchId + " message=" + ex.toString());
        }
    }
    sendOutboundScriptSuffix(out, replies.getBatchId());
}
Also used : IOException(java.io.IOException) MarshallException(org.directwebremoting.extend.MarshallException) IOException(java.io.IOException) ServerException(org.directwebremoting.extend.ServerException) DebuggingPrintWriter(org.directwebremoting.util.DebuggingPrintWriter) ScriptConduit(org.directwebremoting.extend.ScriptConduit) MarshallException(org.directwebremoting.extend.MarshallException) Reply(org.directwebremoting.extend.Reply) RealScriptSession(org.directwebremoting.extend.RealScriptSession) PrintWriter(java.io.PrintWriter) DebuggingPrintWriter(org.directwebremoting.util.DebuggingPrintWriter)

Example 17 with MarshallException

use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.

the class PrimitiveConverter method convertInbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
     */
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
    String value = iv.getValue();
    // EDIT- Terry Packer
    // To deal with bug where 1.0023e+32 gets coded to 1.0023e 32 and can't be converted
    boolean scientific = false;
    if (paramType.getName().equalsIgnoreCase("double") && (value.contains("+"))) {
        scientific = true;
    } else if (paramType.getName().equalsIgnoreCase("float") && (value.contains("+")))
        scientific = true;
    if (!scientific)
        value = LocalUtil.decode(value.trim());
    try {
        return LocalUtil.simpleConvert(value, paramType);
    } catch (NumberFormatException ex) {
        throw new MarshallException(paramType, Messages.getString("PrimitiveConverter.FormatError", value));
    } catch (IllegalArgumentException ex) {
        throw new MarshallException(paramType);
    }
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException)

Example 18 with MarshallException

use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.

the class XOMConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    try {
        // Using XSLT to convert to a stream. Setup the source
        if (!(data instanceof Node)) {
            throw new MarshallException(data.getClass());
        }
        Node node = (Node) data;
        String script = EnginePrivate.xmlStringToJavascriptDom(node.toXML());
        OutboundVariable ov = new SimpleOutboundVariable(script, outctx, false);
        outctx.put(data, ov);
        return ov;
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Node(nu.xom.Node) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException)

Example 19 with MarshallException

use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.

the class DefaultConverterManager method convertInbound.

/* (non-Javadoc)
     * @see org.directwebremoting.ConverterManager#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext, org.directwebremoting.TypeHintContext)
     */
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx, TypeHintContext incc) throws MarshallException {
    Object converted = inctx.getConverted(iv, paramType);
    if (converted == null) {
        // Was the inbound variable marshalled as an Object in the client
        // (could mean that this is an instance of one of our generated
        // JavaScript classes)
        Converter converter = getNamedConverter(paramType, iv.getType());
        // didn't find anything above
        if (converter == null) {
            converter = getConverter(paramType);
        }
        if (converter == null) {
            throw new MarshallException(paramType, Messages.getString("DefaultConverterManager.MissingConverter", paramType));
        }
        // from passing null to things they are not allowed to convert
        if (iv.isNull()) {
            return null;
        }
        inctx.pushContext(incc);
        converted = converter.convertInbound(paramType, iv, inctx);
        inctx.popContext();
    }
    return converted;
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException) NamedConverter(org.directwebremoting.extend.NamedConverter) Converter(org.directwebremoting.extend.Converter)

Example 20 with MarshallException

use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.

the class BlabberConverterManager method getNamedConverter.

/**
 * When we are using typed Javascript names we sometimes want to get a specially named converter
 *
 * @param paramType
 *            The class that we are converting to
 * @param type
 *            The type name as passed in from the client
 * @return The Converter that matches this request (if any)
 * @throws MarshallException
 */
protected Converter getNamedConverter(Class<?> paramType, String type) throws MarshallException {
    if (type.startsWith("Object_")) {
        // Extract the JavaScript classname from the inbound type
        String javascriptClassName = type.substring("Object_".length());
        // Locate a converter for this JavaScript classname
        synchronized (converters) {
            Iterator<Map.Entry<String, Converter>> it = converters.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Converter> entry = it.next();
                String match = entry.getKey();
                Converter conv = entry.getValue();
                // JavaScript mapping is only applicable for compound converters
                if (conv instanceof NamedConverter) {
                    NamedConverter boConv = (NamedConverter) conv;
                    if (boConv.getJavascript() != null && boConv.getJavascript().equals(javascriptClassName)) {
                        // parameter type?
                        try {
                            Class<?> inboundClass = LocalUtil.classForName(match);
                            if (paramType.isAssignableFrom(inboundClass)) {
                                // Hack: We also want to make sure that the
                                // converter creates its object based on the
                                // inbound class instead of the parameter
                                // type, and we have to use the other ref
                                // for this:
                                boConv.setInstanceType(inboundClass);
                                return boConv;
                            }
                        } catch (ClassNotFoundException ex) {
                            throw new MarshallException(paramType, ex);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException) NamedConverter(org.directwebremoting.extend.NamedConverter) NamedConverter(org.directwebremoting.extend.NamedConverter) Converter(org.directwebremoting.extend.Converter) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MarshallException (org.directwebremoting.extend.MarshallException)43 Map (java.util.Map)16 OutboundVariable (org.directwebremoting.extend.OutboundVariable)12 Iterator (java.util.Iterator)10 HashMap (java.util.HashMap)9 TreeMap (java.util.TreeMap)9 Property (org.directwebremoting.extend.Property)9 SimpleOutboundVariable (org.directwebremoting.dwrp.SimpleOutboundVariable)8 InboundVariable (org.directwebremoting.extend.InboundVariable)8 TypeHintContext (org.directwebremoting.extend.TypeHintContext)7 ObjectOutboundVariable (org.directwebremoting.dwrp.ObjectOutboundVariable)5 IntrospectionException (java.beans.IntrospectionException)4 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 StringTokenizer (java.util.StringTokenizer)4 Converter (org.directwebremoting.extend.Converter)4 NamedConverter (org.directwebremoting.extend.NamedConverter)4 BeanInfo (java.beans.BeanInfo)3 PropertyDescriptor (java.beans.PropertyDescriptor)3 StringWriter (java.io.StringWriter)3