/* | |||||
* To change this license header, choose License Headers in Project Properties. | |||||
* To change this template file, choose Tools | Templates | |||||
* and open the template in the editor. | |||||
*/ | |||||
package controller; | |||||
import gui.Hauptfenster; | |||||
import java.awt.event.ActionEvent; | |||||
import java.awt.event.ActionListener; | |||||
import java.text.ParseException; | |||||
import java.util.logging.Level; | |||||
import java.util.logging.Logger; | |||||
import javax.sip.InvalidArgumentException; | |||||
import javax.sip.SipException; | |||||
import model.VoIP; | |||||
/** | |||||
* | |||||
* @author Normal | |||||
*/ | |||||
public class CommandController implements ActionListener | |||||
{ | |||||
private VoIP model; | |||||
private Hauptfenster view; | |||||
public CommandController(VoIP model, Hauptfenster view) | |||||
{ | |||||
this.model = model; | |||||
this.view = view; | |||||
} | |||||
public void registerEvents() | |||||
{ | |||||
view.getBtn1().addActionListener(this); | |||||
} | |||||
@Override | |||||
public void actionPerformed(ActionEvent e) | |||||
{ | |||||
try | |||||
{ | |||||
model.sendRegister("123123", 1); | |||||
} | |||||
catch (ParseException ex) | |||||
{ | |||||
Logger.getLogger(CommandController.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
catch (InvalidArgumentException ex) | |||||
{ | |||||
Logger.getLogger(CommandController.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
catch (SipException ex) | |||||
{ | |||||
Logger.getLogger(CommandController.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
} | |||||
} |
<?xml version="1.0" encoding="UTF-8" ?> | |||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | |||||
<Properties> | |||||
<Property name="defaultCloseOperation" type="int" value="3"/> | |||||
</Properties> | |||||
<SyntheticProperties> | |||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | |||||
<SyntheticProperty name="generateCenter" type="boolean" value="true"/> | |||||
</SyntheticProperties> | |||||
<AuxValues> | |||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> | |||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> | |||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> | |||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> | |||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> | |||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> | |||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | |||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | |||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | |||||
</AuxValues> | |||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> | |||||
<SubComponents> | |||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1"> | |||||
<AuxValues> | |||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> | |||||
</AuxValues> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||||
<BorderConstraints direction="Center"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> | |||||
<SubComponents> | |||||
<Component class="javax.swing.JTextArea" name="txtArea"> | |||||
<Properties> | |||||
<Property name="columns" type="int" value="20"/> | |||||
<Property name="rows" type="int" value="5"/> | |||||
</Properties> | |||||
</Component> | |||||
</SubComponents> | |||||
</Container> | |||||
<Component class="javax.swing.JTextField" name="textField"> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||||
<BorderConstraints direction="First"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Container class="javax.swing.JPanel" name="jPanel1"> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||||
<BorderConstraints direction="Last"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/> | |||||
<SubComponents> | |||||
<Component class="javax.swing.JButton" name="btn1"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="btn1"/> | |||||
</Properties> | |||||
</Component> | |||||
<Component class="javax.swing.JButton" name="btn2"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="btn2"/> | |||||
</Properties> | |||||
</Component> | |||||
</SubComponents> | |||||
</Container> | |||||
</SubComponents> | |||||
</Form> |
/* | |||||
* To change this license header, choose License Headers in Project Properties. | |||||
* To change this template file, choose Tools | Templates | |||||
* and open the template in the editor. | |||||
*/ | |||||
package gui; | |||||
/** | |||||
* | |||||
* @author Normal | |||||
*/ | |||||
public class Hauptfenster extends javax.swing.JFrame | |||||
{ | |||||
/** | |||||
* @return the btn1 | |||||
*/ | |||||
public javax.swing.JButton getBtn1() | |||||
{ | |||||
return btn1; | |||||
} | |||||
/** | |||||
* @return the btn2 | |||||
*/ | |||||
public javax.swing.JButton getBtn2() | |||||
{ | |||||
return btn2; | |||||
} | |||||
/** | |||||
* @return the textField | |||||
*/ | |||||
public javax.swing.JTextField getTextField() | |||||
{ | |||||
return textField; | |||||
} | |||||
/** | |||||
* @param textField the textField to set | |||||
*/ | |||||
public void setTextField(javax.swing.JTextField textField) | |||||
{ | |||||
this.textField = textField; | |||||
} | |||||
/** | |||||
* @return the txtArea | |||||
*/ | |||||
public javax.swing.JTextArea getTxtArea() | |||||
{ | |||||
return txtArea; | |||||
} | |||||
/** | |||||
* @param txtArea the txtArea to set | |||||
*/ | |||||
public void setTxtArea(javax.swing.JTextArea txtArea) | |||||
{ | |||||
this.txtArea = txtArea; | |||||
} | |||||
/** | |||||
* Creates new form Hauptfenster | |||||
*/ | |||||
public Hauptfenster() | |||||
{ | |||||
initComponents(); | |||||
} | |||||
/** | |||||
* This method is called from within the constructor to initialize the form. | |||||
* WARNING: Do NOT modify this code. The content of this method is always | |||||
* regenerated by the Form Editor. | |||||
*/ | |||||
@SuppressWarnings("unchecked") | |||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents | |||||
private void initComponents() | |||||
{ | |||||
jScrollPane1 = new javax.swing.JScrollPane(); | |||||
txtArea = new javax.swing.JTextArea(); | |||||
textField = new javax.swing.JTextField(); | |||||
jPanel1 = new javax.swing.JPanel(); | |||||
btn1 = new javax.swing.JButton(); | |||||
btn2 = new javax.swing.JButton(); | |||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |||||
txtArea.setColumns(20); | |||||
txtArea.setRows(5); | |||||
jScrollPane1.setViewportView(txtArea); | |||||
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); | |||||
getContentPane().add(textField, java.awt.BorderLayout.PAGE_START); | |||||
btn1.setText("btn1"); | |||||
jPanel1.add(btn1); | |||||
btn2.setText("btn2"); | |||||
jPanel1.add(btn2); | |||||
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END); | |||||
pack(); | |||||
setLocationRelativeTo(null); | |||||
}// </editor-fold>//GEN-END:initComponents | |||||
/** | |||||
* @param args the command line arguments | |||||
*/ | |||||
public static void main(String args[]) | |||||
{ | |||||
/* Set the Nimbus look and feel */ | |||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |||||
*/ | |||||
try | |||||
{ | |||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) | |||||
{ | |||||
if ("Nimbus".equals(info.getName())) | |||||
{ | |||||
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
catch (ClassNotFoundException ex) | |||||
{ | |||||
java.util.logging.Logger.getLogger(Hauptfenster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | |||||
catch (InstantiationException ex) | |||||
{ | |||||
java.util.logging.Logger.getLogger(Hauptfenster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | |||||
catch (IllegalAccessException ex) | |||||
{ | |||||
java.util.logging.Logger.getLogger(Hauptfenster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | |||||
catch (javax.swing.UnsupportedLookAndFeelException ex) | |||||
{ | |||||
java.util.logging.Logger.getLogger(Hauptfenster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | |||||
//</editor-fold> | |||||
/* Create and display the form */ | |||||
java.awt.EventQueue.invokeLater(new Runnable() | |||||
{ | |||||
public void run() | |||||
{ | |||||
new Hauptfenster().setVisible(true); | |||||
} | |||||
}); | |||||
} | |||||
// Variables declaration - do not modify//GEN-BEGIN:variables | |||||
private javax.swing.JButton btn1; | |||||
private javax.swing.JButton btn2; | |||||
private javax.swing.JPanel jPanel1; | |||||
private javax.swing.JScrollPane jScrollPane1; | |||||
private javax.swing.JTextField textField; | |||||
private javax.swing.JTextArea txtArea; | |||||
// End of variables declaration//GEN-END:variables | |||||
} |
/* | |||||
* To change this license header, choose License Headers in Project Properties. | |||||
* To change this template file, choose Tools | Templates | |||||
* and open the template in the editor. | |||||
*/ | |||||
package model; | |||||
import gov.nist.javax.sip.DialogTimeoutEvent; | |||||
import gov.nist.javax.sip.SipListenerExt; | |||||
import java.net.InetAddress; | |||||
import java.text.ParseException; | |||||
import java.util.*; | |||||
import java.util.logging.Level; | |||||
import java.util.logging.Logger; | |||||
import javax.sip.DialogTerminatedEvent; | |||||
import javax.sip.IOExceptionEvent; | |||||
import javax.sip.InvalidArgumentException; | |||||
import javax.sip.ListeningPoint; | |||||
import javax.sip.RequestEvent; | |||||
import javax.sip.ResponseEvent; | |||||
import javax.sip.SipException; | |||||
import javax.sip.SipFactory; | |||||
import javax.sip.SipProvider; | |||||
import javax.sip.SipStack; | |||||
import javax.sip.TimeoutEvent; | |||||
import javax.sip.TransactionTerminatedEvent; | |||||
import javax.sip.address.*; | |||||
import javax.sip.header.*; | |||||
import javax.sip.message.*; | |||||
/** | |||||
* | |||||
* @author Normal | |||||
*/ | |||||
public class VoIP implements SipListenerExt | |||||
{ | |||||
SipFactory sipFactory; // Used to access the SIP API. | |||||
SipStack sipStack; // The SIP stack. | |||||
SipProvider sipProvider; // Used to send SIP messages. | |||||
MessageFactory messageFactory; // Used to create SIP message factory. | |||||
HeaderFactory headerFactory; // Used to create SIP headers. | |||||
AddressFactory addressFactory; // Used to create SIP URIs. | |||||
ListeningPoint listeningPoint; // SIP listening IP address/port. | |||||
Properties properties; // Other properties. | |||||
private int counter; | |||||
private int myPort = 5060; | |||||
private String myName = "129"; | |||||
private String protocolTyp = "UDP"; | |||||
private String myIPAddress; | |||||
int tag = (new Random()).nextInt(); | |||||
private int branch = hashCode(); | |||||
Address contactAddress; | |||||
private ContactHeader contactHeader; | |||||
public VoIP() | |||||
{ | |||||
try | |||||
{ | |||||
//wird an sich erstmal nicht gebraucht aber später sinnvoll um in die unteren Daten zu ergänzen | |||||
String abc = InetAddress.getLocalHost().getHostAddress(); | |||||
this.myIPAddress = InetAddress.getLocalHost().getHostAddress(); | |||||
this.sipFactory = SipFactory.getInstance(); | |||||
this.sipFactory.setPathName("gov.nist"); | |||||
this.properties = new Properties(); | |||||
this.properties.setProperty("javax.sip.STACK_NAME", "stack"); | |||||
this.sipStack = this.sipFactory.createSipStack(this.properties); | |||||
this.messageFactory = this.sipFactory.createMessageFactory(); | |||||
this.headerFactory = this.sipFactory.createHeaderFactory(); | |||||
this.addressFactory = this.sipFactory.createAddressFactory(); | |||||
this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.myPort, this.protocolTyp); | |||||
this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint); | |||||
this.sipProvider.addSipListener(this); | |||||
this.contactAddress = this.addressFactory.createAddress("sip:129@" + this.myIPAddress+ ":" + this.myPort); //+ ":" + this.myPort | |||||
this.contactHeader = this.headerFactory.createContactHeader(contactAddress); | |||||
} | |||||
catch (Exception e) | |||||
{ | |||||
System.out.println("Shit"); | |||||
System.exit(-1); | |||||
} | |||||
} | |||||
public int hashCode() | |||||
{ | |||||
int temp = tag*(new Random(100)).nextInt(); | |||||
return temp; | |||||
} | |||||
public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException | |||||
{ | |||||
System.out.println("-----------SendRegister-----------"); | |||||
Address addressto = this.addressFactory.createAddress("sip:192.168.100.11"); //evtl. mit Port: sip:192.168.100.11:5060 | |||||
Address addresstob = this.addressFactory.createAddress("sip:192.168.100.11"); //to get example maybe needed | |||||
ToHeader to = this.headerFactory.createToHeader(addresstob, null); // Integer.toString(tag) address + tag | |||||
URI requestURI = addressto.getURI(); | |||||
CallIdHeader callId = this.sipProvider.getNewCallId(); | |||||
FromHeader from = this.headerFactory.createFromHeader(addresstob, String.valueOf(this.tag)); //this.contactAddress | |||||
ArrayList via = new ArrayList(); //Via needs a List as input | |||||
ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch)); | |||||
via.add(viaheader); | |||||
CSeqHeader cSeq = this.headerFactory.createCSeqHeader(1L, "REGISTER"); | |||||
MaxForwardsHeader maxForwards = this.headerFactory.createMaxForwardsHeader(70); | |||||
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); | |||||
ExpiresHeader expire = this.headerFactory.createExpiresHeader(3600); //int value | |||||
//Create Request Header | |||||
System.out.println("----REQUEST HEADER----"); | |||||
Request request = this.messageFactory.createRequest(requestURI, "REGISTER", callId, cSeq, from, to, via, maxForwards); | |||||
request.addHeader(contactHeader); | |||||
request.addHeader(allow); | |||||
request.addHeader(expire); | |||||
System.out.println(request); | |||||
this.sipProvider.sendRequest(request); | |||||
} | |||||
@Override | |||||
public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) | |||||
{ | |||||
} | |||||
@Override | |||||
public void processRequest(RequestEvent requestEvent) | |||||
{ | |||||
System.out.println("RequestEvent " + requestEvent.getServerTransaction().getDialog()); | |||||
} | |||||
@Override | |||||
public void processResponse(ResponseEvent responseEvent) | |||||
{ | |||||
System.out.println("---Response---"); | |||||
System.out.println(responseEvent.getResponse()); | |||||
if (responseEvent.getResponse().getStatusCode() == Response.UNAUTHORIZED && counter ==0) | |||||
{ | |||||
counter++; | |||||
try { | |||||
Address addresstob = this.addressFactory.createAddress("sip:129@192.168.100.11"); //"sip:Jan@192.168.100.11" | |||||
ToHeader temp = (ToHeader)responseEvent.getResponse().getHeader("To"); | |||||
ToHeader to = this.headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(tag) address + tag | |||||
URI requestURI = addresstob.getURI(); | |||||
//CallIdHeader tempcall = (CallIdHeader)responseEvent.getResponse().getHeader("Call-ID"); | |||||
CallIdHeader callId = (CallIdHeader)responseEvent.getResponse().getHeader("Call-ID"); | |||||
FromHeader from = this.headerFactory.createFromHeader(addresstob, String.valueOf(this.tag)); //this.contactAddress | |||||
//set Authorization header evtl. user Name benutzen den es gibt | |||||
WWWAuthenticateHeader abc = (WWWAuthenticateHeader)responseEvent.getResponse().getHeader("WWW-Authenticate"); | |||||
AuthorizationHeader auth = this.headerFactory.createAuthorizationHeader("Digest");//was kommt in den string | |||||
auth.setRealm(abc.getRealm()); | |||||
auth.setNonce(abc.getNonce()); | |||||
Address addresstest = this.addressFactory.createAddress("sip:"+myName+"@192.168.100.11"); //vielleicht passwort setzen "sip:"+myName+":\"\"@192.168.100.11" | |||||
auth.setURI(addresstest.getURI()); | |||||
//System.out.println("Test"); | |||||
//auth.setQop(abc.getQop()); | |||||
System.out.println("Test"); | |||||
//auth.setOpaque(abc.getOpaque()); | |||||
auth.setUsername(myName); | |||||
System.out.println("-----auth------"); | |||||
System.out.println(auth); | |||||
ArrayList via = new ArrayList(); //Via needs a List as input | |||||
ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch+2));// String.valueOf(hashCode())string branch | |||||
via.add(viaheader); | |||||
CSeqHeader cSeq = this.headerFactory.createCSeqHeader(2L, "REGISTER"); | |||||
MaxForwardsHeader maxForwards = this.headerFactory.createMaxForwardsHeader(70); | |||||
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); | |||||
ExpiresHeader expire = this.headerFactory.createExpiresHeader(3600); //int value | |||||
//Zusätzliche Register Header nach Unauthorzied | |||||
//Create Request Header | |||||
System.out.println("----REQUEST HEADER2----"); | |||||
Request request = this.messageFactory.createRequest(requestURI, "REGISTER", callId, cSeq, from, to, via, maxForwards); | |||||
request.addHeader(contactHeader); | |||||
request.addHeader(allow); | |||||
request.addHeader(expire); | |||||
request.addHeader(auth); | |||||
System.out.println(request); | |||||
this.sipProvider.sendRequest(request); | |||||
} | |||||
catch (ParseException | SipException |InvalidArgumentException ex) { | |||||
Logger.getLogger(VoIP.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
} | |||||
else if (responseEvent.getResponse().getStatusCode() == Response.OK) | |||||
{ | |||||
System.out.println("responseEvent.getResponse()" + responseEvent.getResponse()); | |||||
} | |||||
} | |||||
@Override | |||||
public void processTimeout(TimeoutEvent timeoutEvent) | |||||
{ | |||||
} | |||||
@Override | |||||
public void processIOException(IOExceptionEvent exceptionEvent) | |||||
{ | |||||
} | |||||
@Override | |||||
public void processTransactionTerminated( | |||||
TransactionTerminatedEvent transactionTerminatedEvent) | |||||
{ | |||||
} | |||||
@Override | |||||
public void processDialogTerminated( | |||||
DialogTerminatedEvent dialogTerminatedEvent) | |||||
{ | |||||
} | |||||
} |
/* | |||||
* To change this license header, choose License Headers in Project Properties. | |||||
* To change this template file, choose Tools | Templates | |||||
* and open the template in the editor. | |||||
*/ | |||||
package phone; | |||||
import controller.CommandController; | |||||
import gui.Hauptfenster; | |||||
import java.text.ParseException; | |||||
import model.VoIP; | |||||
/** | |||||
* Builder Class | |||||
* @author Normal | |||||
*/ | |||||
public class Start | |||||
{ | |||||
public Start() throws ParseException | |||||
{ | |||||
Hauptfenster view = new Hauptfenster(); | |||||
VoIP model = new VoIP(); | |||||
CommandController controller = new CommandController(model, view); | |||||
controller.registerEvents(); | |||||
//view.setExtendedState(Frame.MAXIMIZED_BOTH); | |||||
view.setTitle("TestOberfläche VoIP Phone"); | |||||
view.setVisible(true); | |||||
} | |||||
/** | |||||
* @param args the command line arguments | |||||
*/ | |||||
public static void main(String[] args) throws ParseException | |||||
{ | |||||
new Start(); | |||||
} | |||||
} |