Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Flex应用程序中处理自定义Java异常_Java_Apache Flex_Blazeds - Fatal编程技术网

如何在Flex应用程序中处理自定义Java异常

如何在Flex应用程序中处理自定义Java异常,java,apache-flex,blazeds,Java,Apache Flex,Blazeds,我们使用BlazeDS作为Flex和Java之间的代理。该方法与()中的方法相同 Java异常声明: public class FlexException extends RuntimeException { private String name = 'John'; public FlexException(String message) { super(message); } public String getName() { return name; } } 然

我们使用BlazeDS作为Flex和Java之间的代理。该方法与()中的方法相同

Java异常声明:

public class FlexException extends RuntimeException {
 private String name = 'John';

 public FlexException(String message) {
   super(message);
 }

 public String getName() {
   return name;
 }
}
然后,我们抛出它:

public void testMethod(String str) throws Exception {
 throw new FlexException("Custom exception");
}
柔性部件:

private function faultHandler(event:FaultEvent):void
{
  var errorMessage:ErrorMessage = event.message as ErrorMessage;
  trace("error++");
}
远程对象在此处实例化:

<mx:RemoteObject id="mySample" destination="mySample" channelSet="{cs1}" fault="faultHandler(event)" />

以下是在onFaultHandler中设置断点时在Flex中得到的结果: 所以问题是为什么rootClause是空的?我的FlexException在哪里,名称为“John”。

因此,您应该使用:

errorMessage.rootCause.message;
errorMessage.rootCause.name

好的,那么您使用的是spring blazeds flex集成。在这种情况下,前面链接中描述的机制无法正常工作。您需要创建自己的异常转换器,否则将收到通用服务器。处理错误:。请阅读:


您也可以在我的朋友Ionut的博客上阅读这篇文章:

为了正确地(反)序列化自定义属性,您需要一个getter和一个setter。在您的示例中,应该为name属性添加一个“setName”setter。

在我的示例中,问题是rootClause=null。我使用调试器搜索了所有可能的属性,但没有成功。奇怪。根据和相关论坛帖子:从1.0.1版开始,不需要编写自己的异常翻译程序。不幸的是,使用v1.0.3进行快速测试后发现它不工作,异常数据丢失。blazeds记录的异常与您的方法无关,而是与另一个名为“books”的目标相关,该目标似乎是安全的。错误“Login..”直接从BlazeDS的LoginManager类抛出。如果您能提供您的flex测试应用程序和配置文件,这将有所帮助。Cornel,谢谢您的回复。日志是在问题中添加的,对于扩展Throwable的类,您不需要这样做——只使用get方法是可以的。
<?xml version="1.0" encoding="UTF-8"?>
<adapters>
    <adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
    <!-- <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/> -->
</adapters>

<default-channels>
    <channel ref="my-polling-amf"/>
</default-channels>
<?xml version="1.0" encoding="UTF-8"?>
<service id="proxy-service" 
    class="flex.messaging.services.HTTPProxyService">

    <properties>
        <connection-manager>
            <max-total-connections>100</max-total-connections>
            <default-max-connections-per-host>2</default-max-connections-per-host>
        </connection-manager>
        <allow-lax-ssl>true</allow-lax-ssl>
    </properties>

    <adapters>
        <adapter-definition id="http-proxy" class="flex.messaging.services.http.HTTPProxyAdapter" default="true"/>
        <adapter-definition id="soap-proxy" class="flex.messaging.services.http.SOAPProxyAdapter"/>
    </adapters>

    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>

    <destination id="DefaultHTTP">
    </destination>

</service>
<?xml version="1.0" encoding="UTF-8"?>
<adapters>
    <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>

<default-channels>
    <channel ref="my-amf"/>
</default-channels>
<?xml version="1.0" encoding="UTF-8"?>
<services>
    <service-include file-path="remoting-config.xml" />
    <service-include file-path="proxy-config.xml" />
    <service-include file-path="messaging-config.xml" />        
</services>

<security>
    <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>
    <!-- Uncomment the correct app server
    <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
    <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>        
    <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
    <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>
    -->

    <!-- 
    <security-constraint id="basic-read-access">
        <auth-method>Basic</auth-method>
        <roles>
            <role>guests</role>
            <role>accountants</role>
            <role>employees</role>
            <role>managers</role>
        </roles>
    </security-constraint>
     -->
</security>

<channels>

    <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
        <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
    </channel-definition>

    <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
        <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
        <properties>
            <add-no-cache-headers>false</add-no-cache-headers>
        </properties>
    </channel-definition>

    <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
        <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
        <properties>
            <polling-enabled>true</polling-enabled>
            <polling-interval-seconds>4</polling-interval-seconds>
        </properties>
    </channel-definition>

    <!--
    <channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel">
        <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
    </channel-definition>

    <channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
        <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
        <properties>
            <add-no-cache-headers>false</add-no-cache-headers>
        </properties>
    </channel-definition>
    -->
</channels>

<logging>
    <target class="flex.messaging.log.ConsoleTarget" level="Debug">
        <properties>
            <prefix>[BlazeDS] </prefix>
            <includeDate>true</includeDate>
            <includeTime>true</includeTime>
            <includeLevel>true</includeLevel>
            <includeCategory>true</includeCategory>
        </properties>
        <filters>
            <pattern>Endpoint.*</pattern>
            <pattern>Service.*</pattern>
            <pattern>Configuration</pattern>
        </filters>
    </target>
</logging>

<system>
    <redeploy>
        <enabled>false</enabled>
        <!-- 
        <watch-interval>20</watch-interval>
        <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
        <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
        <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
        <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>
        <watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file>
        <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
         -->
    </redeploy>
</system>
<bean id="mySample" class="ru.crystals.pos.testFlexConnection.Test">
    <constructor-arg ref="defaultMessageTemplate" />
    <flex:remoting-destination />
</bean>
    [BlazeDS]03/23/2010 14:46:51.870 [DEBUG] [Endpoint.AMF] Serializing AMF/HTTP res
ponse
Version: 3
  (Message #0 targetURI=/1/onStatus, responseUR|-)
    (Typed Object #0 'flex.messaging.messages.ErrorMessage')
      headers = (Object #1)
      rootCause = null
      body = null
      correlationId = "2EB1C972-B32B-03BA-825C-8AD8B9DFCEF8"
      faultDetail = null
      faultString = "There was an unhandled failure on the server. Custom except
ion"
      clientId = "89FB2149-6E0F-4FB6-4D5E-EC838139EE90"
      timeToLive = 0.0
      destination = "mySample"
      timestamp = 1.269344811854E12
      extendedData = null
      faultCode = "Server.Processing"
      messageId = "89FB2149-6E1A-4453-6E45-55A93BBA50AF"