#StackBounty: #java #maven #deployment #transactions Combining multiple Maven goals into one transaction (e.g. deploy and site-deploy, …

Bounty: 50

I configured the build server to do

clean javadoc:jar deploy site-deploy

Now if site-deploy fails (because the site did not build, or somebody used the wrong parent pom), the build server shows a failed build, but the deploy was already applied.

Is there a way to “combine” deploy and site-deploy in a transactional way?

Or should I use a different chain of goals/phases (e.g. install before site-deploy)?


Get this bounty!!!

#StackBounty: #java #multithreading #locking #hazelcast #hazelcast-imap Correct use of Hazelcast EntryProcessor

Bounty: 50

We’re trying to work out the best way to use Hazelcast’s IMap without using pessimistic locking.

EntryProcessor seems like the correct choice, however we need to apply two different types of operations: ‘create’ when containsKey is false, and ‘update’ when containsKey is true.

How can I utilise EntryProcessor to support these logic checks?

If two threads hit the containsKey() at the same time and it returns false to both of them, I don’t want both of them to create the key. I’d want the second thread to apply an update instead.

This is what we have so far:

public void put(String key, Object value) {

    IMap<String, Object> map = getMap();

    if (!map.containsKey(key)) {
           // create key here
    } else {
        // update existing value here
        // ...
        map.executeOnKey(key, new TransactionEntryProcessor({my_new_value}));
    }
}

private static class MyEntryProcessor implements
        EntryProcessor<String, Object>, EntryBackupProcessor<String, Object>, Serializable {

    private static final long serialVersionUID = // blah blah

    private static final ThreadLocal<Object> entryToSet = new ThreadLocal<>();

    MyEntryProcessor(Object entryToSet) {
        MyEntryProcessor.entryToSet.set(entryToSet);
    }

    @Override
    public Object process(Map.Entry<String, Object> entry) {
        entry.setValue(entryToSet.get());
        return entry.getValue();
    }

    @Override
    public EntryBackupProcessor<String, Object> getBackupProcessor() {
        return MyEntryProcessor.this;
    }

    @Override
    public void processBackup(Map.Entry<String, Object> entry) {
        entry.setValue(entryToSet.get());
    }
}

You can see that two threads can enter the put method and call containsKey at the same time. The second will overwrite the outcome of the first.


Get this bounty!!!

#StackBounty: #java #algorithm #apache-spark #spark-streaming Build path for different events and assign globalID

Bounty: 50

We are working with spark 1.6 and we are trying to keep global identity for similar events. There can be few “groups”of events with identical ID (in the example as number. letters are added just for uniqueness). And we know that some of these events are similar so we are able to connect them. We want to keep something like:

Z -> 1, 2, 3
X -> 4

so in a future if some events with id 4 will come we can assign X as a global identity.

Please check example for better illustration:

Let’s say we have some streaming data coming into spark job.

1a
1b
2c
2d
2e
3f
3g
3h
4i

Since event 1 is our first appearance we want to assign 1 to Z.
Next what we know is that 1b and 2c are similar. so we want to keep somewhere 2->1 mapping. Same thing is for 2e and 3f so we need mapping 3-2. So for now we have 3 pairs 1->Z, 2->1, 3->2.

And we want to create “historical” path: Z <- 1 <- 2 <- 3
At the end we will have all events with ID = Z.

1a -> Z
1b -> Z
2c -> Z
2d -> Z
2e -> Z
3f -> Z
3g -> Z
3h -> Z
4i -> X

We tried to use mapwithstate but only thing we were able to do was that 2->1 and 3->2. With mapwithstate we were not able to get state for “parent” in state for current event – eg. current event 3 with parent 2 and not able to get 2 -> 1 and neither 1 -> Z.

Is it possible to have some global mapping for this? We already tried accumulators and broadcast but looks like not very suitable. And we were not able to replace events 1 for first mapping and events 2 for second mapping with Z.

If new event 5 will come and it is similar with 3h for example we need to assign mapping 5->Z again.


Get this bounty!!!

#StackBounty: #java #spring #rest #apache-camel #resttemplate REST service call with Camel which requires authentication api called first

Bounty: 50

Camel has to call REST service for some integration, However, the REST service has one authentication api (POST api) which needs to be called first to get a token and then other subsequent api calls has to be invoked with the token embedded in header of HTTP requests.

Does Spring Restemplate or apache camel has some api to support the same?


Get this bounty!!!

#StackBounty: #java #jar Same code behaving differently on two different packaging

Bounty: 100

I have a set of codes which are common for two different products, but a part of the code is behaving differently for each product

URL wsdlURL = IntegrationLandscapeServiceWS.class.getClassLoader().getResource("IntegrationLandscapeService.wsdl");

For One set up it is giving absolute path and for the other its giving relative path and this is leading to problems, my requirement is to get absolute path for the issue.

Packaging:
enter image description here

Code flow:

The call is made from the Main Class File and from there CommonCode in common code it is looking for the WSDL located in LandScapeService.jar


Get this bounty!!!

#StackBounty: #java #android #bluetooth Bluetooth app not working on Lollipop

Bounty: 50

I made a Bluetooth app. It works fine in Nougat, Marshmallow, Jelly Bean, KitKat but for reason, it crashes in Android Lollipop when Discover button (which discovers all the discoverable devices) is clicked.

Here is the method which gets triggered on clicking Discover button –

private void discoverDevices() {
        Log.d(TAG, "btnDiscover: Looking for unpaired devices.");

        if(mBluetoothAdapter.isDiscovering()){
            mBluetoothAdapter.cancelDiscovery();
            Log.d(TAG, "btnDiscover: Canceling discovery.");

            //check BT permissions in manifest
            checkBTPermissions();

            mBluetoothAdapter.startDiscovery();
            IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND);
            registerReceiver(mBroadcastReceiver3, discoverDevicesIntent);
        }
        if(!mBluetoothAdapter.isDiscovering()){

            //check BT permissions in manifest
            checkBTPermissions();

            mBluetoothAdapter.startDiscovery();
            IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND);
            registerReceiver(mBroadcastReceiver3, discoverDevicesIntent);
        }


    }

CheckBTPermissions()-

private void checkBTPermissions() {

        if(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP){
            int permissionCheck = this.checkSelfPermission("Manifest.permission.ACCESS_FINE_LOCATION");
            permissionCheck += this.checkSelfPermission("Manifest.permission.ACCESS_COARSE_LOCATION");
            if (permissionCheck != 0) {

                this.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1001); //Any number
            }
        }else{
            Log.d(TAG, "checkBTPermissions: No need to check permissions. SDK version < LOLLIPOP.");
        }
    }

Permissions in Manifest file-

<uses-feature android:name="android.hardware.bluetooth" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />

build.gradle-

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.example.hpi5.bluetooth"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

I have not tested this app on Lollipop myself as I don’t have any device running on Android L. I got to know about the crash from a friend of mine.

Apk file
here


Get this bounty!!!

#StackBounty: #java Problem with Java while trying to upgrade packages

Bounty: 200

I’m getting this erros when trying to upgrade packages:

sudo apt upgrade awesome
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... awesome is already the newest version.
The following packages were automatically installed and are no longer required:
  ant ant-optional antlr3 aspectj default-jdk-doc javahelp2 junit junit-doc junit4 junit4-doc libantlr-java
  libantlr3-runtime-java libasm3-java libaspectj-java libatinject-jsr330-api-java libbeansbinding-java libbindex-java
  libbsh-java libbytelist-java libcdi-api-java libcglib-java libcommons-beanutils-java libcommons-codec-java
  libcommons-collections3-java libcommons-compress-java libcommons-digester-java libcommons-httpclient-java
  libcommons-io-java libcommons-lang-java libcommons-net-java libcommons-net1-java libeclipselink-java
  libequinox-osgi-java libfelix-framework-java libfelix-main-java libfreemarker-java
  libgeronimo-interceptor-3.0-spec-java libgeronimo-j2ee-connector-1.5-spec-java libgeronimo-jms-1.1-spec-java
  libgeronimo-jpa-2.0-spec-java libgeronimo-jta-1.1-spec-java libgeronimo-osgi-support-java
  libgeronimo-validation-1.0-spec-java libhamcrest-java libhamcrest-java-doc libicu4j-4.4-java libini4j-java
  libjavaewah-java libjcodings-java libjcommander-java libjemmy2-java libjgit-java libjna-java libjna-jni
  libjna-platform-java libjnlp-servlet-java libjoda-convert-java libjoda-time-java libjpa-2.1-spec-java
  libjsch-agent-proxy-java libjsch-java libjson-simple-java libjsr311-api-java libjvyamlb-java libjzlib-java
  liblucene3-contrib-java liblucene3-java libmail-java libnb-absolutelayout-java libnb-apisupport3-java libnb-ide14-java
  libnb-java5-java libnb-javaparser-java libnb-org-openide-modules-java libnb-org-openide-util-java
  libnb-org-openide-util-lookup-java libnb-platform-devel-java libnb-platform18-java libntdb1 liboro-java
  libosgi-annotation-java libosgi-compendium-java libosgi-core-java libosgi-foundation-ee-java libregexp-java
  libsdo-api-java libsequence-library-java libserf-1-1 libservlet2.5-java libservlet3.1-java libsimple-validation-java
  libsqljet-java libstringtemplate-java libstringtemplate4-java libsvn-java libsvn1 libsvnclientadapter-java
  libsvnkit-java libswing-layout-java libswingx-java libtrilead-ssh2-java libws-commons-util-java libxerces2-java
  libxml-commons-external-java libxml-commons-resolver1.1-java libyaml-snake-java linux-headers-4.2.0-16
  linux-headers-4.2.0-16-generic linux-image-4.2.0-16-generic linux-image-extra-4.2.0-16-generic openjdk-7-doc
  python-ntdb testng
Use 'apt-get autoremove' to remove them.
Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Setting up oracle-java8-installer (8u111+8u111arm-1~webupd8~0) ...
No /var/cache/oracle-jdk8-installer/wgetrc file found.
Creating /var/cache/oracle-jdk8-installer/wgetrc and
using default oracle-java8-installer wgetrc settings for it.
Downloading Oracle Java 8...
--2017-06-01 18:37:26--  http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz
Resolving download.oracle.com (download.oracle.com)... 72.247.210.9, 72.247.210.27
Connecting to download.oracle.com (download.oracle.com)|72.247.210.9|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz [following]
--2017-06-01 18:37:26--  https://edelivery.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz
Resolving edelivery.oracle.com (edelivery.oracle.com)... 23.39.104.192, 2a02:26f0:15:1:8b00::2d3e, 2a02:26f0:15:1:9100::2d3e
Connecting to edelivery.oracle.com (edelivery.oracle.com)|23.39.104.192|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz?AuthParam=1496335166_b886052f95ea6f92c97b905b0261ad04 [following]
--2017-06-01 18:37:26--  http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz?AuthParam=1496335166_b886052f95ea6f92c97b905b0261ad04
Connecting to download.oracle.com (download.oracle.com)|72.247.210.9|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-06-01 18:37:28 ERROR 404: Not Found.

download failed
Oracle JDK 8 is NOT installed.
dpkg: error processing package oracle-java8-installer (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of oracle-java8-set-default:
 oracle-java8-set-default depends on oracle-java8-installer; however:
  Package oracle-java8-installer is not configured yet.

dpkg: error processing package oracle-java8-set-default (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 oracle-java8-installer
 oracle-java8-set-default
E: Sub-process /usr/bin/dpkg returned an error code (1)

I’m on Ubuntu 15.10.


Get this bounty!!!

#StackBounty: #java #maven #tomcat Apache Tomcat Maven plugin war not found

Bounty: 100

I’m following the documentation here but I end up with a jar that doesn’t find the war to execute. Here’s the error:

java.io.FileNotFoundException: C:UsersortizjDocumentsNetBeansProjectsvalida
tion-managerValidation-Manager-Webtarget.extractwebappsROOT.war (The system
 cannot find the file specified)

For some reason the war file is not added to the jar so it fails when it’s extracting it.

ROOT.war exists and is present in the target folder.

Here’s the relevant POM contents:

<profile>
    <id>installer</id>
    <properties>
        <original.finalName>${project.build.finalName}</original.finalName>
    </properties>
    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>tomcat-run</id>
                        <goals>
                            <goal>exec-war-only</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <path>/</path>
                            <enableNaming>false</enableNaming>
                            <finalName>${original.finalName}-demo.jar</finalName>
                            <charset>utf-8</charset>
                            <httpPort>9078</httpPort>
                            <contextFile>${project.basedir}srcmainjavawebappMETA-INFcontext.xml</contextFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>


Get this bounty!!!

#StackBounty: #java #android #android-activity #screen Process the command without launching MainActivity, in Android

Bounty: 50

I am new to android and stuck at one point with my new screen off test application. I am trying to develop an Android application to turn off or lock the screen directly by clicking the app launcher icon of the application.

I am able to lock the screen with the functionality I want but with one problem. While i click on the screen lock icon in the launcher it takes around a second and then locks the screen (Time is taken by to MainActivity to launch).

I want that time delay to be removed and just wanted to process the command to lock phone when user tap on the app icon in the launcher. But am not able to figure it out.

Here is AndroidManifest.xml

<application
    android:theme="@android:style/Theme.NoDisplay"
    android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:allowBackup="true">

    <activity android:name=".MainActivity"
        android:excludeFromRecents="true"
        android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver android:name="ScreenOffAdminReceiver"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data android:name="android.app.device_admin"
            android:resource="@xml/permissions" />
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
    </receiver>

</application>

MainActivity.java

public class MainActivity extends Activity {

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        DevicePolicyManager deviceManger = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
        ComponentName compName = new ComponentName(this, ScreenOffAdminReceiver.class);
        if (deviceManger.isAdminActive(compName)) {
            deviceManger.lockNow();
            finish();
        } else {
            Intent intent = new Intent("android.app.action.ADD_DEVICE_ADMIN");
            intent.putExtra("android.app.extra.DEVICE_ADMIN", compName);
            intent.putExtra("android.app.extra.ADD_EXPLANATION", getString(R.string.devicePolicyManagerMsg));
            startActivityForResult(intent, 0);
        }
        Process.killProcess(Process.myPid());
    }
}

ScreenOffAdminReceiver.java

public class ScreenOffAdminReceiver extends DeviceAdminReceiver {
    public void onDisabled(Context context, Intent intent) {
        Toast.makeText(context, R.string.deviceAdminDisabled, Toast.LENGTH_SHORT).show();
    }

    public void onEnabled(Context context, Intent intent) {
        Toast.makeText(context, R.string.deviceAdminEnabled, Toast.LENGTH_SHORT).show();
    }
}

I just want to remove the DELAY while locking the screen. Any help will be highly appreciated. Thanks


Get this bounty!!!

#StackBounty: #java #servlets #file-upload #download #struts1 ms word file download issue in servlet from unix server to windows

Bounty: 50

While uploading doc file(example test.doc) to server(unix machine), I am using apache commons jar which gives me FormFile instance at server side which is having all the data in byte array form.

When I write the same byte array to response output stream and send it to browser to download the same file, weird content is shown. I get one pop up to select encoding in which i would like to see the data and weird data is shown in that doc.The content type is set as follows :

response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment;filename=test.doc");

I think that while writing data to output stream, meta data related to doc file is also written which causes this issue.

Is there anything specific for doc or docx file formats, which needs to be done so file is in proper format and i can see correct data which i uploaded or I am missing something?

Any help would be appreciated.

Thanks in Advance.

Let me know if more info is required.


Get this bounty!!!