Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Java Java Java

  1. #1

    Java Java Java

    Ciao
    sono disperata... devo in tutti i modi capire come funzionano sti benedetti EJB con le pagine JSP facendo interagire il tutto con un DB.... Non ci cavo le gambe... Ho trovato una marea di tutorial che ti dicono solo clicca qui clicca là.. e fai tutto con i wizard io invece devo capire come si fanno queste robe qui.... AIUTO... ci metto poi che devo capirlo usando WSAD5 dell'IBM ... UFFA, non ne posso più... qui in ditta devo fare tutto da sola e nessuno mi spiega niente.. c'è qualcuno tra voi che mi può aiutare? Tra poco dovrebbe partire lo sviluppo di un progetto in java che comprende JSP+EJB ( non so se ci sono pure i servlet...) che interagiscono con l'AS/400, quindi mi servirebbe materiale che mi spiega come posso fare anche un esempio cretino su questa roba.... NON NE POSSO PIU' !!! AIUTATEMI, PLEASE PLEAAAASE, PLEEEEEAAAAASE

    Baci tristi a tutti!
    Ty.

  2. #2
    Utente di HTML.it L'avatar di Angelo1974
    Registrato dal
    Feb 2003
    Messaggi
    1,107
    Ciao.. senti io non ho ancora studiato gli EJB, ma sto per arrivarci, posso darti questi esempi, solo che interagiscono anche con SOAP e i Servizi Web, spero ti siano d'aiuto:

    import java.util.*;
    import javax.naming.*;
    import java.rmi.*;
    import javax.rmi.*;
    import jwsunleashed.trading.ejb.*;


    public class TestTrading
    {
    public static void main(String[] args)
    {
    try
    {
    Context context = new InitialContext();

    TradingHome home = (TradingHome) PortableRemoteObject.narrow(
    context.lookup("ejb/TradingHome"), TradingHome.class);

    Trading trading = home.create("mark", "secret");

    trading.buy("SUNW", 100, 2000);

    }
    catch (Exception exc)
    {
    exc.printStackTrace();
    }
    }
    }

    import java.util.*;
    import javax.naming.*;
    import java.rmi.*;
    import javax.rmi.*;
    import javax.ejb.*;
    import java.security.*;
    import java.math.*;
    import jwsunleashed.trading.ejb.*;

    public class StockTrading
    {
    // The table of user sessions
    protected static Hashtable users = new Hashtable();
    protected SecureRandom random;

    public StockTrading()
    {
    try
    {
    // Create the object for creating random session ID's
    random = SecureRandom.getInstance("SHA1PRNG");
    }
    catch (NoSuchAlgorithmException exc)
    {
    exc.printStackTrace();
    }
    }

    public String login(String userID, String password)
    throws TradingException
    {
    try
    {
    Context context = new InitialContext();

    // Locate the Trading session home interface
    TradingHome home = (TradingHome) PortableRemoteObject.narrow(
    context.lookup("ejb/TradingHome"), TradingHome.class);

    // Create a new trading session
    Trading trading = home.create(userID, password);

    byte[] uniqueID = new byte[16];

    // Generate a random 128-bit (16-byte) session key
    random.nextBytes(uniqueID);

    // Use BigInteger to create a string of hex digits
    String uniqueIDKey = (new BigInteger(uniqueID)).toString(16);

    // Associate the key with the trading session
    users.put(uniqueIDKey, trading);

    // Return the key to the user
    return uniqueIDKey;
    }
    catch (NamingException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    catch (CreateException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    catch (Exception exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public TradeResult put(String uniqueID, String stock, int shares,
    int price)
    throws TradingException
    {
    // Locate the user's session
    Trading trading = getTradingSession(uniqueID);

    try
    {
    // Let the trading session handle the put request
    return trading.put(stock, shares, price);
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public TradeResult buy(String uniqueID, String stock, int shares,
    int price)
    throws TradingException
    {
    // Locate the user's session
    Trading trading = getTradingSession(uniqueID);

    try
    {
    // Let the trading session handle the buy request
    return trading.buy(stock, shares, price);
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public TradeResult retractPut(String uniqueID, int putID)
    throws TradingException
    {
    // Locate the user's session
    Trading trading = getTradingSession(uniqueID);

    try
    {
    // Let the trading session retract the put request
    return trading.retractPut(putID);
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public TradeResult retractBuy(String uniqueID, int buyID)
    throws TradingException
    {
    // Locate the user's session
    Trading trading = getTradingSession(uniqueID);

    try
    {
    // Let the trading session retract the buy request
    return trading.retractBuy(buyID);
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public TradeResult getPutStatus(String uniqueID, int putID)
    throws TradingException
    {
    // Locate the user's session
    Trading trading = getTradingSession(uniqueID);

    try
    {
    // Fetch the put status from the session bean
    return trading.getPutStatus(putID);
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public TradeResult getBuyStatus(String uniqueID, int buyID)
    throws TradingException
    {
    // Locate the user's session
    Trading trading = getTradingSession(uniqueID);

    try
    {
    // Fetch the buy status from the session bean
    return trading.getBuyStatus(buyID);
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public TradeResult[] getOutstandingPuts(String uniqueID)
    throws TradingException
    {
    // Locate the user's session
    Trading trading = getTradingSession(uniqueID);

    try
    {
    // Fetch the outstanding puts from the session bean
    return trading.getOutstandingPuts();
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public TradeResult[] getOutstandingBuys(String uniqueID)
    throws TradingException
    {
    // Locate the user's session
    Trading trading = getTradingSession(uniqueID);

    try
    {
    // Fetch the outstanding buys from the session bean
    return trading.getOutstandingBuys();
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    throw new TradingException(exc.toString());
    }
    }

    public void logout(String uniqueID)
    throws TradingException
    {
    // Log the user out (remove the session)
    Trading trading = (Trading) users.get(uniqueID);
    if (trading != null)
    {
    // Remove the session from the table
    users.remove(uniqueID);
    try
    {
    // Remove the EJB session
    trading.remove();
    }
    catch (RemoveException exc)
    {
    exc.printStackTrace();
    }
    catch (RemoteException exc)
    {
    exc.printStackTrace();
    }

    return;
    }
    throw new TradingException("ID "+uniqueID+" is not logged in");
    }

    protected Trading getTradingSession(String uniqueID)
    throws TradingException
    {
    Trading trading = (Trading) users.get(uniqueID);

    if (trading != null) return trading;

    throw new TradingException("ID "+uniqueID+" is not logged in");
    }
    }
    Se vuoi trovare l'arcobaleno, devi sopportare la pioggia

  3. #3
    Utente di HTML.it L'avatar di Angelo1974
    Registrato dal
    Feb 2003
    Messaggi
    1,107
    import java.util.*;
    import java.io.*;
    import java.net.*;
    import jwsunleashed.trading.ejb.TradeResult;
    import jwsunleashed.trading.TradingException;

    import org.apache.soap.*;
    import org.apache.soap.encoding.*;
    import org.apache.soap.encoding.soapenc.*;
    import org.apache.soap.rpc.*;
    import org.apache.soap.util.xml.*;

    public class StockClient
    {
    public static void main(String[] args)
    {
    try
    {
    URL url = new URL("http://localhost:8000/soap/servlet/rpcrouter");

    // Create a new call for logging in
    Call call = new Call();
    call.setTargetObjectURI("urn:Trading");
    call.setMethodName("login");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC );

    // Create the list of parameters
    Vector params = new Vector();

    params.addElement(new Parameter("userID", String.class,
    "mark", null));
    params.addElement(new Parameter("password", String.class,
    "secret", null));

    call.setParams(params);

    // Invoke the call
    Response resp = call.invoke(url, "");

    String uniqueID = null;

    if (!resp.generatedFault())
    {
    Parameter ret = resp.getReturnValue();

    uniqueID = (String) ret.getValue();

    System.out.println("Your login ID is: "+uniqueID);
    }
    else
    {
    Fault fault = resp.getFault();
    System.err.println("Generated fault:");
    System.err.println(" Fault code = " + fault.getFaultCode());
    System.err.println(" Fault string = " + fault.getFaultString());
    System.exit(0);
    }

    // For the other calls, you need a BeanSerializer to process the
    // TradeResult objects
    BeanSerializer ser = new BeanSerializer();

    SOAPMappingRegistry reg = new SOAPMappingRegistry();

    reg.mapTypes(Constants.NS_URI_SOAP_ENC,
    new QName("urn:stocktrading", "traderesult"),
    TradeResult.class, ser, ser);

    // Create another call for issuing a put order
    call = new Call();

    call.setTargetObjectURI("urn:Trading");
    call.setMethodName("put");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC );

    // Tell the call how to deserialize a TradeResult
    call.setSOAPMappingRegistry(reg);

    // Create the parameter list
    params = new Vector();

    params.addElement(new Parameter("uniqueID", String.class,
    uniqueID, null));
    params.addElement(new Parameter("stock", String.class,
    "SUNW", null));
    params.addElement(new Parameter("shares", Integer.class,
    new Integer(1000), null));
    params.addElement(new Parameter("price", Integer.class,
    new Integer(2000), null));

    call.setParams(params);

    // Invoke the call
    resp = call.invoke(url, "");

    if (!resp.generatedFault())
    {
    Parameter ret = resp.getReturnValue();

    TradeResult result = (TradeResult) ret.getValue();

    System.out.println(result);
    }
    else
    {
    Fault fault = resp.getFault();
    System.err.println("Generated fault:");
    System.err.println(" Fault code = " + fault.getFaultCode());
    System.err.println(" Fault string = " + fault.getFaultString());
    System.exit(0);
    }

    // Create a call for issuing a buy order
    call = new Call();
    call.setTargetObjectURI("urn:Trading");
    call.setMethodName("buy");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC );

    // Tell the call how to deserialize a TradeResult
    call.setSOAPMappingRegistry(reg);

    // Create the parameter list
    params = new Vector();

    params.addElement(new Parameter("uniqueID", String.class,
    uniqueID, null));
    params.addElement(new Parameter("stock", String.class,
    "SUNW", null));
    params.addElement(new Parameter("shares", Integer.class,
    new Integer(1000), null));
    params.addElement(new Parameter("price", Integer.class,
    new Integer(2200), null));

    call.setParams(params);

    // Invoke the call
    resp = call.invoke(url, "");

    if (!resp.generatedFault())
    {
    Parameter ret = resp.getReturnValue();

    TradeResult result = (TradeResult) ret.getValue();

    System.out.println(result);
    }
    else
    {
    Fault fault = resp.getFault();
    System.err.println("Generated fault:");
    System.err.println(" Fault code = " + fault.getFaultCode());
    System.err.println(" Fault string = " + fault.getFaultString());
    System.exit(0);
    }

    // Create a call for logging out
    call = new Call();
    call.setTargetObjectURI("urn:Trading");
    call.setMethodName("logout");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC );

    // Create the parameter list
    params = new Vector();

    params.addElement(new Parameter("uniqueID", String.class,
    uniqueID, null));

    call.setParams(params);

    // Invoke the call
    resp = call.invoke(url, "");

    if (!resp.generatedFault())
    {
    System.out.println("You have logged out successfully.");
    }
    else
    {
    Fault fault = resp.getFault();
    System.err.println("Generated fault:");
    System.err.println(" Fault code = " + fault.getFaultCode());
    System.err.println(" Fault string = " + fault.getFaultString());
    System.exit(0);
    }
    }
    catch (Exception exc)
    {
    exc.printStackTrace();
    }
    }
    }


    package jwsunleashed.trading;

    public class TradingException extends Exception
    {
    public TradingException()
    {
    }

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

    Spero ti siano d'aiuto....ciao
    Se vuoi trovare l'arcobaleno, devi sopportare la pioggia

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.