Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
fatwirerestapi_Api_Rest_Content Management System_Fatwire - Fatal编程技术网

fatwirerestapi

fatwirerestapi,api,rest,content-management-system,fatwire,Api,Rest,Content Management System,Fatwire,我在Fatwire中使用RESTAPI创建新资产时遇到问题。我可以连接到读取和更新资产,但要创建资产,我收到一条错误消息 你能帮我吗 我收到一个错误: “PUT返回的响应状态为500” 下面是我的源代码: package com.fatwire.rest.samples.flex; import java.sql.Date; import javax.ws.rs.core.MediaType; import com.fatwire.rest.beans.AssetBean; import

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

你能帮我吗

我收到一个错误:

“PUT返回的响应状态为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().
}
}
  • 验证源AssetBean是否已随所有 根据类型定义的强制性属性和关联
  • 验证的publist属性中至少提供了一个站点 资产净值

您可以发布futuretense日志中的异常堆栈跟踪吗?