Connecting SharePoint in Java - java

I am trying to connect to the SharePoint from my java code. However there seems to be something is missing and I am not able to connect to the sharepoint.
I am using the below code,
NtlmAuthenticator credentials = new NtlmAuthenticator("domain", "uname", "Password");
// Initialize proxy settings
//HttpProxy httpProxy = new HttpProxy("my_system_proxy", 80);
// Connect to Sharepoint
SPSite instance = new SPSite(new URL("https://my_url/cplc/projects/Knowledge%20Share/Forms/PracticeWise.aspx"), credentials, null, true, SPVersion.SP2013);
// Get root web instance
SPWeb rootWeb = instance.getRootWeb();
// Get list of all lists and document libraries from root web
SPListCollection lists = rootWeb.getLists();
I don't know what value I should set for proxy field there.
If I don't set the proxy and send null to it, it says "401: UnAuthorised"
HTTP transport error: java.net.UnknownHostException: proxy.msa"
Update:
I am referring this,
https://code.google.com/p/java-sharepoint-library/
Can anybody please help me to proceed further?

Even if this is not the answer to the question, I want to share with you a project i've just created to help otheres to integrate with sharepoint, as the problem you are into is the same i faced when trying to integrate java apps with sharepoint online. My first approach was to create a jni wrapper of a library made with c#, but this is a headache when you have linux machines in your company, as it will not work as it is based on native dlls method invocation.
I created a simple to use sharepoint java api that hope will help others to communicate with sharepoint
https://github.com/kikovalle/PLGSharepointRestAPI-java/
Also as the full implementation of the Rest API is not covered, you can feel free to contribute to the project.
Hope this will help and be usefull to save you time struggling with sharepoint integrations.

Related

jclouds openstack create instance

I recently installed jclouds to use with eclipse to create a project in java to communicate with openstack. Does anyone know if there is a way to create an instance from a snapshot or using default parameters (ovf image ). I would appreciate it. Thank you very much.
Try OpenStack4j. Jcloud is only a high level basic API for OpenStack since it supports many other clouds. Example using OpenStack4j
// Create a Server Model Object
Server server = Builders.server()
.name("Ubuntu 2")
.flavor("flavorId")
.image("imageId")
.addPersonality("/etc/motd", "Welcome to the new VM! Restricted access only")
.build();
// Boot the Server
Server server = os.compute().servers().boot(server);

How to return Google Drive authorization code from browser window automatically using Java?

I'm attempting to create an application for both PC (Java) and Android that utilizes Google Drive. I've been messing around with the examples to figure out how OAuth 2.0 works, and I can't find a good method of automatically returning the authorization code to my program once the user has allowed the application to access their data. The Google Drive Quickstart example uses a simple copy/paste mechanism that requires user input, but this is not convenient for the user.
It seems there are several suggested ways to retrieve the authorization code without bothering the user (running a local web server, monitoring the browser window launched for authentication, etc...), but Google doesn't strongly recommend any solution nor do they provide examples of how these solutions would work beyond basic descriptions. The following guide gives a few suggestions in Section 4 (Note: I tried to quote the section but SO wouldn't let me with the number of links/images present):
https://developers.google.com/youtube/v3/guides/authentication#installed-apps
Has anybody implemented something similar in the past, or are there best practices to do this? If possible I'd prefer a solution that would work on multiple platforms (i.e. not using any platform specific libraries).
I suppose it's not a huge deal if the user had to do this once (as I'll be storing a refresh token and using that from then on), but it'd be good to have a way around it.
In Oauth2 protocol, you have two ways of getting the authorization code : via a redirect to an url you have control over (could be pointing to a serve you own or localhost) or via copy pasting.
The first way is what you want, presumably with localhost as redirect uri, as you lauch the flow from you desktop app on the user's machine. You'll have no choice but to make your app spawn a little http server that can handle the code url parameter. However, you'll have to be hackish : how do you launch a web browser from your app, for any OS it can run on ? how do you the case where the user's machine is configured to refuse inbound http connection ?
IMO, best course of action is to go for the copy pasting : user knows what happen
I just implemented an oAuth2 solution for Google Drive. I ended up creating a service account via Google App Engine. Here is a good link to get started:
https://developers.google.com/drive/service-accounts
There is a Dr. Edit example that will work you through editing drive objects like spreadsheets.
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(pk12)
.setServiceAccountUser(ACCESS_DOMAIN_IMPERSONATE) // <-- set user email here
.build();
There are a few things you need to do in your Google domain admin console/cpanel for your domain.
Check the following SO answer I posted a day or so ago:
OAuth Google API for Java unable to impersonate user

how can i debug this issue with axis 2 web services and clients

I am learning to make web services with eclipse, apache and axis 2 following this tutorial. I am able to generate web services, create and upload .aar files and generate web service clients just like in the tutorial. But when I go to test the client it is not generating proper responses...
PersonalInfoServiceStub stub = new PersonalInfoServiceStub();
GetContactInfo atn = new GetContactInfo();
atn.setPersonID(1);
GetContactInfoResponse c = stub.getContactInfo(atn);
System.out.println(c.get_return()); //returns null
// The Java Class that serves as the basis for the web service works well...
PersonalInfoService s = new PersonalInfoService();
System.out.println(s.getContactInfo(1).getStreet()); //returns main street
This is all very new for me (I am still pretty dependent on following the tutorial) so I am not sure what might be causing this issue or how I might go about debugging what's wrong. What might be causing the problem and how would I go about debugging it?
If I try to call the webservice in the broswer using this url:
http://localhost:8080/axis2/services/PersonalInfoService/getContactInfo?personID=1
I get this
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ns:getContactInfoResponse xmlns:ns="http://webservices.com">
<ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns:getContactInfoResponse>
It looks like your client code is okay. The response from the server just doesn't contain any data. The simplest explanation is that the server sent back a response without any data. If I were you, I'd troubleshoot the server's behavior when it receives this request, rather than focusing on the client code.
I would start with Wireshark or tcpdump, this will help you capturing Network traffic that will help you debug at application and transport level what your Java code is generating and the response from server.

Obtaining a website's web server

I have taken up an assignment for a website and I am creating an android app for them. I am new to android programming and also new to web programming (using xml, http post and get, etc.).
My doubt is a basic one. I am trying to create the login page for this website and I don't know if the url of the website is sufficient or I need some other data such as the website's server address. And if I do need the web server address, is there a way to obtain this from my browser? Or do I ask the people who made the website itself for this?
P.S. I apologize if this is a very basic doubt. Bear with me. I am a beginner.
I am not an android application expert but I think you would need to get details about the following :
How to pass authentication details to server, for example if you need to get a SAML token from any of the ID servers? Or is it just sending out the plain username and password.
Just the website url may not be enough.
Please have a look at the weblink for authenticating against openID or SAML technologies
https://developers.google.com/accounts/docs/MobileApps
It depends on how the website is structured. Is there some kind of API for the website? If so use that. Otherwise you'll have to post the data to the same page the data gets POSTed to through a browser and find some way to catch an error or success. This method is not preferred. Also there may be some kind of central authentication server (Such as LDAP or AD) If so you would have to interface directly with that.

Associate Cisco-Phone with User via SOAP

Cisco offers the so called "AXL Toolkit" which allows to access functionality provided by the Cisco Unified Communications Manager (CUCM).
A WSDL-File is shipped with the toolkit. Using Eclipse, I tried to create Java-stubs out of it. But this didn't work. It says the file was inaccessible, while I'm having it right on the filesystem...
I would like to associate a phone with an application user. I have a software which does a similar stuff - but sniffing on the network isn't possible, because HTTPS is enforced for AXL-calls.
Any idea how to accomplish this?
I've finally found a tutorial, right on the Cisco website. One can use Apache Axis to transform the WSDL file to working java classes. You just have to modify the WSDL somewhat before.
Here is the information you need to get started:
Using AXL via WSDL and Java (with Axis)
Then you can just run queries against the database directly (here I'm using the AxlSqlToolkit class from the example code at the link provided):
AxlSqlToolkit ast = new AxlSqlToolkit("192.168.10.72", "admin", "admin4cisco");
String[] res = ast.executeSQL("select pkid from device");
for (String s : res) {
System.out.println(s);
}

Categories

Resources