2013-05-22 1 views
2

Javafax 2.2 클라이언트가있는 glassfish 3.1 컨테이너에서 실행되는 원격 EJB를 실행하려고하는데 원격 EJB를 "조회"할 때 예외가 발생합니다. 내 응용 프로그램의 목적은 서버 측에서 XML 파일로 저장/검색하는 Javafx Client 객체를 가져 오거나 가져 오는 것입니다.발생 원인 : java.lang.ClassCastException 래퍼를 캐스팅 할 수 없습니다.

서버 측에서은 EJB가 EAR에 패키지되어 있습니다.

package scrubber_S_Model; 

import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 

import javax.xml.bind.JAXBContext; 
import javax.xml.bind.JAXBException; 
import javax.xml.bind.Marshaller; 
import javax.xml.bind.Unmarshaller; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlRootElement; 


@XmlRootElement(name = "SimpleObject") 
public class SimpleObject implements java.io.Serializable { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 306212289216139111L; 

    /** 
    * Used to define a simpleObject Value Object 
    */ 
    @XmlElement(name = "scrubberValveValue") 
    private int scrubberValveValue; 

    @XmlElement(name = "bypassValveValue") 
    private int bypassValveValue; 

    @XmlElement(name = "exhaustState") 
    private boolean exhaustState; 

    @XmlElement(name = "layoutColor") 
    private String layoutColor; 

    @XmlElement(name = "textValue") 
    private String textValue; 

    @XmlElement(name = "textColor") 
    private String textColor; 

    @XmlElement(name = "pressureThreshold") 
    private int pressureThreshold; 

    public SimpleObject(int bypassvalvevalue, int scrubbervalvevalue, 
      boolean exhauststate, String layoutcolor, String textvalue, 
      String textcolor, int pressurethreshold) { 

     this.bypassValveValue = bypassvalvevalue; 
     this.scrubberValveValue = scrubbervalvevalue; 
     this.exhaustState = exhauststate; 
     this.layoutColor = layoutcolor; 
     this.textValue = textvalue; 
     this.textColor = textcolor; 
     this.pressureThreshold = pressurethreshold; 
    } 

    /** 
    * Empty constructor, just to enable JAXB. 
    */ 
    public SimpleObject() { 
    } 

    /** 
    * Gets the value of the scrubberValveValue property. 
    * 
    */ 
    public int getScrubberValveValue() { 
     return this.scrubberValveValue; 
    } 

    /** 
    * Sets the value of the scrubberValveValue property. 
    * 
    */ 
    public void setScrubberValveValue(int value) { 
     this.scrubberValveValue = value; 
    } 

    /** 
    * Gets the value of the bypassValveValue property. 
    * 
    */ 

    public int getBypassValveValue() { 
     return this.bypassValveValue; 
    } 

    /** 
    * Sets the value of the bypassValveValue property. 
    * 
    */ 
    public void setBypassValveValue(int value) { 
     this.bypassValveValue = value; 
    } 

    /** 
    * Gets the value of the exhaustState property. 
    * 
    */ 

    public boolean isExhaustState() { 
     return this.exhaustState; 
    } 

    /** 
    * Sets the value of the exhaustState property. 
    * 
    */ 
    public void setExhaustState(boolean value) { 
     this.exhaustState = value; 
    } 

    /** 
    * Gets the value of the layoutColor property. 
    * 
    * @return possible object is {@link String } 
    * 
    */ 
    public String getLayoutColor() { 
     return this.layoutColor; 
    } 

    /** 
    * Sets the value of the layoutColor property. 
    * 
    * @param value 
    *   allowed object is {@link String } 
    * 
    */ 
    public void setLayoutColor(String value) { 
     this.layoutColor = value; 
    } 

    /** 
    * Gets the value of the textValue property. 
    * 
    * @return possible object is {@link String } 
    * 
    */ 

    public String getTextValue() { 
     return this.textValue; 
    } 

    /** 
    * Sets the value of the textValue property. 
    * 
    * @param value 
    *   allowed object is {@link String } 
    * 
    */ 
    public void setTextValue(String value) { 
     this.textValue = value; 
    } 

    /** 
    * Gets the value of the textColor property. 
    * 
    * @return possible object is {@link String } 
    * 
    */ 

    public String getTextColor() { 
     return this.textColor; 
    } 

    /** 
    * Sets the value of the textColor property. 
    * 
    * @param value 
    *   allowed object is {@link String } 
    * 
    */ 
    public void setTextColor(String value) { 
     this.textColor = value; 
    } 

    /** 
    * Gets the value of the pressureThreshold property. 
    * 
    */ 

    public int getPressureThreshold() { 
     return this.pressureThreshold; 
    } 

    /** 
    * Sets the value of the pressureThreshold property. 
    * 
    */ 
    public void setPressureThreshold(int value) { 
     this.pressureThreshold = value; 
    } 


public void saveSimpleObject(SimpleObject simpleobjet) throws JAXBException { 
     FileOutputStream fileout = null; 
     JAXBContext jc = JAXBContext.newInstance(SimpleObject.class); 
     Marshaller marshaller = jc.createMarshaller(); 
     marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 
     try { 
      fileout = new FileOutputStream("simpleobjectfile.xml"); 
     } catch (FileNotFoundException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
     marshaller.marshal(simpleobjet, fileout); 
     try { 
      fileout.flush(); 
      fileout.close(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

    } 

public SimpleObject retrieveSimpleObject() throws JAXBException { 
     FileInputStream fileinput = null; 
     JAXBContext jc = JAXBContext.newInstance(SimpleObject.class); 
     Unmarshaller unmarshaller = jc.createUnmarshaller(); 
     try { 
      fileinput = new FileInputStream("simpleobjectfile.xml"); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } 
     SimpleObject simpleobjet = (SimpleObject)unmarshaller.unmarshal(fileinput); 
     try { 
      fileinput.close(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return simpleobjet; 

    } 

} 

JUnit 테스트 :

제어기 "scrubber_S_Controller"을 사용 원격 인터페이스는 scrubber_S_Model 패키지 관리

package scrubber_S_Controller; 

import javax.ejb.Remote; 
import javax.xml.bind.JAXBException; 

import scrubber_S_Model.SimpleObject; 

@Remote 
public interface SessionRemote { 
    public SimpleObject getSimpleObject() throws JAXBException; 
    public void setSimpleObject(SimpleObject simpleobject) throws JAXBException; 

} 

SimpleObject이다

package scrubber_S_Controller; 

import java.io.Serializable; 

import javax.ejb.Stateless; 
import javax.xml.bind.JAXBException; 
import scrubber_S_Model.SimpleObject; 

/** 
* Session Bean implementation class Session 
*/ 
@Stateless 
public class Session implements SessionRemote, Serializable { 

    /** 
    * 
    */ 
    private static final long serialVersionUID = -5718452084852474986L; 

    /** 
    * Default constructor. 
    */ 
    public Session() { 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public SimpleObject getSimpleObject() throws JAXBException { 
     SimpleObject simpleobjet = new SimpleObject(); 
     return simpleobjet.retrieveSimpleObject(); 
    } 

    @Override 
    public void setSimpleObject(SimpleObject simpleobject) throws JAXBException { 
     simpleobject.saveSimpleObject(simpleobject); 

    } 

} 

Stateless와 세션 EJB에게 인 마샬링/언 마샬링이 잘 작동합니다. 클라이언트 측에서 다음과 같은 자바 FX 애플리케이션

INFO: EJB5181:Portable JNDI names for EJB Session: [java:global/Scrubber_S_EAR/Scrubber_S/Session, java:global/Scrubber_S_EAR/Scrubber_S/Session!scrubber_S_Controller.SessionRemote] 
INFO: CORE10010: Loading application Scrubber_S_EAR done in 4 406 ms 

:

package ScrubberView; 
import java.util.Properties; 
import javax.naming.Context; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 
import javax.xml.bind.JAXBException; 
import scrubber_CView_Model.SimpleObject; 
import session.SessionRemote; 
import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.paint.Color; 
import javafx.stage.Stage; 

public class scrubberView extends Application { 

    @Override 
    public void start(Stage primaryStage) throws JAXBException { 
     try { 
      Properties propriétés = new Properties(); 
      propriétés.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); 
      Context ctx = new InitialContext(propriétés); 
      SessionRemote mySession = (SessionRemote)ctx.lookup("java:global/Scrubber_S_EAR/Scrubber_S/Session"); 
      //Create an object to exchange 
      SimpleObject simpleObject = new SimpleObject(1, 2, true, "layoutcolor", "text", "textcolor", 10); 
      mySession.setSimpleObject(simpleObject); 
      @SuppressWarnings("unused") 
      SimpleObject simpleObject2 = new SimpleObject(); 
      simpleObject2 = mySession.getSimpleObject();   
     } catch (NamingException e) { 
      // TODO Auto-generated catch block 
      System.out.println(e.toString() ); 
      e.printStackTrace(); 
     } 

     //compose the scrubberview scene and show it 
     primaryStage.setTitle("scrubberView"); 
     BorderPane borderpane = new BorderPane(); 
     Scene scene = new Scene(borderpane, 350, 80, Color.GREY); 
     primaryStage.setScene(scene); 
     scene.getStylesheets().add("./CleanRoomControl.css"); 
     primaryStage.show(); 

    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

다음 항아리가 응용 프로그램

의 buid의 ENC에를 EJB의

배포는 다음 JNDI 이름을 부여

C:\glassfish3\glassfish\modules\auto-depends.jar 
C:\glassfish3\glassfish\modules\common-util.jar 
C:\glassfish3\glassfish\modules\config-api.jar 
C:\glassfish3\glassfish\modules\config-types.jar 
C:\glassfish3\glassfish\modules\config.jar 
C:\glassfish3\glassfish\modules\deployment-common.jar 
C:\glassfish3\glassfish\modules\dol.jar 
C:\glassfish3\glassfish\modules\ejb-container.jar 
C:\glassfish3\glassfish\modules\ejb.security.jar 
C:\glassfish3\glassfish\modules\glassfish-api.jar 
C:\glassfish3\glassfish\modules\glassfish-corba-asm.jar 
C:\glassfish3\glassfish\modules\glassfish-corba-codegen.jar 
C:\glassfish3\glassfish\modules\glassfish-corba-csiv2-idl.jar 
C:\glassfish3\glassfish\modules\glassfish-corba-newtimer.jar 
C:\glassfish3\glassfish\modules\glassfish-corba-omgapi.jar 
C:\glassfish3\glassfish\modules\glassfish-corba-orb.jar 
C:\glassfish3\glassfish\modules\glassfish-corba-orbgeneric.jar 
C:\glassfish3\glassfish\modules\glassfish-naming.jar 
C:\glassfish3\glassfish\modules\gmbal.jar 
C:\glassfish3\glassfish\modules\hk2-core.jar 
C:\glassfish3\glassfish\modules\internal-api.jar 
C:\glassfish3\glassfish\modules\javax.ejb.jar 
C:\glassfish3\glassfish\modules\kernel.jar 
C:\glassfish3\glassfish\modules\management-api.jar 
C:\glassfish3\glassfish\modules\orb-connector.jar 
C:\glassfish3\glassfish\modules\orb-iiop.jar 
C:\glassfish3\glassfish\modules\security.jar 
C:\glassfish3\glassfish\modules\transaction-internal-api.jar 

SessionRemote mySession = (SessionRemote)ctx.lookup("java:global/Scrubber_S_EAR/Scrubber_S/Session"); 

라인은 다음과 같은 exeption을 제기

Exception in Application start method 
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method 
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403) 
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47) 
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: java.lang.ClassCastException: scrubber_S_Controller._SessionRemote_Wrapper cannot be cast to session.SessionRemote 
    at ScrubberView.scrubberView.start(scrubberView.java:27) 
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) 
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29) 
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73) 
    ... 1 more 

나는 다른 이름으로 시도하는 경우 :

SessionRemote mySession = (SessionRemote)ctx.lookup("java:global/Scrubber_S_EAR/Scrubber_S/Session!scrubber_S_Controller.SessionRemote"); 

그것은 같은 exeption를 발생시킵니다.

누군가가 내가이 문제를 해결하도록 도울 수 있다면 좋을 것입니다.

도움을 주셔서 미리 감사드립니다.

나는 영어가 이해하기 너무 나쁘지 않기를 바랍니다.

답변

1

나는 다음과 같이이 문제를 해결 :

  • 는 ENV에서 jar 파일을 제거하고 만 GF-클라이언트를 넣어.클래스 패스에 항아리로
    How do I access a Remote EJB component from a stand-alone java client?

  • 이름 바꾸기에 "scrubber_S_Controler을"설명 (클라이언트 측에서 해당 패키지와) "세션"에

  • 제거 "retrieveSimpleObject()"와 "saveSimpleObject (SimpleObject simpleobjet) ""SimpleObject "클래스에서"SimpleObjectPersist 클래스 "에 추가하십시오.
  • "SimpleObjectPersist "를 사용하여 SimpleObject를 저장하고 검색하십시오.

우우! 그 후, 잘 실행 중입니다.

관련 문제