I have java-application as wrapper on FFmpeg. I need to capture mp2 multicast stream, convert it to mp3 and send converted multicast stream to another address.
It works well. But now I have two network interfaces. And one of them for internet/local network (eth1). Need to configure second network interface (eth2) to capture and send multicast streams.
But ffmpeg try to capture from first network interface by default. I can see packets in tcpdump, but ffmpeg don't capture it from eth2.
How can I specify interface for stream capturing and interface for stream sending?
This was solved by smcroute utility.
application.properties:
smcroute.config.file = /etc/smcroute.conf
RoutingConfig.java:
public class RoutingConfig {
private final File file;
public RoutingConfig(String filename) {
this.file = new File(filename);
}
public List<RoutingRecord> read() throws IOException {
List<String> lines = Files.readAllLines(file.toPath());
return lines.stream().map(RoutingRecord::new).collect(Collectors.toList());
}
public void write(List<RoutingRecord> records) throws IOException {
List<String> lines = records.stream().map(RoutingRecord::toString).collect(Collectors.toList());
Files.write(file.toPath(), lines);
}
}
RoutingRecord.java:
public class RoutingRecord {
private String sourceInterface;
private String multicastAddress;
private String sourceMulticastAddress;
private List<String> destinationInterfaces;
public RoutingRecord() {
}
public RoutingRecord(String line) {
String[] words = line.split(" ");
this.sourceInterface = words[2];
this.multicastAddress = words[4];
this.sourceMulticastAddress = words[6];
this.destinationInterfaces = new ArrayList<>(Arrays.asList(words).subList(8, words.length));
}
public RoutingRecord(String sourceInterface,
String multicastAddress,
String sourceMulticastAddress,
List<String> destinationInterfaces
) {
this.sourceInterface = sourceInterface;
this.multicastAddress = multicastAddress;
this.sourceMulticastAddress = sourceMulticastAddress;
this.destinationInterfaces = destinationInterfaces;
}
public String getSourceInterface() {return sourceInterface;}
public String getMulticastAddress() {return multicastAddress;}
public String getSourceMulticastAddress() {return sourceMulticastAddress;}
public List<String> getDestinationInterfaces() {return destinationInterfaces;}
public String getDestinationInterfacesLine() {return String.join(", ", destinationInterfaces);}
public RoutingRecord setSourceInterface(String sourceInterface) {
this.sourceInterface = sourceInterface;
return this;
}
public RoutingRecord setMulticastAddress(String multicastAddress) {
this.multicastAddress = multicastAddress;
return this;
}
public RoutingRecord setSourceMulticastAddress(String sourceMulticastAddress) {
this.sourceMulticastAddress = sourceMulticastAddress;
return this;
}
public RoutingRecord setDestinationInterfaces(List<String> destinationInterfaces) {
this.destinationInterfaces = destinationInterfaces;
return this;
}
#Override
public String toString() {
return "mroute from " + sourceInterface + " " +
"group " + multicastAddress + " " +
"source " + sourceMulticastAddress + " " +
"to " + String.join(" ", destinationInterfaces);
}
RoutingServiceImpl.java:
#Service
public class RoutingServiceImpl implements RoutingService {
private final Environment environment;
#Autowired
public RoutingServiceImpl(Environment environment) {
this.environment = environment;
}
#Override
public List<RoutingRecord> getRoutingLines() throws IOException {
String filename = environment.getProperty("smcroute.config.file");
RoutingConfig routingConfig = new RoutingConfig(filename);
return routingConfig.read();
}
#Override
public void saveRoutingLines(List<RoutingRecord> records) throws IOException {
String filename = environment.getProperty("smcroute.config.file");
RoutingConfig routingConfig = new RoutingConfig(filename);
routingConfig.write(records);
}
#Override
public void saveRoutingLine(RoutingRecord routingRecord) throws IOException {
String filename = environment.getProperty("smcroute.config.file");
RoutingConfig routingConfig = new RoutingConfig(filename);
List<RoutingRecord> records = routingConfig.read();
records.add(routingRecord);
routingConfig.write(records);
}
#Override
public void applyRoutes() throws IOException {
Runtime rt = Runtime.getRuntime();
rt.exec(new String[] {
"service",
"smcroute",
"restart"
});
}
}
Related
I am creating a project in which I am using navigation drawer and on navigation item click it opens a login page and after login it movies to my main activity. Now, I want to save my login details and all data in my custom shared preference from the fragment. After that it on app restarts and I go to navigation login items it should check if the user is already logged in then it should move to an activity otherwise it should run my login fragment
my login fragment
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
CDSMainViewModel =
ViewModelProviders.of(this).get(CDP_MainViewModel.class);
View root = inflater.inflate(R.layout.fragment_cdplogin, container, false);
context = container.getContext();
context = getActivity().getApplicationContext();
session = new Session(context);
if (session.isLoggedIn()) {
Intent itra = new Intent(getActivity().getApplicationContext(), Verification_Activity.class);
startActivity(itra);
getActivity().finish();
}
else{
login_button = root.findViewById(R.id.button_click_login);
edit1 = root.findViewById(R.id.input_username);
edit2 = root.findViewById(R.id.input_password);
layout_1 = root.findViewById(R.id.usnamelayout);
layout_2 = root.findViewById(R.id.password_layout);
login_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
return root;
}
private void Login_data() {
String URL = "http://117.240.196.238:8080/api/cdp/getAuth";
Log.i("response", URL);
StringRequest jsonObjRequest = new StringRequest(
Request.Method.POST, URL, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.i("response_login", response);
parseData1(response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("volley", "Error: " + error.getMessage());
showServerConnectionError();
}
}) {
#Override
public String getBodyContentType() {
return "application/x-www-form-urlencoded; charset=UTF-8";
}
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("AuthID", name);
params.put("AuthPwd", password);
return params;
}
};
RequestQueue queue = SingletonRequestQueue.getInstance(getActivity().getApplicationContext()).getRequestQueue();
queue.add(jsonObjRequest);
}
private void parseData1(String response){
try {
JSONObject json = new JSONObject(response);
int success = json.getInt("success");
String msg = json.getString("message");
if(success == 1){
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
JSONArray recData = json.getJSONArray("data");
for (int i = 0; i < recData.length(); i++) {
JSONObject c = recData.getJSONObject(i);
String uname = name;
String upass = password;
String emp_id = c.getString("emp_id");
String empname = c.getString("EmpName");
String office = c.getString("OfficeNameFull");
String desig = c.getString("DesignationName");
String mobile = c.getString("EmpMobile");
String office_code = c.getString("OfficeCode");
String OfficeType = c.getString("OfficeType");
String district = c.getString("DistrictCode");
String DistrictName = c.getString("DistrictName");
String designationCode = c.getString("designationCode");
String DesignationName1 = c.getString("DesignationName1");
String DesigShortName = c.getString("DesigShortName");
Log.i("session",district);
//Here my loginsession is not working its not saving my data in my session..
Session.getInstance(getContext()).loginsession(emp_id,uname,upass,empname,office,desig,mobile,office_code,OfficeType,district,DistrictName,designationCode,DesignationName1,DesigShortName);
// String email = SessionManager.getInstance(context).getUserEmail();
// session.loginsession(emp_id,uname,upass,empname,office,desig,mobile,office_code,OfficeType,district,DistrictName,designationCode,DesignationName1,DesigShortName);
Intent its12 = new Intent(getActivity().getApplicationContext(), Verification_Activity.class);
startActivity(its12);
getActivity().overridePendingTransition(R.anim.from_right, R.anim.slide_to_left);
getActivity().finish();
}
} else {
Toast.makeText(context,msg, Toast.LENGTH_LONG).show();
}
}catch(Exception ex){
}
}
}
//Session manager class
package com.example.agridept.domain;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import com.example.agridept.ui.CDP_login.CDP_MainFragment;
public class Session {
private static Session jInstance;
SharedPreferences preferences;
SharedPreferences.Editor editor;
Context context;
int PRIVATE_MODE = 0;
private static final String IS_LOGIN = "IsLoggedIn";
private static final String PREF_NAME = "AndroidHivePref";
String emp_id1,username1,password1 ,empname1 , office1 , desig1, mobile1, office_code1, OfficeType1 , district1 ,DistrictName1 , designationCode1, DesignationName11 , DesigShortName1;
public Session(Context context){
this.context = context;
preferences = context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = preferences.edit();
}
public void loginsession(String emp_id,String username,String password11 ,String empname ,String office ,String desig,String mobile,String office_code,String OfficeType ,String district ,String DistrictName ,String designationCode,String DesignationName1 ,String DesigShortName){
editor.putBoolean(IS_LOGIN, true);
editor.putString(emp_id1,emp_id);
editor.putString(username1,username);
editor.putString(password1,password11);
editor.putString(empname1,empname);
editor.putString(office1,office);
editor.putString(desig1,desig);
editor.putString(mobile1,mobile);
editor.putString(office_code1,office_code);
editor.putString(OfficeType1,OfficeType);
editor.putString(district1,district);
editor.putString(DistrictName1,DistrictName);
editor.putString(designationCode1,designationCode);
editor.putString(DesignationName11,DesignationName1);
editor.putString(DesigShortName1,DesigShortName);
}
public boolean isLoggedIn() {
return preferences.getBoolean(IS_LOGIN, false);
}
public void logoutUser() {
// Clearing all data from Shared Preferences
editor.clear();
editor.commit();
// After logout redirect user to Loing Activity
Intent i = new Intent(context, CDP_MainFragment.class);
// Closing all the Activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add new Flag to start new Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Staring Login Activity
context.startActivity(i);
}
public void clearinfo() {
// Clearing all data from Shared Preferences
editor.clear();
editor.commit();
}
public SharedPreferences getPreferences() {
return preferences;
}
public void setPreferences(SharedPreferences preferences) {
this.preferences = preferences;
}
public SharedPreferences.Editor getEditor() {
return editor;
}
public void setEditor(SharedPreferences.Editor editor) {
this.editor = editor;
}
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
public int getPRIVATE_MODE() {
return PRIVATE_MODE;
}
public void setPRIVATE_MODE(int PRIVATE_MODE) {
this.PRIVATE_MODE = PRIVATE_MODE;
}
public static String getIsLogin() {
return IS_LOGIN;
}
public static String getPrefName() {
return PREF_NAME;
}
public String getEmp_id1() {
return emp_id1;
}
public void setEmp_id1(String emp_id1) {
this.emp_id1 = emp_id1;
}
public String getPassword1() {
return password1;
}
public void setPassword1(String password1) {
this.password1 = password1;
}
public String getEmpname1() {
return empname1;
}
public void setEmpname1(String empname1) {
this.empname1 = empname1;
}
public String getOffice1() {
return office1;
}
public void setOffice1(String office1) {
this.office1 = office1;
}
public String getDesig1() {
return desig1;
}
public void setDesig1(String desig1) {
this.desig1 = desig1;
}
public String getMobile1() {
return mobile1;
}
public void setMobile1(String mobile1) {
this.mobile1 = mobile1;
}
public String getOffice_code1() {
return office_code1;
}
public void setOffice_code1(String office_code1) {
this.office_code1 = office_code1;
}
public String getOfficeType1() {
return OfficeType1;
}
public void setOfficeType1(String officeType1) {
OfficeType1 = officeType1;
}
public String getDistrict1() {
return district1;
}
public void setDistrict1(String district1) {
this.district1 = district1;
}
public String getDistrictName1() {
return DistrictName1;
}
public void setDistrictName1(String districtName1) {
DistrictName1 = districtName1;
}
public String getDesignationCode1() {
return designationCode1;
}
public void setDesignationCode1(String designationCode1) {
this.designationCode1 = designationCode1;
}
public String getDesignationName11() {
return DesignationName11;
}
public void setDesignationName11(String designationName11) {
DesignationName11 = designationName11;
}
public String getDesigShortName1() {
return DesigShortName1;
}
public void setDesigShortName1(String desigShortName1) {
DesigShortName1 = desigShortName1;
}
public static synchronized Session getInstance(Context context) {
if (jInstance != null) {
return jInstance;
} else {
jInstance = new Session(context);
return jInstance;
}
}
}
I read many articles but still my problem is continuing, while fetching data from firebase as list. could you please help me on this.
Error: com.google.firebase.database.DatabaseException: Can't convert
object of type java.lang.String to type SubCategoryLoad Object
Firebase database image
--> Loading data from firebase:
mSubCategoryDatabaseRef = FirebaseDatabase.getInstance().getReference("user_post_add_database_ref").child("yeswanth599").child(mCategoryNameReceive);
mSubCategoryDatabaseRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
GenericTypeIndicator<Map<String,SubCategoryLoad>> genericTypeIndicator=new GenericTypeIndicator<Map<String,SubCategoryLoad>>(){};
(-->Error Showing in this Line) Map<String,SubCategoryLoad> map=(Map<String, SubCategoryLoad>)postSnapshot.getValue(genericTypeIndicator);
assert map != null;
mSubCategoryLoad=new ArrayList<>(map.values());
}
mSubCategoryAdapter = new SubCategoryDisplayAdapter(getContext(), mSubCategoryLoad);
mSubCategoryRecyclerView.setAdapter(mSubCategoryAdapter);
mSubCategoryProgressCircle.setVisibility(View.INVISIBLE);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(getContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
mSubCategoryProgressCircle.setVisibility(View.INVISIBLE);
}
});
--> SubCategoryLoad.Class
public class SubCategoryLoad {
private String mUserPostAddress;
private String mUserPostBusinessEndTime;
private String mUserPostBusinessSelectedCity;
private String mUserPostBusinessSelectedCountry;
private String mUserPostBusinessStartTime;
private String mUserPostCategory;
private String mUserPostEmail;
private List<UserPostAdsImages> mUserPostImages;
private String mUserPostName;
private String mUserPostPhonenumber;
private List<UserPostAdsLanguages> mUserPostSupportingLanguage;
private String mUserPostWebsite;
public SubCategoryLoad() {
//empty constructor needed
}
public SubCategoryLoad(String userPostAddress, String userPostBusinessEndTime,
String userPostBusinessSelectedCity, String userPostBusinessSelectedCountry,
String userPostBusinessStartTime, String userPostCategory,
String userPostEmail, List<UserPostAdsImages> userPostImages,
String userPostName, String userPostPhonenumber,
List<UserPostAdsLanguages> userPostSupportingLanguage, String userPostWebsite
) {
mUserPostAddress = userPostAddress;
mUserPostBusinessEndTime = userPostBusinessEndTime;
mUserPostBusinessSelectedCity = userPostBusinessSelectedCity;
mUserPostBusinessSelectedCountry = userPostBusinessSelectedCountry;
mUserPostBusinessStartTime = userPostBusinessStartTime;
mUserPostCategory = userPostCategory;
mUserPostEmail = userPostEmail;
mUserPostImages = userPostImages;
mUserPostName = userPostName;
mUserPostPhonenumber = userPostPhonenumber;
mUserPostSupportingLanguage = userPostSupportingLanguage;
mUserPostWebsite = userPostWebsite;
}
public void setUserPostAddress(String userPostAddress) {
this.mUserPostAddress = userPostAddress;
}
public void setUserPostBusinessEndTime(String userPostBusinessEndTime) {
this.mUserPostBusinessEndTime = userPostBusinessEndTime;
}
public void setUserPostBusinessSelectedCity(String userPostBusinessSelectedCity) {
this.mUserPostBusinessSelectedCity = userPostBusinessSelectedCity;
}
public void setUserPostBusinessSelectedCountry(String userPostBusinessSelectedCountry) {
this.mUserPostBusinessSelectedCountry = userPostBusinessSelectedCountry;
}
public void setUserPostBusinessStartTime(String userPostBusinessStartTime) {
this.mUserPostBusinessStartTime = userPostBusinessStartTime;
}
public void setUserPostCategory(String userPostCategory) {
this.mUserPostCategory = userPostCategory;
}
public void setUserPostEmail(String userPostEmail) {
this.mUserPostEmail = userPostEmail;
}
public void setUserPostImages(List<UserPostAdsImages> userPostImages) {
this.mUserPostImages = userPostImages;
}
public void setUserPostName(String userPostName) {
this.mUserPostName = userPostName;
}
public void setUserPostPhonenumber(String userPostPhonenumber) {
this.mUserPostPhonenumber = userPostPhonenumber;
}
public void setUserPostSupportingLanguage(List<UserPostAdsLanguages> userPostSupportingLanguage) {
this.mUserPostSupportingLanguage = userPostSupportingLanguage;
}
public void setUserPostWebsite(String userPostWebsite) {
this.mUserPostWebsite = userPostWebsite;
}
public String getUserPostAddress() {
return mUserPostAddress;
}
public String getUserPostBusinessEndTime() {
return mUserPostBusinessEndTime;
}
public String getUserPostBusinessSelectedCity() {
return mUserPostBusinessSelectedCity;
}
public String getUserPostBusinessSelectedCountry() {
return mUserPostBusinessSelectedCountry;
}
public String getUserPostBusinessStartTime() {
return mUserPostBusinessStartTime;
}
public String getUserPostCategory() {
return mUserPostCategory;
}
public String getUserPostEmail() {
return mUserPostEmail;
}
public List<UserPostAdsImages> getUserPostImages() {
return mUserPostImages;
}
public String getUserPostName() {
return mUserPostName;
}
public String getUserPostPhonenumber() {
return mUserPostPhonenumber;
}
public List<UserPostAdsLanguages> getUserPostSupportingLanguage() {
return mUserPostSupportingLanguage;
}
public String getUserPostWebsite() {
return mUserPostWebsite;
}
}
--> SubCategoryDisplayAdapter.class
SubCategoryLoad subCategoryLoadCurrent = mSubCategoryLoad.get(position);
holder.mSubCategoryAdsTitle.setText(subCategoryLoadCurrent.getUserPostName());
holder.mSubCategoryAdsSupportingLanguagesList.setText("English,Japanese");
//Log.i(TAG, "message:"+subCategoryLoadCurrent.getUserPostImages().get(0).getUserPostImageList());
Glide.with(mContext)
.load(subCategoryLoadCurrent.getUserPostImages().get(0).getUserPostImageList())
.into(holder.mSubCategoryAdsImage);
Thanks & Regards,
Yeswanth.
I used to have the same issue with my parsing and the problem was instead of a list of custom objects i was supposed to be using a Map like this
private Map<String,Boolean>
That field in Firebase contains a key and a state (True or False).
Also you can check the code on the docs to see how they parse these objects.
https://firebase.google.com/docs/database/android/read-and-write?authuser=0#read_data_once
I was trying to implement Amazon SNS service to my project. I am able to create a topic and subscribe to a topic as well. Here, I am using sms as a protocol and phone number as endpoint. The main problem is I am not getting any confirmation to my mobile phone number and unable to publish message. How can I get a token to confirmSubscription? //subscriptionRequest.withToken(token);
public class SNSServiceImpl implements SNSService {
private static final Logger logger = LoggerFactory.getLogger(SNSServiceImpl.class);
#Value("${AWS_ACCESS_KEY_ID:key}")
private String awsAccessKeyId;
#Value("${AWS_SECRET_ACCESS_KEY:secret}")
private String awsAccessKeySecret;
#Value("${AWS_REGION:us-west-2}")
private String awsRegion;
private AmazonSNS snsClient;
private String subscriptionArn;
#PostConstruct
public void setConnection() {
AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKeyId, awsAccessKeySecret);
AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
snsClient = AmazonSNSClient.builder()
.withRegion(awsRegion)
.withCredentials(awsCredentialsProvider)
.build();
}
#Override
public String createTopic(String topicName) {
CreateTopicRequest topicRequest = new CreateTopicRequest(topicName);
CreateTopicResult topicResult = snsClient.createTopic(topicRequest);
return topicResult.getTopicArn();
}
#Override
public void subscribeToTopic(String topicArn) {
SubscribeRequest subscribeRequest = new SubscribeRequest();
subscribeRequest.setTopicArn(topicArn);
subscribeRequest.setProtocol("sms");
subscribeRequest.setEndpoint("+14699011920");
SubscribeResult subscribeResult = snsClient.subscribe(subscribeRequest);
subscriptionArn = subscribeResult.getSubscriptionArn();
}
#Override
public void confirmSubscription(String topicArn) {
ConfirmSubscriptionRequest subscriptionRequest = new ConfirmSubscriptionRequest();
subscriptionRequest.withTopicArn(topicArn);
//subscriptionRequest.withToken(token);
ConfirmSubscriptionResult confirmSubscriptionResult = snsClient.confirmSubscription(subscriptionRequest);
confirmSubscriptionResult.withSubscriptionArn(subscriptionArn);
}
#Override
public void publishMessage(String topicArn, String message) {
PublishRequest publishRequest = new PublishRequest(topicArn, message);
PublishResult publishResult = snsClient.publish(publishRequest);
System.out.println(publishResult);
}
}
I just change the publishMessage method and delete the confirmSubscription this method from my service.
#Component
public class SNSServiceImpl implements SNSService {
private static final Logger logger = LoggerFactory.getLogger(SNSServiceImpl.class);
#Value("${AWS_ACCESS_KEY_ID:key}")
private String awsAccessKeyId;
#Value("${AWS_SECRET_ACCESS_KEY:secret}")
private String awsAccessKeySecret;
#Value("${AWS_REGION:us-west-2}")
private String awsRegion;
private AmazonSNS snsClient;
#PostConstruct
public void setConnection() {
AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKeyId, awsAccessKeySecret);
AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
snsClient = AmazonSNSClient.builder()
.withRegion(awsRegion)
.withCredentials(awsCredentialsProvider)
.build();
}
#Override
public String createTopic(String topicName) {
CreateTopicRequest topicRequest = new CreateTopicRequest(topicName);
CreateTopicResult topicResult = snsClient.createTopic(topicRequest);
logger.info("Create topic request: " + snsClient.getCachedResponseMetadata(topicRequest));
logger.info("Create topic result: " + topicResult);
return topicResult.getTopicArn();
}
#Override
public void subscribeSNSToTopic(String topicArn, String phoneNumber) {
String protocol = "sms";
SubscribeRequest subscribeRequest = new SubscribeRequest(topicArn, protocol, phoneNumber);
SubscribeResult subscribeResult = snsClient.subscribe(subscribeRequest);
logger.info("Subscribe request: " + snsClient.getCachedResponseMetadata(subscribeRequest));
logger.info("Subscribe result: " + subscribeResult);
}
#Override
public void sendSMSMessageToTopic(String topicArn, String message) {
Map<String, MessageAttributeValue> smsAttributes =
new HashMap<>();
smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue()
.withStringValue("mySenderID") //The sender ID shown on the device.
.withDataType("String"));
smsAttributes.put("AWS.SNS.SMS.MaxPrice", new MessageAttributeValue()
.withStringValue("0.50") //Sets the max price to 0.50 USD.
.withDataType("Number"));
smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue()
.withStringValue("Promotional") //Sets the type to promotional.
.withDataType("String"));
PublishResult publishResult = snsClient.publish(new PublishRequest()
.withTopicArn(topicArn)
.withMessage(message)
.withMessageAttributes(smsAttributes));
logger.info("Public Result: " + publishResult);
}
}
I hade a strange happening today with my Firebase project.
Suddenly the
AddressChatMessage chatMessage = snapshot.getValue(AddressChatMessage.class);
parsed everything ok for the AddressChatMessage except for one int.
Took me 2 hour until i tried this, setting the field to public
public int type;
Note I use this code for weeks without problem and today Android studio made some core updated to 2.3.2 and maybe that trigger this strange event.
Here´s the AddressChatMessage.java nothing strange except that the public int type cannot be private, if it is, it will be zero, that too is strange, usually Firebase give out a logcat warning when pojo parsing fails. I have 10 other modell classes like this with plenty of int´s
#IgnoreExtraProperties
public class AddressChatMessage {
// [START Firebase keys inside AddressChatMessage ]
#Exclude
public static final String TYPE = "type";
#Exclude
public static final String SENDER_ID = "senderId";
#Exclude
public static final String MESSAGE = "message";
#Exclude
public static final String FILENAME = "fileName";
#Exclude
public static final String DOWNLOAD_URI = "downloadUri";
#Exclude
public static final String TIME = "time";
// [STOP Firebase keys inside AddressChatMessage ]
public int type;
private String senderId;
private String message;
private String fileName;
private String downloadUri;
#Exclude
private long time;
#Exclude
private String messageId;
public AddressChatMessage() {
}
public AddressChatMessage(int type, String senderUid) {
this.senderId = senderUid;
this.type = type;
}
public AddressChatMessage(int type, String senderUid, String message) {
this.type = type;
this.senderId = senderUid;
this.message = message;
}
private int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getSenderId() {
return senderId;
}
public void setSenderId(String senderId) {
this.senderId = senderId;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getDownloadUri() {
return downloadUri;
}
public void setDownloadUri(String downloadUri) {
this.downloadUri = downloadUri;
}
public long getTime() {
return time;
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
#Exclude
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();
result.put(TYPE, type);
result.put(SENDER_ID, senderId);
result.put(MESSAGE, message);
result.put(FILENAME, fileName);
result.put(DOWNLOAD_URI, downloadUri);
result.put(TIME, time);
return result;
}
#Exclude
public boolean isTypeNormal() {
return getType() == ChatAdapter.MessageType.NORMAL.ordinal();
}
#Exclude
public boolean isTypeImage() {
return getType() == ChatAdapter.MessageType.IMAGE.ordinal();
}
}
When cleaning the code using Lint. Lint suggested changes like "This can be private instead of public" - I accidentally set the getType() to private access.
I want to load data from a remote server in the grid. The following code:
final RepServiceAsync service = GWT.create(RepService.class);
final RepProperties props = GWT.create(RepProperties.class);
RpcProxy<PagingLoadConfig, PagingLoadResult<ReportsList>> proxy = new RpcProxy<PagingLoadConfig, PagingLoadResult<ReportsList>>() {
#SuppressWarnings("unchecked")
#Override
public void load(PagingLoadConfig loadConfig, AsyncCallback callback) {
service.getReports(callback);
}
};
ListStore<ReportsList> store = new ListStore<ReportsList>(props.key());
final PagingLoader<PagingLoadConfig, PagingLoadResult<ReportsList>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<ReportsList>>(
proxy);
loader.setRemoteSort(true);
loader.addLoadHandler(new LoadResultListStoreBinding<PagingLoadConfig, ReportsList, PagingLoadResult<ReportsList>>(
store));
final PagingToolBar toolBar = new PagingToolBar(50);
toolBar.getElement().getStyle().setProperty("borderBottom", "none");
toolBar.bind(loader);
ColumnConfig<ReportsList, String> nameCol = new ColumnConfig<ReportsList, String>(
props.name(), 150, "Name");
ColumnConfig<ReportsList, String> pathCol = new ColumnConfig<ReportsList, String>(
props.path_name(), 150, "Path");
List<ColumnConfig<ReportsList, ?>> l = new ArrayList<ColumnConfig<ReportsList, ?>>();
l.add(nameCol);
l.add(pathCol);
ColumnModel<ReportsList> cm = new ColumnModel<ReportsList>(l);
Grid<ReportsList> grid = new Grid<ReportsList>(store, cm) {
#Override
protected void onAfterFirstAttach() {
super.onAfterFirstAttach();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
loader.load();
}
});
}
};
grid.getView().setForceFit(true);
grid.setLoadMask(true);
grid.setLoader(loader);
RepProperties:
public interface RepProperties extends PropertyAccess<ReportsList> {
#Path("id")
ModelKeyProvider<ReportsList> key();
ValueProvider<ReportsList, String> name();
ValueProvider<ReportsList, String> path_name();
}
ReportsList code:
public class ReportsList implements Serializable {
private static final long serialVersionUID = 1L;
int id;
String name;
String path_name;
public ReportsList() {
}
public ReportsList(int id, String name, String path_name) {
super();
this.id = id;
this.name = name;
this.path_name = path_name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath_name() {
return path_name;
}
public void setPath_name(String path_name) {
this.path_name = path_name;
}
}
GWT Servlet Impl:
public class RepServiceImpl extends RemoteServiceServlet implements RepService {
private static final long serialVersionUID = 1L;
#EJB
private ReportEjb repManager;
#Override
public List<Report> getReports() {
List<Report> reports = null;
reports = repManager.getReports();
return reports ;
}
}
The code is executed without error, the query to the database is performed ( EJB-call ), but the Grid is not populated.
In what could be the problem?
In my experience this usually means that there is an exception while trying to put data into the grid itself. Try attaching a LoadExceptionHandler to your loader and see what it gives you
e.g.
public class DebugLoadHandler implements LoadExceptioniHandler<ListLoadConfig> {
#Override
public void onLoadException(LoadExceptionEvent<ListLoadConfig> event) {
Window.alert("Load Exception" + event.getException().getMessage());
}
}