6

I am trying to publish a component using core services in Java but on running the code, I am getting this error :-

Exception in thread "main" com.sdltridion.contentmanager.coreservice.ICoreServicePublishCoreServiceFaultFaultFaultMessage: Value cannot be null. Parameter name: publishInstruction.ResolveInstruction.

Here's my code

         ReadOptions readOptions = new ReadOptions();

    ArrayOfstring componentsArray=new ArrayOfstring();
    componentsArray.getString().add("tcm:1010-2312-16");


    ArrayOfstring publicationTarget=new ArrayOfstring();
    publicationTarget.getString().add("tcm:0-2-65537");

    PublishInstructionData publishInstructionData = new PublishInstructionData();
    ResolveInstructionData resolveInstructionData = new ResolveInstructionData();
    resolveInstructionData.setIncludeChildPublications(false);


    JAXBElement<ResolvePurpose> resolvePurpose =    new JAXBElement<ResolvePurpose>(new QName("http://www.sdltridion.com/ContentManager/R6","Purpose"), ResolvePurpose.class, ResolvePurpose.PUBLISH);
    resolveInstructionData.setPurpose(resolvePurpose);


    JAXBElement<ResolveInstructionData> jaxbElement =    new JAXBElement<ResolveInstructionData>(new QName("http://www.sdltridion.com/ContentManager/CoreService/2011","com.sdltridion.contentmanager.coreservice._2011.Publish"), ResolveInstructionData.class, resolveInstructionData);
    publishInstructionData.setResolveInstruction(jaxbElement);

     RenderInstructionData renderInstructionData = new RenderInstructionData();


      JAXBElement<RenderMode> renderMode =    new JAXBElement<RenderMode>(new QName("http://www.sdltridion.com/ContentManager/R6","RenderMode"), RenderMode.class, RenderMode.PUBLISH);
      renderInstructionData.setRenderMode(renderMode);

    JAXBElement<RenderInstructionData> renderInstruction =    new JAXBElement<RenderInstructionData>(new QName("http://www.sdltridion.com/ContentManager/CoreService/2011","com.sdltridion.contentmanager.coreservice._2011.Publish"), RenderInstructionData.class, renderInstructionData);



  publishInstructionData.setRenderInstruction(renderInstruction);




      ArrayOfPublishTransactionData ad= endpoint.publish(componentsArray, publishInstructionData, publicationTarget, PublishPriority.LOW, readOptions);
6

Looking at your implementation, publishinstructiondata has two main objects: ResolveInstructionData and RenderInstruction.

In your implementation, you have created object for ResolveInstructionData however you are missing RenderInstruction object. That could be reason the publishing is not working.

|improve this answer|||||
  • I have already tried adding the RenderInstruction but it did'nt work as I always get the same exception which I have pointed above. – Ankur Dec 16 '16 at 9:14
  • RenderInstructionData renderInstructionData = new RenderInstructionData(); @SuppressWarnings("unchecked") JAXBElement<RenderInstructionData> jaxbElement1 = new JAXBElement<RenderInstructionData>(new QName("sdltridion.com/ContentManager/CoreService/…), RenderInstructionData.class, renderInstructionData); publishInstructionData.setRenderInstruction(jaxbElement1); – Ankur Dec 16 '16 at 9:20
  • 1
    For ResolveInstructionData you also need to setPurpose, probably to ResolvePurpose.PUBLISH; and for the RenderInstructionData you need to set a RenderMode, again, probably to RenderMode.PUBLISH. You may also find yatb.mitza.net/2012/12/a-core-service-java-client.html useful if you want to unwrap the JAXB elements. – Dave Forber Dec 16 '16 at 21:40
  • Thanks for your answer Dave, but the recommendation by you doesn't seems to work. I have updated my code and still getting the same error as I have mentioned above. – Ankur Dec 19 '16 at 7:34
5

I think this is mainly a question on how to construct a proper SOAP request in general in Java (using JAXB?)

I recommend to enable WCF Tracing in the Core Service (there are comments in webservices/web.config on how to do that). This allows you to see the SOAP request sent to the Core Service to check what's in there and what's not.

|improve this answer|||||
  • Well I have already made many SOAP request using JAXB to get the data from the CMS using core-services. I want to know here, if there's something I am missing or the way of doing this is not correct ?? – Ankur Dec 16 '16 at 12:17
  • 1
    The answer to that question is most probably "yes", but I can't tell you what the issue is exactly. I just hope that the WCF Trace helps you analyzing the problem. – Rick Pannekoek Dec 16 '16 at 12:20
0

Just adding this answer here since there was no accepted answer and might help people. The namespace URI and the service name used for the QName objects are incorrect for ResolvePurpose, ResolveInstruction and RenderInstruction.

To get the publish to work, I had to use the right namespace URIs and the service names. Something like this should work:

public class PublishService {   
    private static final QName RENDER_MODE_Q_NAME = 
                 new QName("http://www.sdltridion.com/ContentManager/R6", "RenderMode");
    private static final QName RESOLVE_PURPOSE_Q_NAME = 
                 new QName("http://www.sdltridion.com/ContentManager/R6", "ResolvePurpose");
    private static final QName RESOLVE_INSTRUCTION_DATA_Q_NAME = 
                 new QName("http://www.sdltridion.com/ContentManager/R6", "ResolveInstruction");
    private static final QName RENDER_INSTRUCTION_DATA_Q_NAME = 
                 new QName("http://www.sdltridion.com/ContentManager/R6", "RenderInstruction");

    public void publish() throws ICoreServiceGetApiVersionCoreServiceFaultFaultFaultMessage, 
                 ICoreServiceGetDefaultDataCoreServiceFaultFaultFaultMessage, 
                 ICoreServiceCreateCoreServiceFaultFaultFaultMessage,
                 ICoreServicePublishCoreServiceFaultFaultFaultMessage  {
        CoreService201603 coreService = new CoreService201603();
        ICoreService coreServiceClient = coreService.getBasicHttp();

        ArrayOfstring targetIdsArrString = new ArrayOfstring();
        targetIdsArrString.getString().add("tcm:0-20-65538");

        List<String> itemsToPublish = new ArrayList<String>();
        itemsToPublish.add("tcm:150-1365-512");

        ArrayOfstring itemsToPublishArrString = new ArrayOfstring();
        itemsToPublishArrString.getString().addAll(itemsToPublish);


        JAXBElement<RenderMode> renderModeJaxElement = 
                new JAXBElement<RenderMode>(RENDER_MODE_Q_NAME, RenderMode.class, RenderMode.PUBLISH);
        RenderInstructionData renderInstructionData = new RenderInstructionData();
        renderInstructionData.setRenderMode(renderModeJaxElement);

        JAXBElement<ResolvePurpose> resolvePurposeJaxElement = 
                new JAXBElement<ResolvePurpose>(RESOLVE_PURPOSE_Q_NAME, ResolvePurpose.class, ResolvePurpose.PUBLISH);
        ResolveInstructionData resolveInstructionData = new ResolveInstructionData();
        resolveInstructionData.setPurpose(resolvePurposeJaxElement);

        JAXBElement<RenderInstructionData> renderInstructionDataJaxElement = 
                new JAXBElement<RenderInstructionData>(RENDER_INSTRUCTION_DATA_Q_NAME, RenderInstructionData.class, renderInstructionData);
        JAXBElement<ResolveInstructionData> resolveInstructionDataJaxElement = 
                new JAXBElement<ResolveInstructionData>(RESOLVE_INSTRUCTION_DATA_Q_NAME, ResolveInstructionData.class, resolveInstructionData);

        PublishInstructionData publishInstructionData = new PublishInstructionData();
        publishInstructionData.setRenderInstruction(renderInstructionDataJaxElement);
        publishInstructionData.setResolveInstruction(resolveInstructionDataJaxElement);

        coreServiceClient.publish(itemsToPublishArrString, publishInstructionData, targetIdsArrString, PublishPriority.NORMAL, new ReadOptions());
    }
}

We can view how the SOAP body should look like and the namespaces and the service names to be used by loading up the WSDL in a tool like SoapUI.

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.