0

So far, what I thought I could do was, in the Webservice, return info as byte[], so I have an ArrayList of Questions which is a class I made that has 5 byte[] as follows:

public class Question {

private byte[] question;
private byte[] correctAnswer;
private byte[] answer1;
private byte[] answer2;
private byte[] answer3;

public Question(){
}

public void setQuestion(byte[] question) {
    this.question = question;
}

public void setCorrectAnswer(byte[] correctAnswer) {
    this.correctAnswer = correctAnswer;
}

public void setAnswer1(byte[] answer1) {
    this.answer1 = answer1;
}

public void setAnswer2(byte[] answer2) {
    this.answer2 = answer2;
}

public void setAnswer3(byte[] answer3) {
    this.answer3 = answer3;
}

public byte[] getQuestion() {
    return question;
}

public byte[] getCorrectAnswer() {
    return correctAnswer;
}

public byte[] getAnswer1() {
    return answer1;
}

public byte[] getAnswer2() {
    return answer2;
}

public byte[] getAnswer3() {
    return answer3;
}
}

Webservice method that returns the arraylist:

public ArrayList<Question> GetQuestions() {
    ArrayList<Question> questions = new ArrayList();
    try {
        connection = DriverManager.getConnection("jdbc:mysql://" + DBIP + "/" + DBName + "?user=" + DBUser + "&password=" + DBPassword);

        String query
                = "SELECT * FROM questions;";

        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {
            Question question = new Question();

            question.setQuestion(rs.getString("question").getBytes());
            question.setCorrectAnswer(rs.getString("correctAnswer").getBytes());
            question.setAnswer1(rs.getString("answer1").getBytes());
            question.setAnswer2(rs.getString("answer2").getBytes());
            question.setAnswer3(rs.getString("answer3").getBytes());

            questions.add(question);
        }
        stmt.close();
        connection.close();

    } catch (SQLException ex) {
        System.out.println(ex);
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(DataBaseManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    return questions;
}

Android app method that is getting the SOAP Response:

                SoapObject request = new SoapObject( NAMESPACE, METHOD_NAME );

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11 );

    envelope.setOutputSoapObject( request );

    HttpTransportSE androidHttpTransport = new HttpTransportSE( URL );

    androidHttpTransport.call( SOAP_ACTION, envelope );

    SoapObject response = ( SoapObject ) envelope.getResponse();

    for ( int i = 0; i < response.getPropertyCount(); i++ ) {
        Question question = new Question();

        question.setQuestion(response.getProperty( "question" ).toString());
        question.setAnswer1(response.getProperty( "question" ).toString());
        question.setAnswer2(response.getProperty( "question" ).toString());
        question.setAnswer3(response.getProperty( "question" ).toString());
        question.setCorrectAnswer(response.getProperty( "question" ).toString());

        questions.add( question );
    }

With this in mind, I wanted to receive this ArrayList on my Android app and decode the bytes to strings there, but I'm having an issue with the SOAP Response I get, I can only get it as a string, so I get a string representing the bytes and I can't decode that since its already in string form

Is there a way to decode a String to a string pretty much?

Gawhisper
  • 21
  • 2
  • Check this out (https://stackoverflow.com/questions/25149528/how-to-convert-soapbody-to-string) – ucMedia Jul 06 '17 at 00:28
  • Also check this (https://stackoverflow.com/questions/5828091/decode-string-encoded-in-utf-8-format-in-android) – ucMedia Jul 06 '17 at 00:38
  • @ucMedia taking a look at it, but I'm afraid I'm too much of a beginner to fully understand what is going on, thank you very much nonetheless – Gawhisper Jul 06 '17 at 01:03

0 Answers0