Last active
December 16, 2018 19:15
-
-
Save hiranya911/e47d010259228c659cd472edeb0672f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.api.client.http.HttpTransport; | |
import com.google.api.client.http.javanet.NetHttpTransport; | |
import com.google.auth.http.HttpTransportFactory; | |
import com.google.auth.oauth2.GoogleCredentials; | |
import com.google.firebase.FirebaseApp; | |
import com.google.firebase.FirebaseOptions; | |
import com.google.firebase.messaging.FirebaseMessaging; | |
import com.google.firebase.messaging.Message; | |
import com.google.firebase.messaging.Notification; | |
import java.net.InetSocketAddress; | |
import java.net.Proxy; | |
public class Main { | |
public static void main(String[] args) throws Exception { | |
InetSocketAddress address = new InetSocketAddress("localhost", 3128); | |
final HttpTransport transport = new NetHttpTransport.Builder() | |
.setProxy(new Proxy(Proxy.Type.HTTP, address)) | |
.build(); | |
HttpTransportFactory transportFactory = new HttpTransportFactory() { | |
@Override | |
public HttpTransport create() { | |
return transport; | |
} | |
}; | |
FirebaseOptions options = | |
FirebaseOptions.builder() | |
.setCredentials(GoogleCredentials.getApplicationDefault(transportFactory)) | |
.setHttpTransport(transport) | |
.build(); | |
FirebaseApp.initializeApp(options); | |
FirebaseMessaging messaging = FirebaseMessaging.getInstance(); | |
String response = messaging.send(Message.builder() | |
.setTopic("test-topic") | |
.setNotification(new Notification( | |
"Hello from the other side", | |
"I must have called this proxy a thousand times")) | |
.build()); | |
System.out.println(response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment