showForm - java.lang.reflect.InvocationTargetException - codenameone

I have an application on which I was working couple days ago - app was working.
when I try work on it yesterday one of initial screen give me an error
java.lang.reflect.InvocationTargetException
when I call s.showForm("Main",null)
I am using win10, and netbeans 8, latest Codenameone plugin - just reinstall just in case.
I am not sure what could cased this problem.
Thank you for sugestions
Function code:
public void autologin(final StateMachine s,Form f)
{
common.log("Login Auto Login");
autologin=true;
Hashtable hUserDetails = new Hashtable();
Hashtable hLoginDetails = new Hashtable();
hUserDetails = common.readHashtable(constant.getStoreUserDetails());
hLoginDetails = common.readHashtable(constant.getStoreLoginDetails());
if ( hUserDetails!= null && hLoginDetails != null )
{
common.log("Login Check for sessionToken : " + hLoginDetails.get("sessionToken".toString()) );
String SavedSessionToken = hLoginDetails.get("sessionToken".toString()).toString();
common.log("SavedSessionToken : " + SavedSessionToken );
if ( SavedSessionToken.length() > 1 )
{
common.log("Login execute userLogin");
common.log("Call UserLogin user : "+hUserDetails.get("username").toString());
common.log("Call UserLogin pass: "+ hUserDetails.get("password").toString());
UserLogin( s, hUserDetails.get("username").toString(), hUserDetails.get("password").toString(),1);
}else{
common.log("Login sessionToken not found - show Main");
s.showForm("Main",null);
}
}else{
common.log("Login hUserDetails - null; redirect to Main");
try{
s.showForm("Main",null);
}catch (Exception e ){
common.log("autologin showForm Exception "+e );
}
}
}
error message
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.codename1.impl.javase.Executor$1$1.run(Executor.java:100)
at com.codename1.ui.Display.processSerialCalls(Display.java:1148)
at com.codename1.ui.Display.mainEDTLoop(Display.java:965)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Caused by: java.lang.NullPointerException
at userclasses.StateMachine.postMain(StateMachine.java:221)
at generated.StateMachineBase.postShow(StateMachineBase.java:1844)
at com.codename1.ui.util.UIBuilder.postShowImpl(UIBuilder.java:2598)
at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2516)
at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2561)
at userclasses.Login.autologin(Login.java:249)
at userclasses.StateMachine.postSplash(StateMachine.java:539)
at generated.StateMachineBase.postShow(StateMachineBase.java:1820)
at com.codename1.ui.util.UIBuilder.postShowImpl(UIBuilder.java:2598)
at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2516)
at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2561)
at generated.StateMachineBase.startApp(StateMachineBase.java:66)
at generated.StateMachineBase.<init>(StateMachineBase.java:31)
at generated.StateMachineBase.<init>(StateMachineBase.java:118)
at userclasses.StateMachine.<init>(StateMachine.java:53)
at com.degmorinc.app.Degmor.DegmorIncSupport.start(DegmorIncSupport.java:20)
... 9 more
Java Result: 1

Related

Springboot use inmemory database and MSSQL

I have a SpringBoot application I need to work with two databases. When I use inmemory h2 database it all works fine.
I can access the two databases and read the data.
But I need to acces one MSSQL database and keep the other one in H2 format, for now at least. And here my problems start.
I get the following error when I run my application
org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:153) ~[spring-batch-infrastructure-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103) ~[spring-batch-infrastructure-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311) ~[spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:205) ~[spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:68) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:137) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:319) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:147) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at com.sun.proxy.$Proxy72.run(Unknown Source) [na:na]
at se.clearon.validoo.JobInvokerController.handle(JobInvokerController.java:36) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) [spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_152]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_152]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_152]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_152]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_152]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_152]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]
Caused by: java.lang.RuntimeException: Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl, jdbc:h2:~/test;MODE=MSSQLServer
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:110) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:321) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:110) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.2.jar:na]
at org.springframework.batch.item.database.AbstractCursorItemReader.initializeConnection(AbstractCursorItemReader.java:447) ~[spring-batch-infrastructure-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:427) ~[spring-batch-infrastructure-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:150) ~[spring-batch-infrastructure-4.2.1.RELEASE.jar:4.2.1.RELEASE]
... 39 common frames omitted
The SpringBoot application is a batch job, so I thought I should put Spring batch database in the inmemory database, my configuration for spring:
spring:
batch:
job:
enabled: false
initialize-schema: never
initializer:
enabled: false
datasource:
initialization-mode: never
driver-class-name: org.h2.Driver
url: jdbc:h2:~/test;MODE=MSSQLServer
username: sa
password: sa
h2:
console:
enabled: true
error:
whitelabel:
enabled: false
profiles:
active: test
jpa:
database: default
The other data should be saved to a MSSQL database and my configuration for this looks like this
store:
datasource:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://sql.server:1433;databaseName=store
username: admin
password: *****
validationQuery: "select 1"
My configuration class
#Profile("!default")
#Configuration
#EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
public class DataSourceConfig {
#Bean
#Primary
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder
.setType(EmbeddedDatabaseType.H2)
.addScript("classpath:/org/springframework/batch/core/schema-h2.sql")
.build();
}
#Bean(name = "storeDataSourceProperties")
public DataSourceProperties storeDataSourceProperties() {
return new DataSourceProperties();
}
#Bean(name = "storeDataSource")
#ConfigurationProperties("store.datasource")
public HikariDataSource storeDataSource(
#Qualifier("storeDataSourceProperties") DataSourceProperties properties) {
return properties
.initializeDataSourceBuilder()
.type(HikariDataSource.class)
.build();
}
#Bean(name = "storeTransactionManager")
public PlatformTransactionManager storeTransactionManager(
#Qualifier("storeDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
#Bean(name = "storeJdbcTemplate")
public JdbcTemplate storeJdbcTemplate(#Qualifier("storeDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
}
One of my entities:
public class Store {
private String storeID;
private String name;
public Store () {
}
public Supplier(String storeID, String name) {
this.storeID = storeID;
this.name = name;
}
public String getStoreID() {
return storeID;
}
public void setStoreID(String storeID) {
this.gln = storeID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
I am not really sure why it is not working?
I should be able to have two databases in SpringBoot right?
I think there is something wrong with my configuration class because I started with two MSSQL databases and that didn't work either.
My use of an inmemory database is only temporarily, but I really need this to work.

How to resolve MetadataAPI giving 'System.CalloutException: IO Exception: Read timed out' error on setting recordType to lookupfield value

I am using metadata API to add picklist value('custom') in a field.I have a record type (AAM_T) created which has to be associated with value I have added to picklist, but as on running :
service.updateMetadata( new MetadataService.Metadata[] { recordType });
causing an error 'System.CalloutException: IO Exception: Read timed out'.
MetadataService.PickListValue objPickListValue = new MetadataService.PickListValue();
objPickListValue.fullName = 'custom';
objPickListValue.default_x = false;
MetadataService.RecordType recordType = (MetadataService.RecordType)
service.readMetadata('RecordType',
new String[] { 'Account.AAM_T'}).getRecords()[0];
MetadataService.RecordTypePicklistValue[] recordPickListType = recordType.picklistValues;
if(recordPickListType.size() > 0){
for(MetadataService.RecordTypePicklistValue rpk : recordPickListType) {
if(rpk.picklist == picklistToUpdate){
rpk.values.add(objPickListValue);
break;
}
}
try{
service.updateMetadata( new MetadataService.Metadata[] { recordType });
} catch(Exception ex){
system.debug('###getStackTraceString : '+ex.getStackTraceString());
//Result: System.CalloutException: IO Exception: Read timed out -- null
system.debug('###getMessage : '+ex.getTypeName()
+ ': ' + ex.getMessage() + ' -- ' + ex.getCause());
}
}
You can try this like any other webservice. worked to me
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.timeout_x=120000;

MediaRecorder: java.lang.IllegalStateException at

When I start the device and open my app everything works fine, but after use of another app on the device my app gave this error.
public void startRecorder(){
// Check if user has given permission to record audio
int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.RECORD_AUDIO);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSIONS_REQUEST_RECORD_AUDIO);
return;
}
if (mRecorder == null) {
mRecorder = new MediaRecorder();
mRecorder.setOutputFile("/dev/null");
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
mRecorder.start();
} catch (java.io.IOException ioe) {
mRecorder = null;
android.util.Log.e("[Monkey]", "IOException: " + android.util.Log.getStackTraceString(ioe));
} catch (java.lang.SecurityException e) {
mRecorder = null;
android.util.Log.e("[Monkey]", "SecurityException: " + android.util.Log.getStackTraceString(e));
}
}
}
10-08 10:32:42.260 18121-18121/com.avatarmind.ipaldecibel E/###: JNI_MOTIONSERVICE LOAD
10-08 10:32:42.260 18121-18121/com.avatarmind.ipaldecibel E/###: MotionService Setup
10-08 10:32:42.526 18121-18121/com.avatarmind.ipaldecibel E/MediaRecorder: start failed: -38
10-08 10:32:42.529 18121-18121/com.avatarmind.ipaldecibel E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.avatarmind.ipaldecibel, PID: 18121
java.lang.RuntimeException: Unable to resume activity {com.avatarmind.ipaldecibel/com.avatarmind.ipaldecibel.MainActivity}: java.lang.IllegalStateException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3173)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3204)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2548)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1406)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5509)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:772)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
Caused by: java.lang.IllegalStateException
at android.media.MediaRecorder.start(Native Method)
at com.avatarmind.ipaldecibel.MainActivity.startRecorder(MainActivity.java:300)
at com.avatarmind.ipaldecibel.MainActivity.onResume(MainActivity.java:262)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258)
at android.app.Activity.performResume(Activity.java:6342)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3162)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3204) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2548) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1406) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5509) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:772) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662) 
It seems that when resume application and try to call mRecorder.start() u have an illegal state. Possibly u don't release the MediaRecorder when your Activity pause.
Try with the next code:
#Override
protected void onPause() {
super.onPause();
// if we are using MediaRecorder, release it first
releaseMediaRecorder();
}
private void releaseMediaRecorder(){
if (mMediaRecorder != null) {
// clear recorder configuration
mMediaRecorder.reset();
// release the recorder object
mMediaRecorder.release();
mMediaRecorder = null;
}
}
try use, for 21-30 api it work
setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS)
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)

ErrorIrresolvableConflict while creating an event

I am getting a lot of errors related to ErrorIrresolvableConflict response code when trying to create an event
Stack Trace - at Microsoft.OData.ProxyExtensions.DataServiceContextWrapper.<SaveChangesAsync>d__5e.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Office365CalendarProviderBL.<>c__DisplayClass7_0.<<CreateCalendarEvent>b__0>d.MoveNext() - Inner Exception - Microsoft.OData.Client.DataServiceRequestException: An error occurred while processing this request. ---> Microsoft.OData.Client.DataServiceClientException: {"error":{"code":"ErrorIrresolvableConflict","message":"The send or update operation could not be performed because the change key passed in the request does not match the current change key for the item."}}
--- End of inner exception stack trace ---
at Microsoft.OData.Client.SaveResult.HandleResponse()
at Microsoft.OData.Client.BaseSaveResult.EndRequest()
at Microsoft.OData.Client.DataServiceContext.EndSaveChanges(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.OData.ProxyExtensions.DataServiceContextWrapper.<SaveChangesAsync>d__5e.MoveNext()
I am getting this message with this exception - The send or update operation could not be performed because the change key passed in the request does not match the current change key for the item.
Please explain what is a change key and how it works ?
I am getting these exceptions only from yesterday and hasn't changed any code. Do I need to update anything at my end or am I missing anything ?
I am using V1 DLL - https://api.office.com/discovery/v1.0/me/
ProxyExtension Version - 23
Code:-
// In this method, we are populating event properties later used to create event on calendar. Please verify if I am missing any important property here
private Event CreateCalEventObj(CalendarMeetingBL meeting, string location, meetingAdditionalDataBL data)
{
Event calEvent = new Event();
try
{
calEvent.Subject = WEB.HttpUtility.HtmlDecode(meeting.MeetingName);
calEvent.ShowAs = FreeBusyStatus.Busy;
if (meeting.EventAlarmInMinutes == -1)
meeting.EventAlarmInMinutes = null;
calEvent.Reminder = meeting.EventAlarmInMinutes;
calEvent.Start = meeting.StartTime;
calEvent.End = meeting.EndTime;
calEvent.StartTimeZone = meeting.TimeZoneString;
calEvent.EndTimeZone = meeting.TimeZoneString;
if (!string.IsNullOrEmpty(location) && location.Length <= 500)
{
calEvent.Location = new Microsoft.Office365.OutlookServices.Location()
{
DisplayName = CommonBL.FixLineBreakForGooglelocation(WEB.HttpUtility.HtmlDecode(location.Replace("\n", " ")))
};
}
else if (!string.IsNullOrEmpty(data.Phone))
{
calEvent.Location = new Microsoft.Office365.OutlookServices.Location()
{
DisplayName = "Phone: " + CommonBL.FixLineBreakForGooglelocation(WEB.HttpUtility.HtmlDecode(data.Phone))
};
}
else if (!string.IsNullOrEmpty(data.MobileNumber))
{
calEvent.Location = new Microsoft.Office365.OutlookServices.Location()
{
DisplayName = "Mobile: " + CommonBL.FixLineBreakForGooglelocation(WEB.HttpUtility.HtmlDecode(data.MobileNumber))
};
}
calEvent.Body = new ItemBody()
{
Content = CommonBL.RevertLineBreakPlaceHolder((WEB.HttpUtility.HtmlDecode(meeting.MeetingDetails.Replace(#"\\\", "\\"))))
};
}
catch (Exception ex)
{
BLFactory.CurrentInstance.LoggingBLObj.InsertLog("Insert logging here");
calEvent = null;
}
return calEvent;
}
// In this method we are creating event on calendar.
private string CreateCalendarEvent(CalendarMeetingBL meeting, List<ParticipantBL> invitees, string username, string calendarId, OutlookServicesClient service, string location, meetingAdditionalDataBL data, string meetingId = "-1")
{
var taskCreateMeeting = Task<string>.Run(
async () =>
{
Event calEvent = CreateCalEventObj(meeting, location, data);
if (calEvent != null)
{
try
{
//Add invitees to the event
foreach (ParticipantBL inviteeItem in invitees)
{
if (!inviteeItem.IsAdditional)
{
calEvent.Attendees.Add(new Attendee()
{
EmailAddress = new EmailAddress()
{
Address = inviteeItem.Email.Replace("'", "'"),
Name = inviteeItem.Name
},
Type = AttendeeType.Required,
Status = new ResponseStatus()
{
Response = ResponseType.Accepted,
Time = DateTime.Now
}
});
}
}
}
catch (Exception ex)
{
BLFactory.CurrentInstance.LoggingBLObj.InsertLog(meeting.MeetingId, username, "Locally User ID is Meeting id AND email is username - Scheduling Logging Exception 3 - Stack Trace - " + ex.StackTrace + " - Inner Exception - " + ex.InnerException + " - meetingObjValues - " + meetingObjValues + " - meetingAdditionalDataObjValues - " + meetingAdditionalDataObjValues + " - username - " + username + " - calendarId - " + calendarId + " - location - " + location + " - meetingId - " + meetingId, meeting.MeetingId);
return "-1";
}
try
{
var providerDefault = (String.IsNullOrEmpty(calendarId) ? service.Me.Events : service.Me.Calendars[calendarId].Events);
await providerDefault.AddEventAsync(calEvent); // We are getting Exception here but Event is created in calendar
return calEvent.Id; // Event object is not updated after exception
}
catch (Exception ex)
{
BLFactory.CurrentInstance.LoggingBLObj.InsertLog("Insert exception logging here");
return "-1";
}
}
else
return "-1";
}
);
Task.WaitAll(taskCreateMeeting);
string id = taskCreateMeeting.Result;
return id;
}
The exception we are getting is of type Microsoft.OData.Client.DataServiceRequestException but it is not caught under the dedicated catch block
catch (Microsoft.OData.Client.DataServiceRequestException ex)
{
BLFactory.CurrentInstance.LoggingBLObj.InsertLog("Insert logging here");
return "-1";
}
Let me know if anything else is required
Thanks in Advance.
This is not directly related to OData - we have seen the same thing with EWS. We just found the underlying race condition inside of Exchange code that was causing this and one of our devs just checked in a fix for this. As such, it should start rolling out in production soon.
There is nothing wrong with your code that would be causing this for a new item.

What should we use for ClientResponse and GenericType in latest version (3.0.x) Resteasy?

I am developing Resteasy. I migrated my application's maven dependencies from 2.2.x to 3.0.x and suddenly I saw most of the API's are deprecated. So this migration has affect to my code and test cases as its simply saying deprecated in my whole code.
I am taking example of my test cases:
Test case with earlier version(in latest version it deprectaed as mentioned in link: ClientRequestFactory RestEasy Deprecated... Any other RestEasy alternative ?):
import org.jboss.resteasy.util.GenericType;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;
#Test
public void testGetStudent() throws Exception{
String str = "http://localhost:8080/RESTfulExample/rest/restwebservice/list";
ClientRequest request = new ClientRequest(str);
ClientResponse<List<Student>> response = request.get(new GenericType<List<Student>>(){});
List<Student> students = response.getEntity();
System.out.println("Size : "+students.size());
}
So I refactore my test case to use
#Test
public void testGetStudents(){
final String str = "http://localhost:8080/RESTfulExample/rest/restwebservice/list";
Client client = ClientBuilder.newClient();
// Client client = ClientBuilder.newBuilder().build(); // This also works, OR
Response response = client.target(str).request().get();
// This will gives us whole XML output
String s = response.readEntity(String.class);
System.out.println(s);
**What is the replacement of below two lines in latest version? How I can get List of Student Object ?**
// ClientResponse<List<Student>> response = request.get(new GenericType<List<Student>>(){});
// List<Student> students = response.getEntity();
}
Please guide. What is the replacement of below two lines in latest version? How I can get List of Student Object ?
Edit-1: I tried below, but giving following error:
Students.java
#XmlAccessorType(XmlAccessType.NONE)
#XmlRootElement(name = "students")
public class Students {
#XmlElement(name="student")
private ArrayList<Student> users;
public ArrayList<Student> getUsers() {
return users;
}
public void setUsers(ArrayList<Student> users) {
this.users = users;
}
}
But its giving me errors:
#Test
public void testGetStudents(){
final String str = "http://localhost:8080/RESTfulExample/rest/restwebservice/list";
Client client = ClientBuilder.newClient();
// Client client = ClientBuilder.newBuilder().build(); // This also works, OR
Response response = client.target(str).request().get();
// This will gives us whole XML output
String stringOutput = response.readEntity(String.class);
System.out.println("STATUS : "+response.getStatus());
System.out.println(stringOutput);
Students students = response.readEntity(Students.class);
System.out.println("Size : "+students.getUsers().size());
}
java.lang.IllegalStateException: RESTEASY003765: Response is closed.
at org.jboss.resteasy.specimpl.BuiltResponse.abortIfClosed(BuiltResponse.java:256)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.abortIfClosed(ClientResponse.java:328)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:152)
at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:219)
at com.mkyong.rest.test.RestEasySampleTest.testGetStudents(RestEasySampleTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
The Resteasy Client-API has been marked deprecated as JAX-RS standardized a Client-API. You can now use the equivalent javax.ws.rs classes:
javax.ws.rs.client.Client client = javax.ws.rs.client.ClientBuilder.newClient();
javax.ws.rs.client.WebTarget target = client.target("someUrl");
List<Student> students =
target.request().get(new javax.ws.rs.core.GenericType<List<Student>>() {});
Here's an example with query parameters and a check for the HTTP response code, which is handy for failing fast and avoiding stack traces from the JSON mapper, often hiding the real cause:
Response response = null;
try {
response = target.path("apiMethod")
.queryParam("stringParam", "test")
.queryParam("booleanParam", Boolean.FALSE)
.request().accept(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == Response.Status.BAD_REQUEST.getStatusCode()) { // HTTP 400
throw new BadRequestException("invalid parameters!");
} else if (response.getStatus() ==
Response.Status.NOT_FOUND.getStatusCode()) { // HTTP 404
throw new NotFoundException("resource was not found on server!");
}
List<MyPojo> result = response.readEntity(new GenericType<List<MyPojo>>(){});
return result;
} finally {
if (response != null) {
response.close();
}
}

Resources