Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8235191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:43:21+00:00 2026-06-07T18:43:21+00:00

I have a Java web server which I want to send UA push notifications

  • 0

I have a Java web server which I want to send UA push notifications through. I know this is possible through UA’s dashboard, but I want to communicate with UA using the web-server directly.

I have already read this documentation, and have reviewed this SO question, but am still at a bit of a loss for where to start.

Can anyone please help point me toward a good starting point? Do I need to import any specific .jar files, etc?

I have been trying to adapt the following code snippet, but it doesn’t seem to function properly. What am I doing wrong?

URL mURL=new URL("https://go.urbanairship.com/api/push/broadcast");
HttpsURLConnection connection = (HttpsURLConnection)mURL.openConnection();
connection.setRequestMethod("POST");
JSONObject mPayload=new JSONObject();
JSONObject mPayload1=new JSONObject();
JSONObject mPayload2=new JSONObject();
mPayload1.put("extra", mPayload2);
mPayload1.put("alert", "hello world");
mPayload2.put("phonenumber", "12345");
mPayload.put("android", mPayload1);
System.out.println(mPayload.toString());
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.addRequestProperty("Content-Type","application/json;charset=UTF-8");
String authString = "**MY APP KEY**" + ":" + "**MASTER KEY**"; 

String authStringBase64 = new String(Base64.encodeBytes(authString.getBytes()));
authStringBase64 = authStringBase64.trim();

connection.addRequestProperty("Authorization", "Basic " + authStringBase64);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.write(mPayload.toString().getBytes());
wr.flush();
Log.d("print", "response code"+ connection.getResponseCode());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:43:24+00:00Added an answer on June 7, 2026 at 6:43 pm

    You just need to send a POST request to the urbanairship server with your notification, including your AppId and Secret key encoded appropriately…

    It looks like the link you included above is to a library which will do most of this for you.

    Sample code, note: the PushNotificationObj in this example is a bean with the fields for the body of the push..

            URL url = new URL(URBAN_AIRSHIP_API_URL);
            HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
    
            String authString = ApplicationProperties.getUrbanAirshipAppId() + ":" + ApplicationProperties.getUrbanAirshipMasterSecret();
    
            String authStringBase64 = new String(Base64.encodeBase64(authString.getBytes()));
            authStringBase64 = authStringBase64.trim();
    
            req.addHeader(new HTTPHeader("Content-Type", "application/json"));
            req.addHeader(new HTTPHeader("Authorization", "Basic " + authStringBase64));
    
            ObjectMapper mapper = new ObjectMapper();
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
            mapper.writeValue(byteStream, new PushNotificationObj(userEmail, message));
    
            req.setPayload(byteStream.toByteArray());
    

    And then send the request…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java web-service which currently runs on a local tomcat server. I
I have a Java Web Start Application which communicates against my server via a
I have an existing and working java web application. I want to make this
I have a Java based web-application using Java Server Faces and Facelets. I am
We have a Java EE-based web application running on a Glassfish app server cluster.
I have a Java Web-Start-based application, which utilizes several native ".exe" utilities. All jars
I have a java web application which I can debug using IntelliJ or Eclipse
I have java web application to which I'd like to add emailing capabilities, however,
I have setup google checkout for my java web application and I want to
I have server A (Windows, C#.NET), which needs to send an alert/signal to server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.