<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic 401 error with AtomPubBinding in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/401-error-with-atompubbinding/m-p/23226#M10147</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;New to Alfresco.&lt;/P&gt;&lt;P&gt;This code works when run as Java main method, but throws 401 (unauthorized) error, when run as Java web script.&lt;/P&gt;&lt;P&gt;It happens with the server running in local Windows machine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With AtomPub:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom&amp;quot;" title="http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom&amp;quot;" rel="nofollow noopener noreferrer"&gt;http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom"&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public Session getSession() {&lt;/P&gt;&lt;P&gt;if (session == null) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp;SessionFactory factory = SessionFactoryImpl.newInstance();&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Map&amp;lt;String, String&amp;gt; parameter = new HashMap&amp;lt;String, String&amp;gt;();&lt;BR /&gt;&amp;nbsp; &amp;nbsp;// user credentials&lt;BR /&gt;&amp;nbsp; &amp;nbsp;parameter.put(SessionParameter.USER, "admin");&lt;BR /&gt;&amp;nbsp; &amp;nbsp;parameter.put(SessionParameter.PASSWORD, "admin");&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp;// connection settings&lt;BR /&gt;&amp;nbsp; &amp;nbsp;parameter.put(SessionParameter.ATOMPUB_URL, getServiceUrl());&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;List&amp;lt;Repository&amp;gt; repositories = factory.getRepositories(parameter);&lt;BR /&gt;&amp;nbsp; &amp;nbsp;this.session = repositories.get(0).createSession();&lt;BR /&gt; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp;return this.session;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The web script code is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;webscript&amp;gt;&lt;BR /&gt; &amp;lt;shortname&amp;gt;Get documents&amp;lt;/shortname&amp;gt;&lt;BR /&gt; &amp;lt;description&amp;gt;Return documents &amp;lt;/description&amp;gt;&lt;BR /&gt; &amp;lt;url&amp;gt;/getDocuments&amp;lt;/url&amp;gt;&lt;BR /&gt; &amp;lt;format default="json"&amp;gt;extension&amp;lt;/format&amp;gt;&lt;BR /&gt; &amp;lt;authentication runas="admin"&amp;gt;none&amp;lt;/authentication&amp;gt;&lt;BR /&gt; &amp;lt;!--&amp;lt;transaction&amp;gt;required&amp;lt;/transaction&amp;gt;--&amp;gt;&lt;BR /&gt;&amp;lt;/webscript&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public class MyDocumentSearchWebScript extends AbstractWebScript{&lt;/P&gt;&lt;P&gt;@Override&lt;BR /&gt; public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {&lt;BR /&gt; try&lt;BR /&gt; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp;// This is where I have more code to call a service, which will return JSON response&lt;BR /&gt; }&lt;BR /&gt; catch(Exception e)&lt;BR /&gt; {&lt;BR /&gt; throw new WebScriptException("Unable to serialize JSON");&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inside the code, I get 401 error code in the variable resp in internal code of Alfresco.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;protected Response read(UrlBuilder url) {&lt;BR /&gt; // make the call&lt;BR /&gt; Response resp = getHttpInvoker().invokeGET(url, session);&lt;/P&gt;&lt;P&gt;// check response code&lt;BR /&gt; if (resp.getResponseCode() != 200) {&lt;BR /&gt; throw convertStatusCode(resp.getResponseCode(), resp.getResponseMessage(), resp.getErrorContent(), null);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;return resp;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The password and user ID of admin/admin are correct.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 Mar 2017 22:25:56 GMT</pubDate>
    <dc:creator>raghav</dc:creator>
    <dc:date>2017-03-20T22:25:56Z</dc:date>
    <item>
      <title>401 error with AtomPubBinding</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/401-error-with-atompubbinding/m-p/23226#M10147</link>
      <description>New to Alfresco.This code works when run as Java main method, but throws 401 (unauthorized) error, when run as Java web script.It happens with the server running in local Windows machine.With AtomPub:http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom"&amp;nbsp;public Session getSessio</description>
      <pubDate>Mon, 20 Mar 2017 22:25:56 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/401-error-with-atompubbinding/m-p/23226#M10147</guid>
      <dc:creator>raghav</dc:creator>
      <dc:date>2017-03-20T22:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: 401 error with AtomPubBinding</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/401-error-with-atompubbinding/m-p/23227#M10148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why do you need to use CMIS from inside a Java-backed web script? Just inject the services you need (like NodeService, SearchService, etc.) and use those services (aka, the Alfresco Foundation API) to hit Alfresco natively.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is your web script running on the repository tier or the Share tier?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Mar 2017 18:50:36 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/401-error-with-atompubbinding/m-p/23227#M10148</guid>
      <dc:creator>jpotts</dc:creator>
      <dc:date>2017-03-24T18:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: 401 error with AtomPubBinding</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/401-error-with-atompubbinding/m-p/23228#M10149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tq Jeff. Now I am using NodeService/Search Service to retrieve the FolderContent.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Mar 2017 21:48:51 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/401-error-with-atompubbinding/m-p/23228#M10149</guid>
      <dc:creator>raghav</dc:creator>
      <dc:date>2017-03-30T21:48:51Z</dc:date>
    </item>
  </channel>
</rss>

