cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to read field value from main table - unexpected socket read error

Former Member
0 Kudos

Hi Friends,

While executing the below code, I am able to get the value of the field 'id' but i am unable to get the value for the 'materialnumber' field. i am getting the below exception

+com.sap.mdm.commands.CommandException: com.sap.mdm.internal.protocol.manual.ProtocolException: java.io.IOException: Unexpected socket read. Result is -1.

at com.sap.mdm.data.commands.AbstractRetrieveLimitedRecordsCommand.execute(AbstractRetrieveLimitedRecordsCommand.java:158)

at com.sap.mdm.data.commands.RetrieveLimitedRecordsCommand.execute(RetrieveLimitedRecordsCommand.java:157)

at updaterecords.main(updaterecords.java:126)

Caused by: com.sap.mdm.internal.protocol.manual.ProtocolException: java.io.IOException: Unexpected socket read. Result is -1.

at com.sap.mdm.internal.protocol.manual.AbstractProtocolCommand.execute(AbstractProtocolCommand.java:100)

at com.sap.mdm.data.commands.AbstractRetrieveLimitedRecordsCommand.execute(AbstractRetrieveLimitedRecordsCommand.java:146)

... 2 more

Caused by: java.io.IOException: Unexpected socket read. Result is -1.

at com.sap.mdm.internal.net.DataSocket.receiveData(DataSocket.java:59)

at com.sap.mdm.internal.net.ConnectionImpl.readInt(ConnectionImpl.java:417)

at com.sap.mdm.internal.net.ConnectionImpl.nextMessage(ConnectionImpl.java:501)

at com.sap.mdm.internal.net.ConnectionImpl.receiveMessage(ConnectionImpl.java:472)

at com.sap.mdm.internal.net.ConnectionImpl.send(ConnectionImpl.java:209)

at com.sap.mdm.internal.net.ReservedConnection.send(ReservedConnection.java:105)

at com.sap.mdm.internal.protocol.manual.AbstractProtocolCommand.execute(AbstractProtocolCommand.java:97)

... 3 more+

import com.sap.mdm.commands.AuthenticateUserSessionCommand;

import com.sap.mdm.commands.CommandException;

import com.sap.mdm.commands.CreateUserSessionCommand;

import com.sap.mdm.commands.DestroySessionCommand;

import com.sap.mdm.commands.GetRepositoryRegionListCommand;

import com.sap.mdm.data.Record;

import com.sap.mdm.data.RegionProperties;

import com.sap.mdm.data.ResultDefinition;

import com.sap.mdm.data.commands.RetrieveLimitedRecordsCommand;

import com.sap.mdm.ids.TableId;

import com.sap.mdm.net.ConnectionException;

import com.sap.mdm.net.ConnectionPool;

import com.sap.mdm.net.ConnectionPoolFactory;

import com.sap.mdm.schema.FieldProperties;

import com.sap.mdm.schema.RepositorySchema;

import com.sap.mdm.schema.commands.GetFieldListCommand;

import com.sap.mdm.schema.commands.GetRepositorySchemaCommand;

import com.sap.mdm.search.Search;

import com.sap.mdm.server.DBMSType;

import com.sap.mdm.server.RepositoryIdentifier;

public class updaterecords {

public static void main(String[] args) {

try {

String serverName = "159.112.6.26";

ConnectionPool connections = null;

try {

connections = ConnectionPoolFactory.getInstance(serverName);

} catch (ConnectionException e) {

e.printStackTrace();

return;

}

// specify the repository to use

// alternatively, a repository identifier can be obtain from the GetMountedRepositoryListCommand

String repositoryName = "DEMO";

String dbmsName = "MDMD";

RepositoryIdentifier reposId = new RepositoryIdentifier(repositoryName, dbmsName, DBMSType.ORACLE);

// get list of available regions for the repository

GetRepositoryRegionListCommand regionListCommand = new GetRepositoryRegionListCommand(connections);

regionListCommand.setRepositoryIdentifier(reposId);

try {

regionListCommand.execute();

} catch (CommandException e) {

e.printStackTrace();

return;

}

RegionProperties[] regions = regionListCommand.getRegions();

// create a user session

CreateUserSessionCommand sessionCommand = new CreateUserSessionCommand(connections);

sessionCommand.setRepositoryIdentifier(reposId);

sessionCommand.setDataRegion(regions[0]); // use the first region

try {

sessionCommand.execute();

} catch (CommandException e) {

e.printStackTrace();

return;

}

String sessionId = sessionCommand.getUserSession();

// authenticate the user session

String userName = "meter1";

String userPassword = "meter1";

AuthenticateUserSessionCommand authCommand = new AuthenticateUserSessionCommand(connections);

authCommand.setSession(sessionId);

authCommand.setUserName(userName);

authCommand.setUserPassword(userPassword);

try {

authCommand.execute();

} catch (CommandException e) {

e.printStackTrace();

return;

}

GetRepositorySchemaCommand cmd=new GetRepositorySchemaCommand(connections);

cmd.setSession(sessionId);

try{

cmd.execute();

}catch(CommandException e){

System.out.println(e.getLocalizedMessage());

}

RepositorySchema repsch=cmd.getRepositorySchema();

// the main table, hard-coded

TableId mainTableId = new TableId(1);

// specify the result definition (what to retrieve); in this example, nothing

ResultDefinition rd = new ResultDefinition(mainTableId);

// select all records

Search search = new com.sap.mdm.search.Search(mainTableId);

//get fields

GetFieldListCommand getFieldListCommand = new GetFieldListCommand(connections);

getFieldListCommand.setSession(sessionCommand.getUserSession());

getFieldListCommand.setTableId(mainTableId);

try {

getFieldListCommand.execute();

} catch (CommandException e) {

System.out.println(e);

}

FieldProperties[] lookupFields = getFieldListCommand.getFields();

// add fields to records to retrieve

rd.addSelectField(repsch.getFieldId("Products","Id"));

rd.addSelectField(repsch.getFieldId("Products","MaterialNumber"));

// retrieve the records

RetrieveLimitedRecordsCommand limitingCommand = new RetrieveLimitedRecordsCommand(connections);

limitingCommand.setSession(sessionId);

limitingCommand.setResultDefinition(rd);

limitingCommand.setSearch(search);

//limitingCommand.setPageSize(2000);

try {

limitingCommand.execute();

} catch (CommandException e) {

e.printStackTrace();

return;

}

System.out.println("Record count is " + limitingCommand.getRecords().getCount()+"\n");

Record[] records=limitingCommand.getRecords().getRecords();

System.out.println(records[0].getFieldValue(repsch.getFieldId("Products","Id"))+ " \n");

System.out.println(records[0].getFieldValue(repsch.getFieldId("Products","MaterialNumber"))+ " \n");

// finally destroy the session

DestroySessionCommand destroySessionCommand = new DestroySessionCommand(connections);

destroySessionCommand.setSession(sessionId);

try {

destroySessionCommand.execute();

} catch (CommandException e) {

e.printStackTrace();

return;

}

} catch (Exception e) {

System.out.println(e.getLocalizedMessage());

e.printStackTrace();

}

}

}

Kindly let me know where i am going wrong. MaterialNumber field is a TEXT not a lookup table field. Above fields are from the main table.

Thanks,

Raags

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Friends,

I got the solution. It was the error because of not having a the below statement.

limitingCommand.setPageSize(1);

As i havent used that statement, it was trying to get 1000 records, and i dont know exactly what makes this to get that error. Anyhow., As i want to use for updation, i cn live with one record.

Thanks,

Raags

Former Member
0 Kudos

I don't see how setting the page size to one would help resolve the problem. The page size indicates to the server how many records to send back. It basically translate to the amount of data being send over the network.

Were there any changes besides setting the page size to one? If you can reproduce the problem consistently, I would like to look into the problem.