BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-22-2008, 04:13 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2008
Model: 7100T
PIN: N/A
Carrier: Vodafone
Posts: 15
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default user credentials for webservice

Please Login to Remove!

hi i using ksoap to invoke the service.its working fine.now i need to give username n password since security is enabled for the service.wats the code for that



//package org.ksoap2.samples.quotes;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import org.ksoap2.*;
import org.ksoap2.transport.*;
import org.ksoap2.serialization.*;


public class StockQuoteDemo extends MIDlet implements CommandListener, Runnable {

Form mainForm = new Form("Create");
TextField symbolField = new TextField("Oppurtunity_ID:", "", 5, TextField.ANY);
StringItem resultItem = new StringItem("", "");
Command getCommand = new Command("Fetch", Command.SCREEN, 1);

public StockQuoteDemo() {
mainForm.append(symbolField);
mainForm.append(resultItem);
mainForm.addCommand(getCommand);
mainForm.setCommandListener(this);
}

public void startApp() {
Display.getDisplay(this).setCurrent(mainForm);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void run(){
try {
// build request string
String symbol = symbolField.getString();


// Create SOAP object.This will contain your webservice request
SoapObject rpc = new SoapObject("http://xmlns.oracle.com/Enterprise/Tools/schemas/M676127.V1", "Get__CompIntfc__SC_HANDHELD_CI");

// Lets assume, the SOAP Request contains following data:
// a 'String' data as Opportunity id.
rpc.addProperty("OPPORTUNITY_ID", symbol);
// rpc.addProperty("IntData", new Integer(10));

//Now, lets make SOAP envelope
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;

// Making webservice call
HttpTransport http = new HttpTransport("http://172.16.186.86:12345/PSIGW/PeopleSoftServiceListeningConnector/PSFT_CR/CI_SC_HANDHELD_CI.1.wsdl");
http.call("Get1.V1", envelope);

SoapObject result = (SoapObject)envelope.bodyIn;
resultItem.setLabel("Result:");
resultItem.setText(result.getProperty("OPPORTUNITY _NAME")+" "+result.getProperty("PERSON_ID")+" "+result.getProperty("OPPORTUNITY_ID"));

}
catch (SoapFault sf){
resultItem.setLabel("FAULT:\n");
String faultString = "Code: " + sf.faultcode + "\nString: " + sf.faultstring;
resultItem.setText(faultString);

}
catch (Exception e) {
e.printStackTrace();
resultItem.setLabel("Error:");
resultItem.setText(e.toString());
}


}


public void commandAction(Command c, Displayable d) {
new Thread(this).start();
}

/** for me4se */

public static void main(String[] argv) {
new StockQuoteDemo().startApp();
}
}
Offline  
Old 04-23-2008, 07:37 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The easiest way is to modify the HttpTransport class of kSOAP to support basic authentication. BUT in this case you have to use SSL / HTTPS connection, otherwise it is a serious security problem...

add additional header to your connection in HttpTransport:
PHP Code:
...
connection.setRequestProperty("Authorization""Basic " login);
... 
login is a String that has to be Base64 encoded and that could be passed as a paramter to the call() function.

PHP Code:
...
String login username ":" password;
//Encode the login information in Base64 format.
String login_encoded Base64OutputStream.encodeAsString(login.getBytes(),0,login.length(),false,false);

... 
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.