FFmpegFrameRecorder Issue - java-native-interface

While using FFmpegFrameRecorder from JavaCV the JVM crashes with the following message :
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000699d6a64, pid=4076, tid=308
#
# JRE version: 7.0_13-b20
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.7-b01 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [avformat-54.dll+0xd6a64] av_read_play+0x4
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Sagar Jadhav\Documents\NetBeansWorkspace\OpenCV\hs_err_pid4076.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Java Result: 1
The code is as follows :
package com.opencv.windows;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.FFmpegFrameGrabber;
import com.googlecode.javacv.FFmpegFrameRecorder;
import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core;
public class VideoRecorderDemo
{
OpenCVFrameGrabber grabber;
FFmpegFrameRecorder recorder;
CanvasFrame canvasFrame;
VideoRecorderDemo()
{
grabber = new OpenCVFrameGrabber("c:\\sample.mp4");
recorder = new FFmpegFrameRecorder("c:\\sample1.mp4", 2);
canvasFrame = new CanvasFrame("Video Recorder Demo");
canvasFrame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
try
{
grabber.start();
opencv_core.IplImage image;
while((canvasFrame.isVisible()) && (image = grabber.grab()) != null)
canvasFrame.showImage(image);
}
catch(Exception e)
{
System.out.println("Error : " + e.getMessage());
}
init();
startRecording();
stopRecording();
}
void init()
{
try
{
grabber.start();
recorder.start();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void startRecording()
{
try
{
opencv_core.IplImage image;
while((canvasFrame.isVisible()) && (image = grabber.grab()) != null)
{
recorder.record(image);
canvasFrame.showImage(image);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void stopRecording()
{
try
{
grabber.stop();
recorder.stop();
canvasFrame.dispose();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public static void main(String args[])
{
new VideoRecorderDemo();
}
}
I am using OpenCV 2.4.3 libs and the ffmpeg libs provided from zeronoe (ffmpeg-20130209-git-969039e-win64-shared)
Thanks

u must use this version of ffmpeg:
http://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-20121029-git-11d695d-win64-shared.7z
i had ur problem but i searched the JavaCV readme file and i found that JavaCV has been compiled with this version of ffmpeg
good luck

Related

Build problems with CodenameOneCameraKit.cn1lib

I am trying to run the demo program for the CodenameOne CameraKit:
https://github.com/codenameone/CameraKitDemo/ after reading
https://www.codenameone.com/blog/camerakit-low-level-camera-api.html
It compiles and runs in the simulator, but when I send it to the server to build, it gives me a build error.
Am I missing something?
I am using the IntelliJ IDE:
IntelliJ IDEA 2018.1.1 (Community Edition)
Build #IC-181.4445.78, built on April 9, 2018
JRE: 1.8.0_152-release-1136-b27 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.3
Latest Codename One plugin
Here follows the code, and the errors from the build server.
enter code here
package com.test;
import static com.codename1.ui.CN.*;
import com.codename1.camerakit.CameraEvent;
import com.codename1.camerakit.CameraKit;
import com.codename1.camerakit.CameraListener;
import com.codename1.components.FloatingActionButton;
import com.codename1.components.SpanLabel;
import com.codename1.components.ToastBar;
import com.codename1.ui.*;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.LayeredLayout;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.NetworkEvent;
/**
* This file was generated by Codename One for the purpose
* of building native mobile applications using Java.
*/
public class CameraDemo3 {
private Form current;
private Resources theme;
private CameraKit ck;
public void init(Object context) {
ck = CameraKit.create();
// use two network threads instead of one
updateNetworkThreadCount(2);
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
addNetworkErrorListener(err -> {
// prevent the event from propagating
err.consume();
if(err.getError() != null) {
Log.e(err.getError());
}
Log.sendLogAsync();
Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
});
}
public void start() {
if(ck != null && !ck.isStarted()) {
ck.start();
}
if(current != null){
current.show();
return;
}
Form hi = new Form("Native Camera", new LayeredLayout());
hi.setScrollableY(false);
if(ck != null) {
ck.addCameraListener(new CameraListener() {
#Override
public void onError(CameraEvent ev) {
// We currently get some errors on Android
Log.p(ev.getMessage() + " : " + ev.getExceptionMessage());
}
#Override
public void onImage(CameraEvent ev) {
ToastBar.showInfoMessage("Captured image bytes");
}
#Override
public void onVideo(CameraEvent ev) {
ToastBar.showInfoMessage("Captured video: " + ev.getFile());
}
});
hi.add(ck.getView());
Button video = new Button();
FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM);
video.addActionListener(e -> {
Boolean b = (Boolean)video.getClientProperty("capturing");
if(b == null) {
video.putClientProperty("capturing", Boolean.TRUE);
ck.captureVideo();
FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM_OFF);
} else {
video.putClientProperty("capturing", null);
ck.stopVideo();
FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM);
}
});
FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_CAMERA);
fab.bindFabToContainer(hi, CENTER, BOTTOM);
fab.addActionListener(e -> ck.captureImage());
Button toggleCamera = new Button();
FontImage.setMaterialIcon(toggleCamera, FontImage.MATERIAL_CAMERA_FRONT);
Button toggleFlash = new Button();
FontImage.setMaterialIcon(toggleFlash, FontImage.MATERIAL_FLASH_ON);
toggleCamera.addActionListener(e -> ck.toggleFacing());
toggleFlash.addActionListener(e -> ck.toggleFlash());
Container buttons = BoxLayout.encloseY(video, toggleCamera, toggleFlash);
buttons.setScrollableY(true);
hi.add(BorderLayout.east(buttons));
} else {
hi.add(BorderLayout.north(new SpanLabel("Loading native camera view")));
}
hi.show();
}
public void stop() {
current = getCurrentForm();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = getCurrentForm();
}
}
public void destroy() {
}
}
Build Server output:
User-level: 1000
Request Args:
-----------------
java.version=8
ios.NSCameraUsageDescription=We need camera access to grab pictures and videos
ios.newStorageLocation=true
-------------------
Executing: /home/ec2-user/android-sdk/tools/android create project --target android-23 --name CameraDemo3 --path /tmp/build9109673224646903413xxx/CameraDemo3 --activity CameraDemo3Stub --package com.test --gradle --gradle-version 2.0.0 Created directory /tmp/build9109673224646903413xxx/CameraDemo3/src/main/java
Created directory /tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/test
...... cut to reduce length .....
Compiling with JDK Java compiler API.
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:3: error: package com.wonderkiln.camerakit does not exist
import com.wonderkiln.camerakit.*;
^
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:9: error: cannot find symbol
private CameraView view;
^
symbol: class CameraView
location: class CameraNativeAccessImpl
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:10: error: cannot find symbol
private CameraKitEventListener listener = new CameraKitEventListener() {
^
symbol: class CameraKitEventListener
location: class CameraNativeAccessImpl
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:10: error: cannot find symbol
private CameraKitEventListener listener = new CameraKitEventListener() {
^
symbol: class CameraKitEventListener
location: class CameraNativeAccessImpl
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:35: error: cannot find symbol
view = new CameraView(AndroidNativeUtil.getContext());
^
symbol: class CameraView
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
:compileDebugJavaWithJavac FAILED
:compileDebugJavaWithJavac (Thread[Daemon worker,5,main]) completed. Took 7.792 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileDebugJavaWithJavac'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:154)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:151)
at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:45)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:52)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:40)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:47)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:103)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:52)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:34)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:38)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:24)
at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:157)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:127)
at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:244)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:231)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:209)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 68 more
BUILD FAILED
Total time: 18.103 secs
Stopped 0 compiler daemon(s).
Received result Failure[value=org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':compileDebugJavaWithJavac'.] from daemon DaemonInfo{pid=11167, address=[46019278-8ed8-4606-8f74-3c03030b4a25 port:44179, addresses:[/0:0:0:0:0:0:0:1%lo, /127.0.0.1]], idle=false, context=DefaultDaemonContext[uid=1240b5d8-39f4-4710-ac85-f3cf1a99af7f,javaHome=/home/ec2-user/jdk1.8.0_45,daemonRegistryDir=/home/ec2-user/.gradle/daemon,pid=11167,idleTimeout=120000,daemonOpts=-XX:MaxPermSize=512m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx2048m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]} (build should be done).
Process return code is 1
It looks like you took the cn1lib and tried to use the code instead of installing the cn1lib using the extension manager available in Codename One Settings.
I would suggest installing the extension.
If you would still want to use the code notice you also need to replicate the changes to build hints which are missing. These are within the properties files that are a part of the cn1lib.

Remove Eclipse Environment Variable programmatically Plugin Development

I'm currently developing an plugin which must remove a Eclipse Environment variable, for now i have this:
public static void removeEnvironmentVariable(IProject proj, String variable) {
// environment path
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(proj);
IEnvironmentVariableManager envManager =
CCorePlugin.getDefault().getBuildEnvironmentManager();
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
// We must iterate through all configurations
for(ICConfigurationDescription config : prjDesc.getConfigurations()) {
contribEnv.removeVariable(variable, config);
}
// Save the changes to the environment
try {
CoreModel.getDefault().setProjectDescription(proj, prjDesc);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
What am I doing wrong?

PHPUnit fails testing a custom exception

I am having trouble to test correctly a thrown exception (Is it a namspacing problem).
Here is my custom exception:
<?php
namespace Example\Customexception;
class ResourceNotAvailableException extends \Exception {}
Here the class I am testing:
namespace Example\Lib;
use Example\Customexception\ResourceNotAvailableException;
class Configuration {
private static $instance;
private $arrConfig;
private function __construct($configFile)
{
$this->arrConfig = parse_ini_file($configFile, true);
if ($this->arrConfig == false){
throw new ResourceNotAvailableException("Config file {$configFile} not available.");
}
}
public static function getInstance($configFile = "config/config.ini")
{
if (self::$instance == null){
try {
self::$instance = new Configuration($configFile);
}
catch(ResourceNotAvailableException $e) {
throw $e;
}
}
return self::$instance;
}
}
And here is my test class:
use Example\Lib\Configuration;
class ConfigurationTest extends PHPUnit_Framework_TestCase {
/**
* #expectedException Example\Customexception\ResourceNotAvailableException
*/
function testGetInstanceThrowsException()
{
$configuration = Configuration::getInstance("configtestini");
}
}
And here is the output I get:
PHPUnit 5.3.2 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 89 ms, Memory: 2.75Mb
There was 1 error:
1) ConfigurationTest::testGetInstanceThrowsException
parse_ini_file(configtestini): failed to open stream: No such file or directory
/home/me/workspace/codeexample/src/Lib/Configuration.php:24
/home/me/workspace/codeexample/src/Lib/Configuration.php:39
/home/me/workspace/codeexample/tests/unit/Lib/ConfigurationTest.php:14
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Please ignore the line numbers in the output because I removed some comments from the code to make it easily readable here.
Thanks
parse_ini_file() raises an error which is turned into an exception by PHPUnit's error handler.

org.omg.CORBA.MARSHAL: Server-side Exception: null

I'm trying to register to a CORBA CosNotification Service. In the documentation of the service I'm trying to connect to, it says I have to a CosNotifyComm::SequencePushConsumer object, and attach it to the notification service. I've included my code, and the error I'm getting back.
AlarmClient.java
import NotificationIRPSystem.*;
import org.omg.CosNotification.*;
import org.omg.CosNotifyComm.*;
import org.omg.CosNotifyChannelAdmin.*;
import org.omg.CosNotifyFilter.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.PortableServer.*;
public class AlarmClient
{
static _NotificationIRPOperations notiOp;
public static void main (String args [])
{
try{
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, null);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references ("NameService");
System.out.println("IOR===> " + objRef);
NamingContextExt nc = NamingContextExtHelper.narrow(objRef);
String name = "com/ericsson/nms/cif/service/NMSNAConsumer";
String portal = "com/ericsson/nms/cif/service/NMSNAPortal";
org.omg.CORBA.Object notiObj = nc.resolve_str(name);
System.out.println(nc.resolve_str(portal));
System.out.println("noti---->" + notiObj);
_NotificationIRPOperations tt = _NotificationIRPOperationsHelper.narrow(notiObj);
IRPManager irpMan = new IRPManager();
POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate();
org.omg.CORBA.Object objNotiServer = poa.servant_to_reference(irpMan);
String manager_reference = orb.object_to_string(objNotiServer);
System.out.println("MANAGER REF: " + manager_reference);
System.out.println("OBJ NOTI SERVER: " + objNotiServer);
int time_tick = 15;
String filter = "";
String[] asd = {};
NotificationIRPConstDefs.EventTypesSetHolder e_list = new NotificationIRPConstDefs.EventTypesSetHolder();
NotificationIRPConstDefs.ExtendedEventTypesSetHolder ex_list = new NotificationIRPConstDefs.ExtendedEventTypesSet\
Holder();
String cats[] = tt.get_notification_categories(e_list, ex_list);
String res = tt.attach_push(manager_reference, time_tick, asd , filter);
// System.out.println("SUCCESS--->" + res);
// String[] ids = tt.get_subscription_ids(manager_reference);
System.out.println("ALARMIRPOPERATIONS_----> " + tt);
} catch (Exception e){
System.out.println ("ERROR: " + e);
e.printStackTrace (System.out);
}
}
}
IRPManager.java
import NotificationIRPSystem.*;
import org.omg.CosNotification.*;
import org.omg.CosNotifyComm.*;
import org.omg.CosNotifyChannelAdmin.*;
import org.omg.CosNotifyFilter.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.PortableServer.*;
public class IRPManager
extends SequencePushConsumerPOA
{
public void disconnect_sequence_push_consumer()
{
System.out.println("Disconnected!");
}
public void push_structured_events(org.omg.CosNotification.StructuredEvent[] notifications) throws org.omg.CosEvent\
Comm.Disconnected
{
System.out.println("Received Event");
}
public void offer_change(org.omg.CosNotification.EventType[] added, org.omg.CosNotification.EventType[] removed) th\
rows org.omg.CosNotifyComm.InvalidEventType
{
System.out.println("Offer Change!");
}
}
OUTPUT
14-Aug-2013 3:54:02 PM org.jacorb.orb.ORBSingleton <init>
INFO: created ORBSingleton
IOR===> IOR:000000000000001D49444C3A6F6D672E6F72672F434F5242412F4F626A6563743A312E3000000000000000010000000000000040000102000000000F3137322E33302E3132302E3135380000C06600000000000B4E616D655365727669636500000000010000000000000008000000004A414300
14-Aug-2013 3:54:03 PM org.jacorb.orb.giop.ClientConnectionManager getConnection
INFO: ClientConnectionManager: created new ClientGIOPConnection to 172.30.120.158:49254 (7bea5671)
14-Aug-2013 3:54:03 PM org.jacorb.orb.iiop.ClientIIOPConnection connect
INFO: Connected to 172.30.120.158:49254 from local port 57080
14-Aug-2013 3:54:03 PM org.jacorb.orb.iiop.ClientIIOPConnection close
INFO: Client-side TCP transport to 172.30.120.158:49254 closed.
14-Aug-2013 3:54:03 PM org.jacorb.orb.giop.ClientConnectionManager getConnection
INFO: ClientConnectionManager: created new ClientGIOPConnection to 10.20.0.4:49254 (58a17083)
14-Aug-2013 3:54:03 PM org.jacorb.orb.iiop.ClientIIOPConnection connect
INFO: Connected to 10.20.0.4:49254 from local port 52574
IOR:000000000000001849444C3A506F7274616C2F53657276696365733A312E300000000001000000000000007C000102000000000A31302E32302E302E3800C27B0000002000504D43000000040000000C2F466163746F7279504F4100000000040000000000000003564953030000000500070801FF000000000000000000000800000000564953000000000100000018000000000001000100000001050100010001010900000000
noti---->IOR:000000000000004449444C3A336770707361352E6F72672F4E6F74696669636174696F6E49525053797374656D2F4E6F74696669636174696F6E4952504F7065726174696F6E733A312E3000000000010000000000000088000102000000000A31302E32302E302E3800C27B0000002C00504D43000000040000000C2F466163746F7279504F4100000000104E4D534E41436F6E73756D6572322E3300000003564953030000000500070801FF000000000000000000000800000000564953000000000100000018000000000001000100000001050100010001010900000000
14-Aug-2013 3:54:03 PM org.jacorb.poa.AOM add
INFO: oid: 00 40 46 20 4B 4D 29 05 2A 07 10 06 30 46 38 14 14 1B 48 4C .#F KM).*...0F8...HL1B .object is activated
14-Aug-2013 3:54:03 PM org.jacorb.poa.POA getImplName
INFO: Using server ID (8624227886) for transient POA
MANAGER REF: IOR:000000000000003349444C3A6F6D672E6F72672F436F734E6F74696679436F6D6D2F53657175656E636550757368436F6E73756D65723A312E300000000000010000000000000050000102000000000E3137322E31362E32342E31353200B91900000020383632343232373838362F004046204B4D29052A07100630463814141B484C1B000000010000000000000008000000004A414300
OBJ NOTI SERVER: IOR:000000000000003349444C3A6F6D672E6F72672F436F734E6F74696679436F6D6D2F53657175656E636550757368436F6E73756D65723A312E300000000000010000000000000050000102000000000E3137322E31362E32342E31353200B91900000020383632343232373838362F004046204B4D29052A07100630463814141B484C1B000000010000000000000008000000004A414300
14-Aug-2013 3:54:03 PM org.jacorb.orb.giop.ClientConnectionManager getConnection
INFO: ClientConnectionManager: created new ClientGIOPConnection to 10.20.0.8:49787 (68e6ff0d)
14-Aug-2013 3:54:03 PM org.jacorb.orb.iiop.ClientIIOPConnection connect
INFO: Connected to 10.20.0.8:49787 from local port 35910
**************************************************************************org.jacorb.orb.giop.RequestOutputStream#1be1a408
14-Aug-2013 3:54:04 PM org.jacorb.orb.iiop.ClientIIOPConnection close
INFO: Client-side TCP transport to 10.20.0.8:49787 closed.
org.omg.CORBA.MARSHAL: Server-side Exception: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at org.jacorb.orb.SystemExceptionHelper.read(SystemExceptionHelper.java:222)
at org.jacorb.orb.ReplyReceiver.getReply(ReplyReceiver.java:456)
at org.jacorb.orb.Delegate._invoke_internal(Delegate.java:1418)
at org.jacorb.orb.Delegate.invoke_internal(Delegate.java:1187)
at org.jacorb.orb.Delegate.invoke(Delegate.java:1175)
at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:80)
at NotificationIRPSystem.__NotificationIRPOperationsStub.attach_push(__NotificationIRPOperationsStub.java:288)
at AlarmClient.main(AlarmClient.java:43)
I'm not really sure what's happening. I think maybe that the object I'm trying to marshal is different from what the server expects? I hope someone can help, let me know if you need more information or if I missed something.
UPDATE
This is the _NotificationIRPOperationsStub code which contains attach_push
public java.lang.String attach_push(java.lang.String manager_reference, int time_tick, java.lang.String[] notification_category_set, java.lang.String filter) throws NotificationIRPSystem.AlreadySubscribed,NotificationIRPSystem.Attach,NotificationIRPSystem.AtLeast\
OneNotificationCategoryNotSupported,NotificationIRPSystem.ParameterNotSupported,NotificationIRPSystem.InvalidParameter
{
while(true)
{
if(! this._is_local())
{
org.omg.CORBA.portable.InputStream _is = null;
org.omg.CORBA.portable.OutputStream _os = null;
try
{
_os = _request( "attach_push", true);
java.lang.String tmpResult10 = manager_reference;
_os.write_string( tmpResult10 );
_os.write_ulong(time_tick);
NotificationIRPConstDefs.NotificationCategorySetHelper.write(_os,notification_category_set);
java.lang.String tmpResult11 = filter;
_os.write_string( tmpResult11 );
System.out.println("**************************************************************************" + _os.toString());
_is = _invoke(_os);
java.lang.String _result = _is.read_string();
return _result;
}
catch( org.omg.CORBA.MARSHAL m){
m.printStackTrace();
return m.getStackTrace().getClassName();
}
catch( org.omg.CORBA.portable.RemarshalException _rx )
{
continue;
}
catch( org.omg.CORBA.portable.ApplicationException _ax )
{
String _id = _ax.getId();
try
{
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/AlreadySubscribed:1.0"))
{
throw NotificationIRPSystem.AlreadySubscribedHelper.read(_ax.getInputStream());
}
else
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/Attach:1.0"))
{
throw NotificationIRPSystem.AttachHelper.read(_ax.getInputStream());
}
else
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/AtLeastOneNotificationCategoryNotSupported:1.0"))
{
throw NotificationIRPSystem.AtLeastOneNotificationCategoryNotSupportedHelper.read(_ax.getInputStream());
}
else
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/ParameterNotSupported:1.0"))
{
throw NotificationIRPSystem.ParameterNotSupportedHelper.read(_ax.getInputStream());
}
else
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/InvalidParameter:1.0"))
{
throw NotificationIRPSystem.InvalidParameterHelper.read(_ax.getInputStream());
}
else{
throw new RuntimeException("Unexpected exception " + _id );
}
}
finally
{
try
{
_ax.getInputStream().close();
}
catch (java.io.IOException e)
{
throw new RuntimeException("Unexpected exception " + e.toString() );
}
}
}
finally
{
if (_os != null)
{
try
{
_os.close();
}
catch (java.io.IOException e)
{
throw new RuntimeException("Unexpected exception " + e.toString() );
}
}
this._releaseReply(_is);
}
}
else
{
org.omg.CORBA.portable.ServantObject _so = _servant_preinvoke( "attach_push", _opsClass );
if( _so == null )
continue;
_NotificationIRPOperationsOperations _localServant = (_NotificationIRPOperationsOperations)_so.servant;
java.lang.String _result;
try
{
_result = _localServant.attach_push(manager_reference,time_tick,notification_category_set,filter);
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).normalCompletion();
return _result;
}
catch (NotificationIRPSystem.AlreadySubscribed ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (NotificationIRPSystem.Attach ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (NotificationIRPSystem.AtLeastOneNotificationCategoryNotSupported ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (NotificationIRPSystem.ParameterNotSupported ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (NotificationIRPSystem.InvalidParameter ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (RuntimeException re)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(re);
throw re;
}
catch (java.lang.Error err)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(err);
throw err;
}
finally
{
_servant_postinvoke(_so);
}
}
}
}
Thanks.
UPDATE # 2
Thanks to Brian for posting that version of the document. I took the IDL from there, and with a minor adjustment I was able to call attach_push with my objNotiServer. My next question is about how I can set my AlarmClient up to receive these notifications. My assumption is that I can call orb.run() and then when notifications come in, I will receive them in my IRPManager object, is that right?
CORBA::MARSHAL exceptions usually occur because of one of these reasons:
IDL mismatches between client and server (causing unexpected payload differences)
Crappy ORB products that don't know how to unmarshal complex but valid payloads correctly
Reason #2 is really unlikely nowadays, as ORBs have matured enough that this rarely happens. As long as you're using ORB products on both the client and server side that were built in this century then you're probably ok. That leaves reason #1.
The IDL for the method you're calling is (I believe) from this document, and looks like this:
interface NotificationIRPOperations {
NotificationIRPConstDefs::SubscriptionId attach_push (
in Object manager_reference,
in long time_tick,
in NotificationCategorySet notification_category_set,
in string filter
)
raises (Attach, ParameterNotSupported, InvalidParameter, AlreadySubscribed,
AtLeastOneNotificationCategoryNotSupported);
Note the first parameter, it's of type Object. However in your code, you're passing a string. However the IDL type Object maps to org.omg.CORBA.Object in Java, not to a String. I would have expected to see you pass objNotiServer instead for this parameter.
So either your IDL is mismatched with what your server is expecting (likely), or your IDL compiler isn't following the basic IDL-to-Java mapping rules (unlikely).
Either way, something smells bad there. I don't believe that the ORB will implicitly call ORB.string_to_object() for you, so that would lead to a regular string being sent on the network when the server is actually expecting a stringified Object reference. The difference is subtle but it might be the reason why the server is throwing a MARSHAL back at you.
So your first port of call should be a check on the IDL file that you're using to build your client. Make sure that you've got the exact and correct IDL for the server you're trying to call. If there's any mismatch at all then MARSHAL exceptions will happen, and happen a lot.
The server side has a problem, therefor you receive the server side exception.
Your IDL is different on Server/Client which causes this error.
You have to look at the server's logfile. If you do not have access to the server, implement your own dummy-server and find out whether or not it works.
Regarding the manager_reference, test it in your own code via: narrow and a call to _non_existent(). I.e.
org.omg.CORBA.Object managerObj = orb.string_to_object(manager_reference);
IRPManager managerImpl = IRPManagerHelper.narrow(managerObj);
managerImpl._non_existent()
If this works, your IRPManager servant works.
By the way, you have a lot of unused imports and should refactor them. Your IDE would help you.
For Update2
Yout Alarmclient has to implement StructuredPushConsumer (see Initializing Corba notification service in java successfully but cannot get any events in linux but it's done in windows) and subscribe to the notifications.
But I recomment to open a new question.
Your code looks suspicious, you never activate irpMan in the POA, but you do use servant_to_reference. Try the code below, handle it as pseudo code, I haven't tested it and I normally program C++.
IRPManager irpMan = new IRPManager();
POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate();
ObjectId id = poa.activate_object (irpMan);
org.omg.CORBA.Object objNotiServer = poa.id_to_reference(id);
String manager_reference = orb.object_to_string(objNotiServer);
System.out.println("MANAGER REF: " + manager_reference);
System.out.println("OBJ NOTI SERVER: " + objNotiServer);
int time_tick = 15;
String filter = "";
String[] asd = {};
NotificationIRPConstDefs.EventTypesSetHolder e_list = new NotificationIRPConstDefs.EventTypesSetHolder();
NotificationIRPConstDefs.ExtendedEventTypesSetHolder ex_list = new NotificationIRPConstDefs.ExtendedEventTypesSet\
Holder();
String cats[] = tt.get_notification_categories(e_list, ex_list);
String res = tt.attach_push(objNotiServer, time_tick, asd , filter);

get the list of source files from existing eclipse project using CDT

i am working on CDT eclipse plug in development, i am trying to get the list of sources files which exist in eclipse project explorer using CDT code using following code ,which results null.
Case1:
IFile[] files2 = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(new URI("file:/"+workingDirectory));
for (IFile file : files2) {
System.out.println("fullpath " +file.getFullPath());
}
Case2:
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(getProject().getRawLocationURI());
for (IFile file : files) {
System.out.println("fullpath " +file.getFullPath());
}
Case3:
IFile[] files3 = ResourceLookup.findFilesByName(getProject().getFullPath(),ResourcesPlugin.getWorkspace().getRoot().getProjects(),false);
for (IFile file : files3) {
System.out.println("fullpath " +file.getFullPath());
}
Case4:
IFolder srcFolder = project.getFolder("src");
Case 1 ,2,3 giving me output null, where i am expecting list of files;
in Case 4: i am getting the list of "helloworld/src" files, but i am expecting to get the files from the existing project mean main root ,ex:"helloworld"
please suggest me on this.
You can either walk through the worspace resources tree using IResourceVisitor - or you can walk through CDT model:
private void findSourceFiles(final IProject project) {
final ICProject cproject = CoreModel.getDefault().create(project);
if (cproject != null) {
try {
cproject.accept(new ICElementVisitor() {
#Override
public boolean visit(final ICElement element) throws CoreException {
if (element.getElementType() == ICElement.C_UNIT) {
ITranslationUnit unit = (ITranslationUnit) element;
if (unit.isSourceUnit()) {
System.out.printf("%s, %s, %s\n", element.getElementName(), element.getClass(), element
.getUnderlyingResource().getFullPath());
}
return false;
} else {
return true;
}
}
});
} catch (final CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Note there may be more source files then you actually want (e.g. you may not care system about headers) - you can filter them by checking what the underlying resource is.