0

助けてください。私はRestKitを初めて使用し、RestKit .20.3を使用してかなり簡単なPOSTを正常に実行するのに何日も苦労しています。私はすべてのさまざまなサンプルと指示に従い、Alexander Edge のチュートリアルの一部と、RestKit GitHub のサンプルとドキュメントを無駄に使用しました。誰かが私のコードをざっと見て、RestKit .20.3 を使用して POST を成功させるために何ができるかについてのヒントを教えてもらえますか? 私のpostObjectが「nil」であるため、コードの最後の行に問題があると思われますが、よくわかりません。ヒントや提案をいただければ幸いです。

ところで: デバッグ ログに表示されるエラーは、"Expected status code in (400-499), got 204" です。

- (void)setupRestKitTutorial{
NSLog(@"setupRestKitTutorial - Start");

RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:getDataURL]];
//[manager setRequestSerializationMIMEType:RKMIMETypeJSON];

//[[manager HTTPClient] setDefaultHeader:@"X-Parse-REST-API-Key" value:@"inquiryData"];
//[[manager HTTPClient] setDefaultHeader:@"X-Parse-Application-Id" value:@"inquiryData"];


//Set up Request Header
[[manager HTTPClient] setDefaultHeader:@"clientAccount" value:@"6"];
[[manager HTTPClient] setDefaultHeader:@"docType" value:@"T"];
[[manager HTTPClient] setDefaultHeader:@"userId" value:@"uid01"];
[[manager HTTPClient] setDefaultHeader:@"class" value:headerClass];
[[manager HTTPClient] setDefaultHeader:@"clientCode" value:@"02"];
[[manager HTTPClient] setDefaultHeader:@"requestType" value:@"submit"];
[[manager HTTPClient] setDefaultHeader:@"token" value:@"f3a6a4dc1c8f77d79a1a1f6a5d439933"];
[[manager HTTPClient] setDefaultHeader:@"documentNum" value:@"439299827"];
[[manager HTTPClient] setDefaultHeader:@"Content-Type" value:@"application/x-www-form-urlencoded"];

//End setup Request Header


NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
manager.managedObjectStore = managedObjectStore;

RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];

[errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"errorMessage"]];

RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping
                                                                                pathPattern:nil
                                                                                    keyPath:@"error"
                                                                                statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];

[manager addResponseDescriptorsFromArray:@[errorDescriptor]];


NSDictionary *parentObjectMapping = @{
                                      @"inquiryStatus" : @"inquiryStatus",
                                      @"entityNo" : @"entityNo",
                                      @"docType" : @"docType",
                                      @"docNumber" : @"docNumber",
                                      @"mvNumber" : @"mvNumber",
                                      @"totalAmount" : @"totalAmount"
                                      };

RKEntityMapping *ticketParentMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([TicketParent class]) inManagedObjectStore:manager.managedObjectStore];
ticketParentMapping.identificationAttributes = @[ @"entityNo" ];
[ticketParentMapping addAttributeMappingsFromDictionary:@{
 @"name" : @"name"
 }];
[ticketParentMapping addAttributeMappingsFromDictionary:parentObjectMapping];


/**
 Complete Core Data stack initialization
 */

[managedObjectStore createPersistentStoreCoordinator];

NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"TicketParent.sqlite"];

NSError *error;

NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil  withConfiguration:nil options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error:&error];

NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);

// Create the managed object contexts
[managedObjectStore createManagedObjectContexts];

// Configure a managed object cache to ensure we do not create duplicate objects
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];

[manager postObject:nil path:@"http://www.mytesturl.com/jsonservices" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
    NSLog(@"We object mapped the response with the following result: %@", result);
} failure:nil];

}

これが私の更新されたコードです。私はすべての提案改造を行いましたが、次のエラーが発生しています: got 500" UserInfo=0x95c7bd0 {NSLocalizedRecoverySuggestion=Error 500: javax.servlet.ServletException: org.codehaus.jackson.map.JsonMappingException: Can not find a deserializer for non -concrete マップ型 [マップ型; クラス javax.ws.rs.core.MultivaluedMap, [単純型, クラス java.lang.String] -> [単純型, クラス java.lang.String]] 修正に関するアイデアはありますか?

- (void)setupRestKitTutorial{
NSLog(@"setupRestKitTutorial - Start");

RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:getDataURL]];
[manager setRequestSerializationMIMEType:RKMIMETypeJSON];
[manager setAcceptHeaderWithMIMEType:@"application/x-www-form-urlencoded"];
[manager setAcceptHeaderWithMIMEType:RKMIMETypeJSON];


[RKObjectManager setSharedManager:manager];
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"application/x-www-form-urlencoded"];

RKObjectMapping *userMapping = [RKObjectMapping requestMapping];
[userMapping addAttributeMappingsFromDictionary:@{@"clientAccount" : @"clientAccount",
 @"docType" : @"docType",
 @"userId" : @"userId",
 @"class1" : @"class1",
 @"clientCode" : @"clientCode",
 @"requestType" : @"requestType",
 @"token" : @"token",
 @"documentNum" : @"documentNum"}];

RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:userMapping objectClass:[RequestInquiry class]                                       rootKeyPath:nil method:RKRequestMethodPOST];

[manager addRequestDescriptor:requestDescriptor];


[[manager HTTPClient] setDefaultHeader:@"X-Parse-REST-API-Key" value:@"inquiryData"];
[[manager HTTPClient] setDefaultHeader:@"X-Parse-Application-Id" value:@"inquiryData"];


//Set up Request Header
[[manager HTTPClient] setDefaultHeader:@"clientAccount" value:@"6"];
[[manager HTTPClient] setDefaultHeader:@"docType" value:@"T"];
[[manager HTTPClient] setDefaultHeader:@"userId" value:@"uid01"];
[[manager HTTPClient] setDefaultHeader:@"class1" value:headerClass];
[[manager HTTPClient] setDefaultHeader:@"clientCode" value:@"02"];
[[manager HTTPClient] setDefaultHeader:@"requestType" value:@"submit"];
[[manager HTTPClient] setDefaultHeader:@"token" value:@"f3a6a4dc1c8f77d79a1a1f6a5d439933"];
[[manager HTTPClient] setDefaultHeader:@"documentNum" value:@"439299827"];
//[[manager HTTPClient] setDefaultHeader:@"contenttype" value:@"application/x-www-form-urlencoded"];

//End setup Request Header


NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
manager.managedObjectStore = managedObjectStore;

RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];

[errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"errorMessage"]];

RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping
                                                                                pathPattern:nil
                                                                                keyPath:@"error"
                                                                                //statusCodes:[NSIndexSet indexSetWithIndex:200]];
                                                                                statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];

[manager addResponseDescriptorsFromArray:@[errorDescriptor]];


NSDictionary *parentObjectMapping = @{
                                      @"inquiryStatus" : @"inquiryStatus",
                                      @"entityNo" : @"entityNo",
                                      @"docType" : @"docType",
                                      @"docNumber" : @"docNumber",
                                      @"mvNumber" : @"mvNumber",
                                      @"totalAmount" : @"totalAmount"
                                      };


RKEntityMapping *ticketParentMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([TicketParent class]) inManagedObjectStore:manager.managedObjectStore];
ticketParentMapping.identificationAttributes = @[ @"entityNo" ];
[ticketParentMapping addAttributeMappingsFromDictionary:@{
 @"mvType" : @"mvType"
 }];
[ticketParentMapping addAttributeMappingsFromDictionary:parentObjectMapping];


/**
 Complete Core Data stack initialization
 */

[managedObjectStore createPersistentStoreCoordinator];

NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"TicketParent.sqlite"];

NSError *error;

NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil  withConfiguration:nil options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error:&error];

NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);

// Create the managed object contexts
[managedObjectStore createManagedObjectContexts];

// Configure a managed object cache to ensure we do not create duplicate objects
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];

// Request Object with json paramaters
RequestInquiry *requestInquiry = [[RequestInquiry alloc] init];
requestInquiry.docType = @"T";
requestInquiry.documentNum = @"439299827";
requestInquiry.clientAccount = @"6";
requestInquiry.clientCode = @"02";
requestInquiry.token = @"f3a6a4dc1c8f77d79a1a1f6a5d439933";
requestInquiry.requestType = @"submit";
requestInquiry.userId = @"uid01";
requestInquiry.class1 = @"class com.rest.client.JsonRequest";

[manager postObject:requestInquiry path:@"/RestIVR/restservices/ticketservices/jinquiry" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *ticketParentMapping)
 {
     RKLogError(@"%@",ticketParentMapping);
 }
            failure:^(RKObjectRequestOperation *operation, NSError *error)
 {
     RKLogError(@"%@",error);
 }];
4

2 に答える 2

0

前述のように、POST は、渡すオブジェクトが RequestDescriptor に基づいて、指している URL にシリアル化されることを意味します。

nil は機能しません。また、RequestDescriptor を設定していません

于 2013-09-11T20:01:21.917 に答える