Im trying to create Server to connect to Firebase XMPP endpoint to receive upstream messages. Im using Java Openfire Smack library. When i try to connect to the endpoint i receive error provided down below.
I have tried to find some examples of how to connect to the Firebase XMPP endpoint, but they were outdated.
MY CONNECTION BUILDER
private static final String fcmServer = "fcm-xmpp.googleapis.com";
private static final int fcmPort = 5236;
private static final String fcmSenderId = "[email protected]";
private static final String fcmApiKey = "XYZ";
private XMPPTCPConnectionConfiguration configuration;
private XMPPTCPConnection connection;
public XmppClientModule() {
try {
configuration = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(fcmSenderId, fcmApiKey)
.setXmppDomain("PROJECT_ID.fcm-xmpp.googleapis.com")
.setHost(fcmServer)
.setPort(fcmPort)
.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible)
.build();
}catch (Exception e){
System.out.println("Error handling");
}
connection = new XMPPTCPConnection(configuration);
}
public void run() {
try {
connection.connect();
connection.login();
System.out.println("Connected successfully");
} catch (SmackException | IOException | XMPPException | InterruptedException e) {
e.printStackTrace();
}
}
ERROR
org.jivesoftware.smack.SmackException$SmackWrappedException: org.jivesoftware.smack.xml.XmlPullParserException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
at org.jivesoftware.smack.AbstractXMPPConnection.setCurrentConnectionExceptionAndNotify(AbstractXMPPConnection.java:687)
at org.jivesoftware.smack.AbstractXMPPConnection.notifyConnectionError(AbstractXMPPConnection.java:987)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$4100(XMPPTCPConnection.java:131)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1167)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$700(XMPPTCPConnection.java:916)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:939)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.jivesoftware.smack.xml.XmlPullParserException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Caused by: org.jivesoftware.smack.xml.XmlPullParserException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
at org.jivesoftware.smack.xml.stax.StaxXmlPullParser.next(StaxXmlPullParser.java:193)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1143)
... 3 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652)
at org.jivesoftware.smack.xml.stax.StaxXmlPullParser.next(StaxXmlPullParser.java:191)
... 4 more
Dependencies
I also tried to use
implementation 'org.igniterealtime.smack:smack-xmlparser-xpp3:4.4.6'
but i received same error differently paraphrased
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
implementation 'org.igniterealtime.smack:smack-core:4.4.6'
implementation 'org.igniterealtime.smack:smack-tcp:4.4.6'
implementation 'org.igniterealtime.smack:smack-extensions:4.4.6'
implementation 'org.igniterealtime.smack:smack-xmlparser-stax:4.4.6'
implementation 'org.igniterealtime.smack:smack-resolver-dnsjava:4.4.6'
}