0

Maybe it's because I'm not to android development - but I don't understand the difference between the two ways that I add parameters.

Is String[] not a String?

For example if i run my void onclick below. The webservice works as intended

public void onClick(View v) {
    new Thread() {
        @Override
        public void run() {//Create request
            try {


                //start SoapObject
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                /*List<String> ArgumentPipeValue = new ArrayList<String>();
                ArgumentPipeValue.add("_caseId|apples");
                for (String arg : ArgumentPipeValue) {
                    String[] splitArgs = arg.split("|");
                     request.addProperty(splitArgs[0],splitArgs[1]);;


                    }*/
                request.addProperty("_caseId", "apples");
                //create the envelope
                SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);
                //Needed to make the internet call
                HttpTransportSE androidHttpTransport = getHttpTransportSE();
                //this is the actual part that will call the webservice
                androidHttpTransport.call(SOAP_ACTION, envelope);

                //SoapObject soapResponse = (SoapObject) envelope.getResponse();
                SoapPrimitive results = (SoapPrimitive)envelope.getResponse();




            } catch (Exception e) {
                e.printStackTrace();
                Log.w("myApp", e.getMessage());
                Log.w("myApp", e.getCause());

            }


        }
    }.start();
}

However if I run the webservice the way below I get the error Unexpected token (position:TEXT Bad Request@1:12 in java.io.InputStreamReader@3709d6f6)

 public void onClick(View v) {
    new Thread() {
        @Override
        public void run() {//Create request
            try {


                //start SoapObject
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                List<String> ArgumentPipeValue = new ArrayList<String>();
                ArgumentPipeValue.add("_caseId|apples");
                for (String arg : ArgumentPipeValue) {
                    String[] splitArgs = arg.split("|");
                     request.addProperty(splitArgs[0],splitArgs[1]);


                    }
                //request.addProperty("_caseId", "apples");
                //create the envelope
                SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);
                //Needed to make the internet call
                HttpTransportSE androidHttpTransport = getHttpTransportSE();
                //this is the actual part that will call the webservice
                androidHttpTransport.call(SOAP_ACTION, envelope);

                //SoapObject soapResponse = (SoapObject) envelope.getResponse();
                SoapPrimitive results = (SoapPrimitive)envelope.getResponse();




            } catch (Exception e) {
                e.printStackTrace();
                Log.w("myApp", e.getMessage());
                Log.w("myApp", e.getCause());

            }


        }
    }.start();
}

The only difference is I'm adding the property via request.addProperty("_caseId", "apples"); instead of request.addProperty(splitArgs[0],splitArgs[1]);

What am I missing? why does this happen?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
JL1
  • 309
  • 2
  • 18

2 Answers2

0

In Java, a String[] is not a String (however, calling String[int] yields a String). But, pipe is a special regex character. You need to escape it in in your split. Like,

String[] splitArgs = arg.split("\\|");
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0
String[] split = argString.split("\\|");

You can then do

for(String s : split){
   System.out.println(s);
}