You need to sign in to do that
Don't have an account?
GABRIEL SILVA
call web service method from java and limit conection
Hello,
I'm trying to call my Apex web service method from java. The jar file was generated with enterprise.wsdl and wsc-39.0.4.jar. I created a simple java application and imported both jar files.
This is my simple web service on Apex:
I created a class in java to connect with my org. Here it is:
After running the application, I noticed that I have all the permissions on org, but I just want to connect with my web service and not have full access. How can i call WS method and block access to other things?
I'm trying to call my Apex web service method from java. The jar file was generated with enterprise.wsdl and wsc-39.0.4.jar. I created a simple java application and imported both jar files.
This is my simple web service on Apex:
global class webServiceBiel{ WebService static integer soma(integer a, integer b){ return a+b; } }
I created a class in java to connect with my org. Here it is:
import com.sforce.soap.enterprise.Connector; import com.sforce.soap.enterprise.EnterpriseConnection; import com.sforce.soap.enterprise.QueryResult; import com.sforce.soap.enterprise.sobject.Account; import com.sforce.soap.enterprise.sobject.SObject; import com.sforce.ws.ConnectionException; import com.sforce.ws.ConnectorConfig; import java.util.List; import java.util.Arrays; public class Main { static final String USERNAME = "gabriel.silva.dph@delphos.com.br.desenv"; static final String PASSWORD = "Apex7410Z6iLE5wLGxxYbZsUY62U7lPC"; static EnterpriseConnection connection; public static void main(String[] args) { ConnectorConfig config = new ConnectorConfig(); config.setUsername(USERNAME); config.setPassword(PASSWORD); try { connection = Connector.newConnection(config); System.out.println("Auth EndPoint: " + config.getAuthEndpoint()); System.out.println("Service EndPoint: " + config.getServiceEndpoint()); System.out.println("Username: " + config.getUsername()); System.out.println("SessionId: " + config.getSessionId()); Biel_getContas(); } catch (ConnectionException e1) { e1.printStackTrace(); } } private static void Biel_getContas() { Account conta; System.out.println("Buscando as contas existentes..."); try { QueryResult queryResults = connection.query("SELECT Id, Name FROM Account"); if (queryResults.getSize() > 0) { List<SObject> contas = Arrays.asList(queryResults.getRecords()); for (SObject obj : contas) { conta = (Account) obj; System.out.println("ID = "+conta.getId()); System.out.println("Name = "+conta.getName()); } } } catch (Exception e) { e.printStackTrace(); } } }
After running the application, I noticed that I have all the permissions on org, but I just want to connect with my web service and not have full access. How can i call WS method and block access to other things?
Remove "“API Enabled" permission to stop the connection. If you wanted to limit the data you can remove the object permission on the profile.
Thanks ,
Raj
My class now:
The found error: