Skip to content

Instantly share code, notes, and snippets.

@hiranya911
Last active December 16, 2018 19:15
Show Gist options
  • Save hiranya911/e47d010259228c659cd472edeb0672f1 to your computer and use it in GitHub Desktop.
Save hiranya911/e47d010259228c659cd472edeb0672f1 to your computer and use it in GitHub Desktop.
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