gpt4 book ai didi

java - 出现错误 javax.sip.PeerUnavailableException : The Peer SIP Stack: gov. nist.javax.sip.SipStackImpl 无法实例化

转载 作者:行者123 更新时间:2023-12-01 11:22:30 28 4
gpt4 key购买 nike

我在使用以下代码时遇到错误。

我已经包含了 Sip 所需的所有 jar ;但是,我仍然不明白为什么会发生这个错误。你能给我解释一下吗?

我的代码类是:

import java.net.InetAddress;

import java.util.ArrayList;

import java.util.Properties;

import java.util.Random;


import javax.sip.DialogTerminatedEvent;
import javax.sip.IOExceptionEvent;
import javax.sip.ListeningPoint;
import javax.sip.RequestEvent;
import javax.sip.ResponseEvent;
import javax.sip.SipFactory;
import javax.sip.SipListener;
import javax.sip.SipProvider;
import javax.sip.SipStack;
import javax.sip.TimeoutEvent;
import javax.sip.TransactionTerminatedEvent;
import javax.sip.address.Address;
import javax.sip.address.AddressFactory;
import javax.sip.header.CSeqHeader;
import javax.sip.header.CallIdHeader;
import javax.sip.header.ContactHeader;
import javax.sip.header.FromHeader;
import javax.sip.header.HeaderFactory;
import javax.sip.header.MaxForwardsHeader;
import javax.sip.header.ToHeader;
import javax.sip.header.ViaHeader;
import javax.sip.message.MessageFactory;
import javax.sip.message.Request;
import javax.swing.JFrame;

public class SipClient extends JFrame implements SipListener
{
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.

String ip; // The local IP address.
int port = 6060; // The local port.
String protocol = "udp"; // The local protocol (UDP).
int tag = (new Random()).nextInt(); // The local tag.
Address contactAddress; // The contact address.
ContactHeader contactHeader; // The contact header.
public SipClient()
{
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.
*/

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN- BEGIN:initComponents
private void initComponents() {

scrollPane = new javax.swing.JScrollPane();
textArea = new javax.swing.JTextArea();
buttonRegisterStateless = new javax.swing.JButton();
buttonRegisterStatefull = new javax.swing.JButton();
buttonInvite = new javax.swing.JButton();
buttonBye = new javax.swing.JButton();
textField = new javax.swing.JTextField();
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("SIP Client");
setLocationByPlatform(true);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
onOpen(evt);
}
});

textArea.setEditable(false);
textArea.setColumns(20);
textArea.setRows(5);
scrollPane.setViewportView(textArea);

buttonRegisterStateless.setText("Reg (SL)");
buttonRegisterStateless.setEnabled(true);
buttonRegisterStateless.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onRegisterStateless(evt);
}
});

buttonRegisterStatefull.setText("Reg (SF)");
buttonRegisterStatefull.setEnabled(true);
buttonRegisterStatefull.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onRegisterStatefull(evt);
}
});

buttonInvite.setText("Invite");
buttonInvite.setEnabled(true);
buttonInvite.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onInvite(evt);
}
});

buttonBye.setText("Bye");
buttonBye.setEnabled(true);
buttonBye.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onBye(evt);
}
});

textField.setText("");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G)
.addComponent(scrollPane)
.addGroup(layout.createSequentialGroup()
.addComponent(buttonRegisterStateless, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonRegisterStatefull, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonInvite, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonBye, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 2, Short.MAX_VALUE))
.addComponent(textField))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(textField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonRegisterStateless)
.addComponent(buttonInvite)
.addComponent(buttonBye)
.addComponent(buttonRegisterStatefull))
.addContainerGap())
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void onOpen(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_onOpen
try
{
this.ip=InetAddress.getLocalHost().getHostAddress();
System.out.println(ip);
this.sipFactory=SipFactory.getInstance();
this.sipFactory.setPathName("gov.nist");
this.properties=new Properties();
this.properties.setProperty("javax.sip.STACK_NAME", "myStack");
// Create the SIP stack.
this.sipStack = this.sipFactory.createSipStack(this.properties);
// Create the SIP message factory.
this.messageFactory = this.sipFactory.createMessageFactory();
// Create the SIP header factory.
this.headerFactory = this.sipFactory.createHeaderFactory();
// Create the SIP address factory.
this.addressFactory = this.sipFactory.createAddressFactory();
// Create the SIP listening point and bind it to the local IP address, port and protocol.
this.listeningPoint = this.sipStack.createListeningPoint(this.ip, this.port, this.protocol);
// Create the SIP provider.
this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint);
// Add our application as a SIP listener.
this.sipProvider.addSipListener(this);
// Create the contact address used for all SIP messages.
System.out.println("Local address: " + this.ip +" : "+ this.port + "\n");
this.contactAddress = this.addressFactory.createAddress("sip: "+ this.ip +" : "+ this.port);
// Create the contact header used for all SIP messages.
this.contactHeader = this.headerFactory.createContactHeader(contactAddress);

// Display the local IP address and port in the text area.
System.out.println("Local address: " + this.ip +" : "+ this.port + "\n");
}
catch(Exception e)
{
e.printStackTrace();
}
}//GEN-LAST:event_onOpen

private void onRegisterStateless(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onRegisterStateless
try {
// Get the destination address from the text field.
Address addressTo = addressFactory.createAddress(textField.getText());
// Create the request URI for the SIP message.
javax.sip.address.URI requestURI = addressTo.getURI();
// Create the SIP message headers.
// The "Via" headers.
ArrayList viaHeaders = new ArrayList();
ViaHeader viaHeader = headerFactory.createViaHeader(ip, port, "udp", null);
viaHeaders.add(viaHeader);
// The "Max-Forwards" header.
MaxForwardsHeader maxForwardsHeader = headerFactory.createMaxForwardsHeader(70);
// The "Call-Id" header.
CallIdHeader callIdHeader = sipProvider.getNewCallId();
// The "CSeq" header.
CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L,"REGISTER");
// The "From" header.
FromHeader fromHeader = headerFactory.createFromHeader(contactAddress, String.valueOf(tag));
// The "To" header.
ToHeader toHeader = headerFactory.createToHeader(addressTo, null);

// Create the REGISTER request.
Request request = messageFactory.createRequest(
requestURI,
"REGISTER",
callIdHeader,
cSeqHeader,
fromHeader,
toHeader,
viaHeaders,
maxForwardsHeader);
// Add the "Contact" header to the request.
request.addHeader(contactHeader);

// Send the request statelessly through the SIP provider.
sipProvider.sendRequest(request);

// Display the message in the text area.
textArea.append(
"Request sent:\n" + request.toString() + "\n\n");
}
catch(Exception e) {
// If an error occurred, display the error.
textArea.append("Request sent failed: " + e.getMessage() + "\n");
}
}//GEN-LAST:event_onRegisterStateless

private void onRegisterStatefull(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onRegisterStatefull
// A method called when you click on the "Reg (SF)" button.
}//GEN-LAST:event_onRegisterStatefull

private void onInvite(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onInvite
// A method called when you click on the "Invite" button.
}//GEN-LAST:event_onInvite

private void onBye(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onBye
// A method called when you click on the "Bye" button.
}//GEN-LAST:event_onBye

/**
* @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(SipClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SipClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SipClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SipClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new SipClient().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonBye;
private javax.swing.JButton buttonInvite;
private javax.swing.JButton buttonRegisterStatefull;
private javax.swing.JButton buttonRegisterStateless;
private javax.swing.JScrollPane scrollPane;
private javax.swing.JTextArea textArea;
private javax.swing.JTextField textField;
// End of variables declaration//GEN-END:variables
public void processRequest(RequestEvent requestEvent) {
// A method called when you receive a SIP request.
}

public void processResponse(ResponseEvent responseEvent) {
// A method called when you receive a SIP request.
}

public void processTimeout(TimeoutEvent timeoutEvent) {
// A method called when a SIP operation times out.
}

public void processIOException(IOExceptionEvent exceptionEvent) {
// A method called when a SIP operation results in an I/O error.
}

public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
// A method called when a SIP transaction terminates.
}

public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
// A method called when a SIP dialog terminates.
}
}

我也包含了 org.apache.log4j jar,但我仍然收到以下错误:

javax.sip.PeerUnavailableException: The Peer SIP Stack:   gov.nist.javax.sip.SipStackImpl could not be instantiated. Ensure the Path Name has been set.
at javax.sip.SipFactory.createStack(SipFactory.java:324)
at javax.sip.SipFactory.createSipStack(SipFactory.java:152)
at ServerClasses.sc.SipClient.onOpen(SipClient.java:169)
at ServerClasses.sc.SipClient.access$0(SipClient.java:159)
at ServerClasses.sc.SipClient$1.windowOpened(SipClient.java:77)
at java.awt.Window.processWindowEvent(Unknown Source)
at javax.swing.JFrame.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: gov.nist.javax.sip.SipStackImpl
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.sip.SipFactory.createStack(SipFactory.java:305)
... 29 more

请帮我解决这个问题。我是 SIP 编程新手。

最佳答案

您需要 jain-sip-api 和 jain-sip-ri jar。通过查看错误,您缺少 ri jar。您可以从此处的存档中获取 jar https://jsip.ci.cloudbees.com/job/jsip/lastSuccessfulBuild/artifact/trunk/jain-sip-1.2.2370.tar.gz

关于java - 出现错误 javax.sip.PeerUnavailableException : The Peer SIP Stack: gov. nist.javax.sip.SipStackImpl 无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31073428/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com