TRIM WebServices and JAVA: 401 Unauthorized (628 Views)
Reply
Occasional Visitor
fredcoughlin
Posts: 1
Registered: ‎01-25-2013
Message 1 of 2 (628 Views)

TRIM WebServices and JAVA: 401 Unauthorized

[ Edited ]

Hi all,

 

Apologies for what is likely a stupid question.  I've been trying to start accessing a TRIM database from  WebServices.  I'm using TRIM 7.3, and Java 1.4.  Using Creating Java Proxy Classes as a base, I created my project and tried to log into TRIM.  I then received a 401:  Unauthorized exception thrown back in my face.  Seeing how people suggested on forums suggested that I create an authenticator, I did so.  I still am getting an error.  From my debug output, it's clear that the constructor is called, but the getPasswordAuthentication function is never called, which is slightly confusing.  Does anyone have any suggestions as to how to make this work?  Relevant snippets of my Java code are below.

 

Potentially I can upgrade to a higher Java version, but the code skeleton generated by the WSDL2Java app that I used generated properties with the word enum in them (which is reserved from 1.5 on, I have read)

 

Thanks,

Fred

public class TrimServices
{


private static String createRecord2()
{
try
{ 
Authenticator.setDefault(new MyAuthenticator());

Create create = new Create();
/*Establish create, snipped code...*/

try
{
TrimRequest req = new TrimRequest();
req.setCreate(create);

String url = "http://localhost/trimws/trim.asmx";
java.net.URL host = new java.net.URL(url);

EngineLocator engine = new EngineLocator();
EngineSoap soapEngine = engine.getEngineSoap(host);
TrimResponse tr = null;
tr = soapEngine.execute(req);
}
catch(Exception ex)
{
System.err.println(ex);
}

return "Returning from Create";

}

static class MyAuthenticator extends Authenticator {
private String username, password;
public MyAuthenticator()
{
username = "Administrator";
password = "password";
System.err.println("HERE 1");
}

public PasswordAuthentication getPasswordAuthentication () {
System.err.println("HERE 2");
return new PasswordAuthentication (username, password);
}
}

 

Occasional Visitor
Jacob4
Posts: 2
Registered: ‎03-11-2013
Message 2 of 2 (560 Views)

Re: TRIM WebServices and JAVA: 401 Unauthorized

I was stuck on this for ages as well, turns out in some situations your username needs to be in the format "domain/username"

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.