Sharepoint web service throwing Microsoft.SharePoint.SoapServer.SoapServerException - java

I am coding for consuming Sharepoint 2010 web services in Java using Netbeans. I am able to creating the web service client from WSDL using the provided wizard. When I call the following code I get the Microsoft.SharePoint.SoapServer.SoapServerException
import java.net.Authenticator;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import proxy.webs.GetWebCollectionResponse;
import proxy.webs.GetWebResponse;
import proxy.webs.Webs;
import proxy.webs.WebsSoap;
public class AccessLists {
public static void main(String[] args) throws Exception {
String username = "domain\\Administrator";
char[] password = "password".toCharArray();
NtlmAuthenticator ntlmAuth = new NtlmAuthenticator(username, password);
Authenticator.setDefault(ntlmAuth);
Webs websService = new Webs(new URL("http://servername:7766/_vti_bin/Webs.asmx?wsdl"));
WebsSoap webPort = websService.getWebsSoap();
GetWebResponse.GetWebResult webRes = webPort.getWeb("http://servername/sites/Test1");
System.out.println(webRes);
}
}
The site http://servername/sites/Test1 exists and I can open it in the browser.
Update 1: Similar thing happens for C# code, which I run on the same machine as Sharepoint 2010:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Webs webService = new Webs();
webService.Credentials = System.Net.CredentialCache.DefaultCredentials;
Object o = webService.GetWeb("http://servername/sites/Test1");
Console.WriteLine(o.ToString());
}
}
}
I guess this is the problem with the set up and not with the code.

I was using the wrong endpoint for the web service. For the Sharepoint site http://servername/sites/Test1 the endpoint should also be http://servername/sites/Test1/_vti_bin/Webs.asmx?wsdl

Related

How to enable Neural Text-to-Speech (NTTS) in Java using Amazon Polly

I am trying to use Amazon Polly to convert text to speech using Java API. As described by Amazon there are several US english voices which support Neural. https://docs.aws.amazon.com/polly/latest/dg/voicelist.html
The code I am following to run in Java application is as following:
package com.amazonaws.demos.polly;
import java.io.IOException;
import java.io.InputStream;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.polly.AmazonPollyClient;
import com.amazonaws.services.polly.model.DescribeVoicesRequest;
import com.amazonaws.services.polly.model.DescribeVoicesResult;
import com.amazonaws.services.polly.model.OutputFormat;
import com.amazonaws.services.polly.model.SynthesizeSpeechRequest;
import com.amazonaws.services.polly.model.SynthesizeSpeechResult;
import com.amazonaws.services.polly.model.Voice;
import javazoom.jl.player.advanced.AdvancedPlayer;
import javazoom.jl.player.advanced.PlaybackEvent;
import javazoom.jl.player.advanced.PlaybackListener;
public class PollyDemo {
private final AmazonPollyClient polly;
private final Voice voice;
private static final String JOANNA="Joanna";
private static final String KENDRA="Kendra";
private static final String MATTHEW="Matthew";
private static final String SAMPLE = "Congratulations. You have successfully built this working demo of Amazon Polly in Java. Have fun building voice enabled apps with Amazon Polly (that's me!), and always look at the AWS website for tips and tricks on using Amazon Polly and other great services from AWS";
public PollyDemo(Region region) {
// create an Amazon Polly client in a specific region
polly = new AmazonPollyClient(new DefaultAWSCredentialsProviderChain(),
new ClientConfiguration());
polly.setRegion(region);
// Create describe voices request.
DescribeVoicesRequest describeVoicesRequest = new DescribeVoicesRequest();
// Synchronously ask Amazon Polly to describe available TTS voices.
DescribeVoicesResult describeVoicesResult = polly.describeVoices(describeVoicesRequest);
//voice = describeVoicesResult.getVoices().get(0);
voice = describeVoicesResult.getVoices().stream().filter(p -> p.getName().equals(MATTHEW)).findFirst().get();
}
public InputStream synthesize(String text, OutputFormat format) throws IOException {
SynthesizeSpeechRequest synthReq =
new SynthesizeSpeechRequest().withText(text).withVoiceId(voice.getId())
.withOutputFormat(format);
SynthesizeSpeechResult synthRes = polly.synthesizeSpeech(synthReq);
return synthRes.getAudioStream();
}
public static void main(String args[]) throws Exception {
//create the test class
PollyDemo helloWorld = new PollyDemo(Region.getRegion(Regions.US_WEST_1));
//get the audio stream
InputStream speechStream = helloWorld.synthesize(SAMPLE, OutputFormat.Mp3);
//create an MP3 player
AdvancedPlayer player = new AdvancedPlayer(speechStream,
javazoom.jl.player.FactoryRegistry.systemRegistry().createAudioDevice());
player.setPlayBackListener(new PlaybackListener() {
#Override
public void playbackStarted(PlaybackEvent evt) {
System.out.println("Playback started");
System.out.println(SAMPLE);
}
#Override
public void playbackFinished(PlaybackEvent evt) {
System.out.println("Playback finished");
}
});
// play it!
player.play();
}
}
By default its taking the Standard of the voice of Matthew. Please suggest what needs to be changed to make the speech Neural for the voice of Matthew.
Thanks
Thanks #ASR for your feedback.
I was able to find the engine parameter as you suggested.
The way I had to solve this is:
Update the aws-java-sdk-polly version from 1.11.77 (as they have in their documentation) to the latest 1.11.762 in the pom.xml and build the Maven project. This brings the latest class definition for SynthesizeSpeechRequest Class. With 1.11.77 I was unable to see withEngine function in its definition.
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-polly</artifactId>
<version>1.11.762</version>
</dependency>
Updated the withEngine("neural") as below:
SynthesizeSpeechRequest synthReq =
new SynthesizeSpeechRequest().withText(text).withVoiceId(voice.getId())
.withOutputFormat(format).withEngine("neural");
As defined in https://docs.aws.amazon.com/polly/latest/dg/NTTS-main.html Neural voice is only available in specific regions. So I had to chose as following:
PollyDemo helloWorld = new PollyDemo(Region.getRegion(Regions.US_WEST_2));
After this Neural voice worked perfectly.
I am assuming you are using AWS Java SDK 1.11
AWS documentation here states that you need to set the engine parameter in the speech sysnthesis request to neural. AWS Java SDK documentation here describes the withEngine method to set it to neural.
PS: the documentation page doesn't seem to provide the method URLs, so you will have to search for it.

How to create request from WADL programatically in java

Is there any way we can create request from WSDL for REST services in java?.programatically Read/parse WSDL and append the values to query paramets and execure request.I was able to find example for WSDL as in here
package com.bbog.soap;
import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlOperation;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
import com.eviware.soapui.model.iface.Operation;
public class WsdlAnalyzer {
public static void main(String[] args) throws Exception {
WsdlProject project = new WsdlProject();
WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://localhost:7000/Solicitud?wsdl");
WsdlInterface wsdl = wsdls[0];
for (Operation operation : wsdl.getOperationList()) {
WsdlOperation op = (WsdlOperation) operation;
System.out.println("OP:"+op.getName());
System.out.println(op.createRequest(true));
System.out.println("Response:");
System.out.println(op.createResponse(true));
}
}
}
The link are:
how to generate a SOAP message with a fully populated request from WSDL without code gen
how to create a SOAP UI project and run requests to it in Java
Is there something similar in REST to read WADL?. Any help is appreciated.Thanks.

Java application for Bing API

I have to make an application which is able to use Bing Search API ( SOAP Services) with java.It must do a specific search for a word.Here is my code :
import com.google.code.bing.search.client.BingSearchClient;
import com.google.code.bing.search.client.BingSearchServiceClientFactory;
import com.google.code.bing.search.client.BingSearchClient.SearchRequestBuilder;
import com.google.code.bing.search.schema.AdultOption;
import com.google.code.bing.search.schema.SearchOption;
import com.google.code.bing.search.schema.SearchRequest;
import com.google.code.bing.search.schema.SearchResponse;
import com.google.code.bing.search.schema.SourceType;
import com.google.code.bing.search.schema.web.WebResult;
import com.google.code.bing.search.schema.web.WebSearchOption;
public class MyApp {
String apikey = "****************";
String searchword="google";
public static void main(String[] args){
BingSearchServiceClientFactory factory = BingSearchServiceClientFactory.newInstance();
BingSearchClient client = factory.createBingSearchClient();
SearchRequestBuilder builder = client.newSearchRequestBuilder();
builder.withAppId(apikey);
builder.withQuery(searchword);
builder.withSourceType(SourceType.WEB);
builder.withVersion("2.0");
builder.withMarket("en-us");
builder.withAdultOption(AdultOption.MODERATE);
builder.withSearchOption(SearchOption.ENABLE_HIGHLIGHTING);
builder.withWebRequestCount(10L);
builder.withWebRequestOffset(0L);
builder.withWebRequestSearchOption(WebSearchOption.DISABLE_HOST_COLLAPSING);
builder.withWebRequestSearchOption(WebSearchOption.DISABLE_QUERY_ALTERATIONS);
SearchResponse response = client.search(builder.getResult());
for (WebResult result : response.getWeb().getResults()) {
System.out.println(result.getTitle());
System.out.println(result.getDescription());
System.out.println(result.getUrl());
System.out.println(result.getDateTime());
}
}
}
I found this http://code.google.com/p/bing-search-java-sdk/ site.
I get my appkey from Azure MarketPlace. I get an error : java.lang.NullPointerException at the line for loop that will show response. That means response is null.
I don't understand what I am missing .
bing is changing their license system at the moment. this API was created using the "old" version 2 license. MS had done some changes when migrating to Azzure market place:
https://datamarket.azure.com/dataset/5BA839F1-12CE-4CCE-BF57-A49D98D29A44
migration guide:
http://go.microsoft.com/fwlink/?LinkID=248077
I don't think that this is covered by this Java-API wrapper you use already.

Web Services using jdk 1.6

Hi All
I am new to web services. I have written a java class.
But I am not getting how to deploy it. I mean do i need web server or app server . As this is simple java class i can not make WAR file to deploy it . So what is the method to deploy it and which server should i use. I am using JDK 1.6
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.Endpoint;
#WebService
public class WiseQuoteServer {
#SOAPBinding(style = Style.RPC)
public String getQuote(String category) {
if (category.equals("fun")) {
return "5 is a sufficient approximation of infinity.";
}
if (category.equals("work")) {
return "Remember to enjoy life, even during difficult situatons.";
} else {
return "Becoming a master is relatively easily. Do something well and then continue to do it for the next 20 years";
}
}
public static void main(String[] args) {
WiseQuoteServer server = new WiseQuoteServer();
Endpoint endpoint = Endpoint.publish(
"http://localhost:9191/wisequotes", server);
The best answer to your question would be the tutorial of JAX-WS

Changing parameters in a JAX-WS web service

I'm creating some web services using JAX-WS and the java SE build-in server. Every time I add a new parameter on a web service i need to change the URL it's published to. Otherwise the new parameters always get a null value. How can I make this work without changing the URL?
Here's the main class code with the publishing code:
import javax.xml.ws.Endpoint;
import pickate.AmazonMail;
import pickate.FacebookStream;
class Main {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8888/pickate/amazonmail", new AmazonMail());
Endpoint.publish("http://localhost:8888/pickate/facebookstream", new FacebookStream());
}
}
And the implementation of one of the webservices
package pickate;
import java.util.List;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
// Other imports go here
#WebService
public class FacebookStream
{
public FacebookStream()
{
}
#WebMethod
#Oneway
public void sendNotification(
#WebParam(name = "receivers") List<String> receivers,
#WebParam(name = "fbtoken") String fbtoken,
#WebParam(name = "body") String body,
)
{
// Some interesting stuff goes here
}
}
It was indeed the client caching up the WSDL file. It seems the PHP Soap Extension (which is what i'm using on the client-side) does it by default.

Categories

Resources