0

我在 Fatwire 中使用 REST API 创建新资产时遇到问题。我可以连接以读取和更新资产,但要创建我会收到一条错误消息。

你可以帮帮我吗?

我收到一个错误:

" PUT http://localfw.com.br:8080/cs/REST/sites/MySite/types/FD_Ajuda_C/assets/0?multiticket=ST-30-i3DZmlFcbbNNsdK0IwE0-cas-.com.br-1返回响应状态500"

在我的源代码下面:

package com.fatwire.rest.samples.flex;

import java.sql.Date;

import javax.ws.rs.core.MediaType;

import com.fatwire.rest.beans.AssetBean;
import com.fatwire.rest.beans.Association;
import com.fatwire.rest.beans.Associations;
import com.fatwire.rest.beans.Attribute;
import com.fatwire.rest.beans.Parent;
import com.fatwire.rest.beans.Attribute.Data;
import com.fatwire.rest.beans.Blob;
import com.fatwire.wem.sso.SSO;
import com.fatwire.wem.sso.SSOException;
import com.fatwire.wem.sso.SSOSession;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;

public final class CreateAsset
{

public static void main(String[] args)
{
    // Step 1: Initiate Jersey client
    Client client = Client.create();

    // Step 2: Create a WebResource with the base URL
    WebResource webResource =
        client.resource("http://localfw.com.br:8080/cs/REST/");

    // Step 3: Authenticate over SSO-CAS to acquire a ticket specific to a
    // service or a multi-ticket over multiple services.
    SSOSession ssoSession = null;
    String multiticket = null;
    try
    {
        ssoSession = SSO.getSSOSession("ExampleCASConfig.xml");
        multiticket = ssoSession.getMultiTicket("user", "pss");
    }
    catch (SSOException e)
    {
        e.printStackTrace();
    }

    // Step 4: Provide the ticket into the REST request
    webResource = webResource.queryParam("multiticket", multiticket);

    // Trying to create a Flex asset for the Flex asset type
    String flexAssetSiteName = "FolhaDirigida";
    String flexAssetTypeName = "FD_Ajuda_C";

    // Step 5: Specify the REST Resource URL into the WebResource
    // For creating assets of type {typename} in the CS site {sitename},
    // this is: {base_url}/sites/{sitename}/types/{typename}/assets/0
    webResource =
        webResource.path("sites").path(flexAssetSiteName).path("types")
            .path(flexAssetTypeName).path("assets").path("0");

    // Step 6: Create a Builder and set the desired response type
    // Supported response types are:
    // MediaType.APPLICATION_XML, or,
    // MediaType.APPLICATION_JSON
    Builder builder = webResource.accept(MediaType.APPLICATION_XML);

    // Step 7: Instantiate and define the AssetBean for the asset
    AssetBean sourceAsset = new AssetBean();

    // Name - mandatory field
    sourceAsset.setName("Test REST API FD_Ajuda_C");

    //sourceAsset.setId("1307037035763");        

    // Description - optional field
    sourceAsset.setDescription("Test FD_Ajuda_C description");

    // Add attributes / associations / parents as in the Asset type
    // definition
    Attribute sourceAssetAttribute = new Attribute();
    Data sourceAssetAttributeData = new Data();
    sourceAssetAttribute.setName("titulo");
    sourceAssetAttributeData.setStringValue("Test Título FD_Ajuda_C");
    sourceAssetAttribute.setData(sourceAssetAttributeData);
    sourceAsset.getAttributes().add(sourceAssetAttribute);

    sourceAssetAttribute = new Attribute();
    sourceAssetAttributeData = new Data();
    sourceAssetAttribute.setName("conteudo");
    sourceAssetAttributeData.setStringValue("Test Long Description FD_Ajuda_C");
    sourceAssetAttribute.setData(sourceAssetAttributeData);
    sourceAsset.getAttributes().add(sourceAssetAttribute);

    sourceAssetAttribute = new Attribute();
    sourceAssetAttributeData = new Data();
    sourceAssetAttribute.setName("indAtivo");
    sourceAssetAttributeData.setStringValue("FD_IndAtivo_C:1307036912210");
    sourceAssetAttribute.setData(sourceAssetAttributeData);
    sourceAsset.getAttributes().add(sourceAssetAttribute);

    Parent parent = new Parent();
    parent.setParentDefName("CategoriaAjuda");
    parent.getAssets().add("FD_Conteudo_P:1307036837080");
    sourceAsset.getParents().add(parent);

    // Required: Must specify the site(s) for the asset
    sourceAsset.getPublists().add(flexAssetSiteName);

    try{
        // Step 8: Invoke the REST request to create the asset
        AssetBean resultAsset = builder.put(AssetBean.class, sourceAsset);          
    }
    catch (UniformInterfaceException e) {
        // TODO: handle exception            
        System.out.println("Teste" + e.getResponse());
        System.out.println(" || sourceAsset: " + sourceAsset.toString());
    }


    // If the REST call encounter a server side exception, the client
    // receives a UniformInterfaceException at runtime.


    // Troubleshooting UniformInterfaceException
    // =========================================
    //
    // Cause: HTTP 403: User does not have permission to access the REST
    // resource.
    // Remedy: Use an authorized CAS user to use this REST resource.
    //
    // Cause: HTTP 404: Either site and/or asset type does not exist, or the
    // asset type is not enabled in the site.
    // Remedy: Verify existence of the site and/or asset type, if necessary
    // create the site and/or type and make sure that the type is enabled in
    // the site.
    //
    // Cause: HTTP 500: Generic server side exception.
    // Remedy: Verify that the source AssetBean has been provided with all
    // mandatory attributes, associations as per type definition, verify
    // that at least one site has been provided in the publist attribute of
    // the AssetBean.
    //
    // Cause: UnmarshalException.
    // Remedy: Verify that the correct bean has been provided in the
    // argument for put().
}
}
4

1 回答 1

0
  • 验证源 AssetBean 是否已根据类型定义提供了所有必需的属性、关联
  • 验证 AssetBean 的 publist 属性中是否至少提供了一个站点
于 2012-07-03T10:25:11.170 回答