Dynamics CRM 2011 Online WebServices from Java - java

I'm trying to access MicroSoft Dynamic CRM 2011 online webservices from Java but no luck so far.
I got Organization WSDL file and generated required java stub files with the help of Axis2 (wsdl2Java).
And my simple client code is
public class TestCRM2 {
public static void main(String[] args) {
try {
// create query
QueryExpression query = new QueryExpression();
query.setEntityName("Contact");
ArrayOfstring colAra = new ArrayOfstring();
colAra.addString("fullname");
ColumnSet columnSet = new ColumnSet();
columnSet.setAllColumns(false);
columnSet.setColumns(colAra);
PagingInfo pageinfo = new PagingInfo();
pageinfo.setCount(10);
pageinfo.setPageNumber(1);
query.setColumnSet(columnSet);
query.setPageInfo(pageinfo);
ConditionExpression condition = new ConditionExpression();
condition.setAttributeName("fullname");
condition.setOperator(ConditionOperator.Equal);
ArrayOfanyType values = new ArrayOfanyType();
values.setAnyType(new String[] {"something"});
condition.setValues(values);
RetrieveMultiple retrieveMultiple = new RetrieveMultiple();
retrieveMultiple.setQuery(query);
OrganizationServiceStub stub = new OrganizationServiceStub();
//set Timeout
ServiceClient serviceClient = stub._getServiceClient();
serviceClient.getOptions().setTimeOutInMilliSeconds( 3 * 60 * 1000);
/*serviceClient.getOptions().setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION, HTTPConstants.HEADER_PROTOCOL_10);
serviceClient.getOptions().setProperty(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED,false);*/
RetrieveMultipleResponse response = stub.retrieveMultiple(retrieveMultiple);
EntityCollection collection = response.getRetrieveMultipleResult();
int count = collection.getTotalRecordCount();
System.out.println(count);
} catch (Exception e) {
e.printStackTrace();
}
}}
When i run this from Eclipse, i get the following runtime error
org.apache.axis2.AxisFault: Connection reset
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.microsoft.schemas.xrm._2011.contracts.OrganizationServiceStub.retrieveMultiple(OrganizationServiceStub.java:1177) at test.TestCRM.main(TestCRM.java:105)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:755)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
... 9 more
Is there any thing I'm missing in my client code. Your help is highly appreciated.
Regards,

You have to append "/web" at the end of your endpoint url in service client.
You will have to provide NTLM2 authenticator implementation and register it with httpclient used by your stub.

Related

Getting java.lang.IllegalStateException: Connection is not open

I am getting the below error while my code is trying to access a 3rd party endpoint
This request is sent via Service Stub generated code
We are using Axis2 version 1.7.7
Caused by: java.lang.IllegalStateException: Connection is not open
at org.apache.commons.httpclient.HttpConnection.assertOpen(HttpConnection.java:1277)
at org.apache.commons.httpclient.HttpConnection.getResponseInputStream(HttpConnection.java:858)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.getResponseInputStream(MultiThreadedHttpConnectionManager.java:1297)
What could be the reason for this and how can we solve this.
Below is the code for reference
public com.test.Token validateToken(com.test.Token actionToken)throws java.rmi.RemoteException
{
org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext();
try{
org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[0].getName());
_operationClient.getOptions().setAction("http://serviceURL/action");
_operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
addPropertyToOperationClient(_operationClient,org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,"&");
org.apache.axiom.soap.SOAPEnvelope env = null;
env = toEnvelope(getFactory(_operationClient.getOptions().getSoapVersionURI()),
actionToken,
optimizeContent(new javax.xml.namespace.QName("http://serviceURL", "action")),
new javax.xml.namespace.QName("http://serviceURL", "action"));
_serviceClient.addHeadersToEnvelope(env);
_messageContext.setEnvelope(env);
_operationClient.addMessageContext(_messageContext);
_operationClient.execute(true);
org.apache.axis2.context.MessageContext _returnMessageContext = _operationClient.getMessageContext(
org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();
java.lang.Object object = fromOM(
_returnEnv.getBody().getFirstElement() ,
com.test.Token.class);
return (com.test.Token)object;
}

cannot run telegram bot with proxy

I wrote a robot under the server
And I want to run with a proxy
But I miss the following error
mybot is:
public class StoreBot extends TelegramLongPollingBot {
public StoreBot( DefaultBotOptions botOptions) {
super(botOptions);
}
public int creatorId() {
return 0;
}
public StoreBot() {
}
....
}
mycode for run bot is:
ApiContextInitializer.init();
// Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi();
// Set up Http proxy
DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
botOptions.setProxyHost("2.181.254.198");
botOptions.setProxyPort(8580);
// Select proxy type: [HTTP|SOCKS4|SOCKS5] (default: NO_PROXY)
botOptions.setProxyType(DefaultBotOptions.ProxyType.SOCKS5);
// Register your newly created AbilityBot
StoreBot bot = new StoreBot(botOptions);
botsApi.registerBot(bot);
when run get this error:
org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException: Error removing old webhook
...
Caused by: org.telegram.telegrambots.meta.exceptions.TelegramApiException: Unable to execute deleteWebhook method
...
Caused by: java.net.SocketException: Connection timed out: connect
RequestConfig requestConfig = RequestConfig.custom()
.setProxy(new HttpHost(host, port))
.build();
DefaultBotOptions botOptions = new DefaultBotOptions();
botOptions.setRequestConfig(requestConfig);
StoreBot bot = new StoreBot(botOptions);

Rendering SSRS Reports in Java

I am working a on project which should render SSRS reports in Java.
Below is the procedure that I have followed.
Installed Eclipse
Created a java project By setting Execution Environment Java SE 1.8
Created a proxy using wsimport
wsimport image
Added the references for the generated proxy
added classed
Written this code
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Holder;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ArrayOfString;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ArrayOfWarning;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ExecutionHeader;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ExecutionInfo;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ReportExecutionService;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ReportExecutionServiceSoap;
public class Render {
static {
java.net.Authenticator.setDefault(new java.net.Authenticator() {
#Override
protected java.net.PasswordAuthentication getPasswordAuthentication() {
return new java.net.PasswordAuthentication("username", "pwd".toCharArray());
}
});
}
public static void main(String[] args) {
String reportPath = "/Reporting/Customers" ;
String format = "HTML4.0";
String historyID = null;
String devInfo = "<DeviceInfo><Toolbar>False</Toolbar><HTMLFragment>True</HTMLFragment></DeviceInfo>";
String executionID = null;
Holder<String> extension = null;
Holder<String> mimeType = null;
Holder<String> encoding = null;
Holder<ArrayOfWarning> warnings = null;
Holder<ArrayOfString> streamIDs = null;
Holder<byte[]> result = new Holder<byte[]>();
ReportExecutionService res = new ReportExecutionService();
ReportExecutionServiceSoap ress = res.getReportExecutionServiceSoap();
BindingProvider bp = (BindingProvider)ress;
bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
ExecutionInfo execInfo = new ExecutionInfo();
execInfo = ress.loadReport(reportPath, historyID);
executionID = execInfo.getExecutionID();
bp.getRequestContext().put("sessionID", executionID);
ExecutionHeader eh = new ExecutionHeader();
eh.setExecutionID(executionID);
System.out.println(executionID);
ress.render(format, devInfo, result, extension, mimeType, encoding, warnings, streamIDs);
String resultString = new String(result.value);
}
}
When I am running this code , i am getting the below error.
Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: The session identifier is missing. A session identifier is required for this operation. ---> Microsoft.ReportingServices.Diagnostics.Utilities.MissingSessionIdException: The session identifier is missing. A session identifier is required for this operation. Please see the server log to find more detail regarding exact cause of the failure.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(Unknown Source)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
at com.sun.proxy.$Proxy35.render(Unknown Source)
at Render.main(Render.java:50)
I am new to java, am I missing something ? I already set session id.
any help is appreciated.
Thanks in advance.

Solrj DeleteByQuery is not working

I have spent more than 3 hours of time to fix this issue, but unfortunately i am not able to fix it. Can anyone help me on this ?
Here is the exception i am getting while running deletebyQuery using solrj while adding to solr is working. Note : deletebyQuery is not working but add is working.
org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: http://localhost:8090/solr/abc
at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:589)
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:241)
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:230)
at org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.request(ConcurrentUpdateSolrClient.java:351)
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:150)
at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:896)
at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:914)
at net.merger.prune.Merger.run(Merger.java:19)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:886)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:480)
... 14 more
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:663)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
... 18 more
and here is my SolrServerHolder code.
public class SolrServerHolder {
private static SolrClient concurrentSolrServer = null;
private static HttpSolrClient solrServer = null;
#SuppressWarnings("deprecation")
private static HttpSolrServer httpServer = null;
private static DefaultHttpClient client = null;
private static synchronized void initHttpClient() {
try {
PoolingClientConnectionManager connManager = new PoolingClientConnectionManager();
connManager.setDefaultMaxPerRoute(20); // Allow upto 20 connections for solr server
connManager.setMaxTotal(1000);
client = new DefaultHttpClient(connManager);
} catch (Error e) {
e.getMessage();
}
}
private static synchronized void initConcurrentSolrServer() throws Exception {
if(client == null)
initHttpClient();
UsernamePasswordCredentials defaultcreds = new UsernamePasswordCredentials("XXXX", "YYYY");
client.getCredentialsProvider().setCredentials(
new AuthScope("localhost",
"8090", AuthScope.ANY_REALM),defaultcreds);
concurrentSolrServer = new ConcurrentUpdateSolrClient("http://localhost:8090/solr/abc", client, 5000, 2);
}
public static SolrClient getConcurrentSolrServer() throws Exception {
if(concurrentSolrServer == null)
initConcurrentSolrServer();
return concurrentSolrServer;
}
}
and Here is my code which will trying to delete the data by query and throwing exception :
SolrClient server =SolrServerHolder.getConcurrentSolrServer();
server.deleteByQuery("id:65657575", 12000);
server.commit();
if i am trying to add docs to solr it is working perfectly Fine
SolrInputDocument docs = getDocs();
SolrClient server =SolrServerHolder.getConcurrentSolrServer();
server.add(abc);
server.commit();
I have refereed similar issues and solutions but it didn't help me.
Solrj Authentication Fails On Write Operation

Python Server / Java Client "Connection refused: connect"

I am communicating using TCP Socket.
While Working, a problem arises
Client can't make 'Socket' Instance.
Strange Point is that (In Server using Python)
Using 'socket' class in python don't cause problem,
but using 'SocketServer.TCPServer' class in python cause problem
This is my environment.
Server : Python
Client : Java / Many Users will try connect.
Server Code (using Python):
SooMain.py
if name == "main":
server = SooServer('localhost', PORT_DEBUG, SooRequestHandler)
server.serve_forever()
SooServer.py
class SooServer(SocketServer.TCPServer):
"This is Server For Project201201"
def __init__(self,
host='localhost',
port=PORT_DEBUG,
handler=SooRequestHandler):
#SocketServer.ThreadingTCPServer.__init__(self, (host, port), handler)
SocketServer.TCPServer.__init__(self, (host, port), handler)
print "SooServer <State> __init__"
self.abort=0
self.timeout=10
def shutdown(self):
SocketServer.ThreadingTCPServer.shutdown(self)
print "SooServer <State> shutdown"
Client Code (using Java):
TestJava.java
public class TestJava {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
try {
String[] aStrData = {
"Test",
"Test" };
InetAddress m_oInetAddr = InetAddress.getByName(DEBUG_ADDR);
Socket m_oSocket = new Socket(m_oInetAddr, DEBUG_PORT); //This Line Makes Exception!!!!!
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(m_oSocket.getOutputStream())), true);
int nNumData = aStrData.length;
out.println(Integer.toString(nNumData));
for (int i=0 ; i<nNumData ; i++) {
out.println(aStrData[i]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Error Code (using Java):
Releated Line : Socket m_oSocket = new Socket(m_oInetAddr, DEBUG_PORT);
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:241)
at TestJava.main(TestJava.java:51)

Categories

Resources