How to handle `SOAPFault` when `SOAPConnection.call` throws an exception in Java?

I’m using javax.xml.soap classes to handle SOAP communication. Now I want to handle SOAPFailt, but a call of SOAPConnection.call throws an exception instead of returning the response. The server returns fault message , but with the HTTP status 400, which is probably the cause of this:

com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (400Bad Request

Reading the SOAP 1.2 specification I’ve found that the server should return HTTP status 500 instead. Now, I can’t change the server behavior (I’m using the ‘happytime’ simulation server for the development), but can I do something to make ‘SOAPConnection.call’ to return the response instead to throw an exception?

How to force a subclass to provide specific data within an overridden method

I have a base class called Feature, and another two classes Feature1 which is extension to the base calss.
in other words, Feature1 extends Feature as shown in the code.

what i want to do is, since feature1 extends the base Feature class it should override the capture() method, but what i want to do also is,
to force feature1 also to provide a variable called captureId within the capture() method. which mean I want to force each feature extends Feature class
must privide captureId within the overriden capture() method

code:

class Feature {
...
...
...

public void capture() {

}
}

class Feature1 extends Feature {
...
...
...
//override
public void capture() {
//captureId must be mandatory to be provided by each class extends Feature
}
}

JPA (Hibernate): “ORA-02289 Sequence does not exist”, but it does

I’m working with JPA entities.

I created a new one like this:

@Entity
public class Entity {
    @Id
    @GeneratedValue(generator = "Entity_Sequence", strategy = GenerationType.SEQUENCE)
    @SequenceGenerator(name = "Entity_Sequence", sequenceName = "Entity_Seq")
    private Long id;

    // ... other fields
}

Generated SQL I used to create DB Objects:

CREATE SEQUENCE ENTITY_SEQ START WITH 1 INCREMENT BY 50;

CREATE TABLE ENTITY (
  ID     NUMBER(19, 0) NOT NULL,
  -- ... other fields
  PRIMARY KEY (ID)
);

Now, I am able to query the nextval of the sequence from SQL Developer and from IntelliJ, but Hibernate throws the following exception:

15:21:11,022 INFO  [stdout] (EJB default - 2) Hibernate: select ENTITY_SEQ.nextval from dual
15:21:11,037 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 2) SQL Error: 2289, SQLState: 42000
15:21:11,037 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 2) ORA-02289: Sequence ist nicht vorhanden.

(“Sequence ist nicht vorhanden” translates to “Sequence does not exist”.)

Why is Hibernate not able to find the sequence while I am?

Sample code use for (moa PairedLearners)

Hello I am new into using MOA and WEKA,

I need to test paired learners concept using this code and I have been able to locate the code but I cannot find any example online and
I am having a hard time figuring how to pas my data into the code and run a test and see my results.
Pls can anyone point my in a right direction or give me a few pointers that I could follow to implement this.

moa/moa/src/main/java/moa/classifiers/meta/PairedLearners.java

Best Regards.

GOOGLE_APPLICATION_CREDENTIALS dosn`t work in JAVA

I try to use Google Speach Api

and I have big problem witch authentication.

I fallow this tutorial, and i export GOOGLE_APPLICATION_CREDENTIALS, and i check it use echo, and all ok.

But when I start code from first link I get error:

Exception in thread "main" java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:119)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:127)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:100)
at com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:53)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:110)
at com.google.cloud.speech.v1.stub.GrpcSpeechStub.create(GrpcSpeechStub.java:93)
at com.google.cloud.speech.v1.SpeechSettings.createStub(SpeechSettings.java:128)
at com.google.cloud.speech.v1.SpeechClient.<init>(SpeechClient.java:143)
at com.google.cloud.speech.v1.SpeechClient.create(SpeechClient.java:125)
at com.google.cloud.speech.v1.SpeechClient.create(SpeechClient.java:117)
at com.example.speech.QuickstartSample.main(QuickstartSample.java:58)

Ofcourse i chcek path in environment variable, even i get this file chmod 777, and nothing help.

anyone have similar problem?

Java – Sort an array with Extreme Minimum or maximun values

I want to get the maximum or minimum values from an Arraylist.

For example I have follwing values in my Arraylist,
1.22 , 2.55 , 6.00 , 3.00 , 4.77 , 9.88 , 7.23 , 8.22

I would like to get it sorted like

9.88, 1.22 , 8.22 , 2.55 , 7.45 … … …

Currently i am sorting the values in decessending order using following code,

Collections.sort(characterPairs, new Comparator<Pair<String, Double>>() {

        @Override
        public int compare(Pair<String, Double> o1, Pair<String, Double> o2) {
            if(o1.second>o2.second)
                return -1;
            if(o1.second<o2.second)
                return 1;
            return 0;
        }
    });

Attempt to invoke virtual method-FAILURE : App Crashed

Blockquote–> While trying to run the app , it crashes and says that “Attempt to invoke virtual method” ..
below is the error found in the logcat.

FATAL EXCEPTION: main
                                                                          Process: com.example.sayantan.moviebugs, PID: 1694
                                                                          java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.example.sayantan.moviebugs.model.MoviesResponse.getResults()' on a null object reference
                                                                              at com.example.sayantan.moviebugs.MainActivity$2.onResponse(MainActivity.java:132)
                                                                              at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
                                                                              at android.os.Handler.handleCallback(Handler.java:739)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:168)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5885)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)

Blockquote–> Below is the Json code snippet from main_activity.java file:

eCall<MoviesResponse> call = apiService.getPopularMovies(BuildConfig.THE_MOVIE_DB_API_TOKEN);
        call.enqueue(new Callback<MoviesResponse>() {
            @Override
            public void onResponse(Call<MoviesResponse> call, Response<MoviesResponse> response) {
                List<Movie> movies = response.body().getResults();

                //Collections.sort(movies, Movie.BY_NAME_ALPHABETICAL);
                recyclerView.setAdapter(new MoviesAdapter(getApplicationContext(), movies));
                recyclerView.smoothScrollToPosition(0);
                if (swipeContainer.isRefreshing()){
                    swipeContainer.setRefreshing(false);
                }

Blockquote–>Below is the snippet from the model file :

  public void setPage(int page) {
    this.page = page;
}

public List<Movie> getResults()
{
    return results;
}

public List<Movie> getMovies() {
    return results;
}

public void setResults(List<Movie> results) {
    this.results = results;
}

Instanciation depending on type, generics, inheritance or both?

I have a method instanciating a specific class depending on type send as parameter of this method. This works perfectly but I really don’t like this if(c == class_name.class) way to deal with this and I’m pretty sure there is a better way to do this using generics and inheritance. The method I use looks (maybe mistakenly…) dirty to me.

I followed several tutorials regarding generics and inheritance but even if I think I more or less understand these two concepts separately I’m strugling understanding the mix of both… And I think these both concepts could resolve my problem once mixed. Could anybody show me the right track to follow, generics, inheritance, both or keep my code like this. Is there a better way to do this ?

This is my actual method :

private void addData(String csvFile, char separator, Class<?> c) {
        int lineNumber = 1;
        CSVReader reader;

        try {
            reader = new CSVReader(new InputStreamReader(getAssets().open(csvFile)), separator);
            String[] line;

            realm.beginTransaction();
            if(c == FlagDef.class) {
                while ((line = reader.readNext()) != null) {
                    FlagDef flagDef = new FlagDef(Long.parseLong(line[0]), line[1], line[2]);
                    Log.d(TAG, String.format("%s %s %s", line[0], line[1], line[2]));
                    realm.copyToRealm(flagDef);
                    lineNumber++;
                }
            }
            if(c == Picture.class) {
                while ((line = reader.readNext()) != null) {
                    Picture picture = new Picture(Long.parseLong(line[0]), line[1]);
                    Log.d(TAG, String.format("%s %s", line[0], line[1]));
                    realm.copyToRealm(picture);
                    lineNumber++;
                }
            }
            realm.commitTransaction();

            reader.close();
        } catch (FileNotFoundException ex) {
            Log.e(TAG, String.format("File %s not found : %s", csvFile, ex));
        } catch (IOException ex) {
            Log.e(TAG, String.format("Error parsing line number %s : %s", lineNumber, ex));
        }
    }

How can execute a sequence in JpaRepository?

how can execute a sequence in JpaRepository?

and then read the id from the Entity.

public interface EmailRepository extends JpaRepository<Email, Long> {

}

emailService.persistEmail(from, to, subject, content);
    @Inject
    private EmailRepository emailRepository;

    @Transactional
    public void persistEmail(String mailFrom, String mailTo, String subject, String content) {
        Email email = new Email(mailFrom, mailTo, content, subject);
        Email persisted = emailRepository.save(email);
        persisted.getId();
        log.debug("Persisted Information for Mail: {}", persisted.getMailFrom());
    }

i can’t persist because the id is null. Any ideas