Not getting any response from the jpos server - iso8583

I'm sending following 0800 request from my jpos client.
private void sendLonOnRequest() {
ISOMsg logOnMessage = null;
try {
Object sessionId = sp.rd(cfg.get(READ_KEY), cfg.getLong(TIME_OUT));
if (sessionId != null) {
logOnMessage = new ISOMsg();
logOnMessage.setMTI("0800");
logOnMessage.set(7, ISODate.getDateTime(new Date()));
logOnMessage.set(11, getSystemAuditNumber());
logOnMessage.set(70, "001");
logOnMessage.set(125, "EFT");
ISOMsg response = mux.request(logOnMessage, 30000);
if (response != null) {
sp.out(ECHO, new Object(), echoInterval);
handleSuccess(logOnMessage);
} else {
log.info("############ RESPONSE NULL");
handleFailure(logOnMessage, null);
}
}
} catch (ISOException e) {
handleFailure(logOnMessage, e);
}
}
system audit number is generated as:
public String getSystemAuditNumber() {
int stan = new Random().nextInt(900000);
return ISOUtil.zeropad(stan, 6);
}
A sample request is:
<log realm="channel/xxx.xxx.xx.xxx:port" at="Thu Aug 10 14:12:32 IST 2017.175" lifespan="78ms">
<send>
<isomsg direction="outgoing">
<!-- org.jpos.iso.packager.GenericPackager[D:/location/to/packager/iso87ascii.xml] -->
<field id="0" value="0800"/>
<field id="7" value="0810141232"/>
<field id="11" value="022887"/>
<field id="70" value="001"/>
<field id="125" value="EFT"/>
</isomsg>
</send>
</log>
But I do not get any response (response is null) from the jpos server and the client times out. I do not have a way to see the server's logs or debug it. Can someone please help me on this.

If you don't have option to get logs from the server, the best option is to go for network sniffer such as Wireshark.
This can help you to understand what is going on (TCP packet level).

Related

Logging Of 400 Error Mssage

In Production Environment,When I make Request for my web page.The Request show in apache's access logs,but not in configured my configured web logs.
My logback.xml is
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<jmxConfigurator />
<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } --- [%15.15t{14}] %-40.40logger{0} : %m%n" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/var/log/company_name/payments.log</file>
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="FILE" />
</root>
And My controller is
#CrossOrigin
#RestController
#RequestMapping("/my/v1")
public class PaymentApi {
#RequestMapping(value = RestURIConstants.VOID_TRANSACTION,
method = RequestMethod.POST )
public #ResponseBody ResponseEntity<?> voidPayment(#RequestParam("request") String voidRequestJson,
HttpServletRequest httpServletRequest) {
//Code here.
}
#ExceptionHandler
void handleException(Exception e, HttpServletResponse response) throws IOException {
logger.error("Error in Request : " + new ObjectMapper().writeValueAsString(e));
if (e instanceof IllegalArgumentException) {
response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage());
return;
}
response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), "an error occured while processing request");
}
}
I am making web Request using below code.
public static <T extends Response,S extends Request> T doPostRequest(S request,
Class<T> responseClass,
String urlString) throws ClientProtocolException, IOException{
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
logger.info("Sending Request " + objectMapper.writeValueAsString(request));
HttpEntity<String> entity = new HttpEntity<String>("request=" + objectMapper.writeValueAsString(request), headers);
ResponseEntity<String> response = null ;
response = restTemplate.exchange(urlString, HttpMethod.POST, entity, String.class);
logger.info("Response recieved " + response.toString());
if (response.getStatusCode() == HttpStatus.OK ||
response.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) {
return objectMapper.readValue(response.getBody(), responseClass) ;
// gson.fromJson(response.getBody(), responseClass) ;
}else{
return objectMapper.readValue(response.getBody(), responseClass) ;
}
}
Same code is working for my local ,But in production it throws 400 Error and also there are no logs in payments.log file.
The Java version in production on my payment server is on 1.8.0_25 and server which is making these request are on 1.8.0_91.
I am unable to identify the reasons as there are no logs are present for this web request in payments.log
their is limit on header size on production.Because of that i am getting this issue and there are no logs in payments.log.

publisher failed to recieve first message on rabbitmq

im trying to implement an integration test on RabbitMQ, so i have a setup of a published and basic consumer, to send and receive messages across a queue.
try
{
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setHost("localhost");
factory.setPort(5672);
connection = factory.newConnection();
channel = connection.createChannel();
channel.queueDeclare(RPC_QUEUE_NAME_KEY, DURABLE, EXCLUSIVE, AUTO_DELETE, null);
channel.exchangeDeclare(RPC_EXCHANGE_NAME, "direct");
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, RPC_EXCHANGE_NAME, RPC_QUEUE_NAME_KEY);
channel.basicQos(1);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, false, consumer);
System.out.println(" [x] Awaiting RPC requests");
while(true)
{
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
BasicProperties props = delivery.getProperties();
BasicProperties replyProps = new BasicProperties.Builder().correlationId(props.getCorrelationId()).build();
try
{
RetrieveUnencryptedCardsResponse response = null;
JAXBContext jaxbContext = JAXBContext.newInstance(RetrieveUnencryptedCardsRequest.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(new String(delivery.getBody()));
JAXBElement<RetrieveUnencryptedCardsRequest> message = jaxbUnmarshaller.unmarshal(new StreamSource(reader), RetrieveUnencryptedCardsRequest.class);
response = retrieveUnencryptedCardsResponse(message);
JAXBContext jaxbMarshallingContext = JAXBContext.newInstance(RetrieveUnencryptedCardsResponse.class);
Marshaller jaxbMarshaller = jaxbMarshallingContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
ByteArrayOutputStream xmlStream = new ByteArrayOutputStream();
jaxbMarshaller.marshal(new JAXBElement<RetrieveUnencryptedCardsResponse>(_RetrieveUnencryptedCardsResponse_QNAME, RetrieveUnencryptedCardsResponse.class, null,
response), xmlStream);
data = xmlStream.toByteArray();
xmlStream.close();
}
catch(Exception e)
{
logger.error(e);
}
finally
{
channel.basicPublish("", props.getReplyTo(), replyProps, data);
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if(connection != null)
{
try
{
connection.close();
}
catch(Exception ignore)
{
}
}
}
}
The problem occurs when I try to receive the messages from the queue. i cant receive the first message, but i can from the second one.
i don't know if this might help:
<rabbit:queue id="account.amqp.default.reply.queue"
name="${vendor.account.amqp.default.reply.queue}" durable="${connector.fixed.queue.durable}"
auto-delete="false" exclusive="false">
<rabbit:queue-arguments>
<entry key="x-message-ttl">
<value type="java.lang.Long">${vendor.account.amqp.default.reply.ttl}</value>
</entry>
<entry key="x-ha-policy" value="${vendor.account.default.queue.ha.policy}" />
<entry key="x-ha-policy-params"
value="#{ T(org.springframework.util.CollectionUtils).arrayToList((T(org.springframework.util.StringUtils).commaDelimitedListToSet('${vendor.account.default.queue.ha.nodes}')).toArray())}" />
</rabbit:queue-arguments>
</rabbit:queue>
<rabbit:template id="pamRabbitTemplate"
connection-factory="connectionFactory" message-converter="accountMarshallingMessageConverter"
reply-timeout="${gateway.reply.timeout}" reply-queue="${vendor.account.amqp.default.reply.queue}">
<rabbit:reply-listener
concurrency="${vendor.account.amqp.default.reply.queue.consumers}" />
</rabbit:template>
<bean id="accountMarshallingMessageConverter"
class="org.springframework.amqp.support.converter.MarshallingMessageConverter">
<property name="marshaller" ref="fuelNotificationWsMarshaller" />
<property name="unmarshaller" ref="fuelNotificationWsMarshaller" />
</bean>
and in pamRabbitTemplate:
<int:channel id="channel.accounts.request" />
<int:channel id="channel.accounts.reply" />
<int:channel id="channel.accounts.outbound.request" />
<int:channel id="channel.accounts.outbound.reply" />
<int:channel id="channel.accounts.error" />
<int-amqp:outbound-gateway request-channel="channel.accounts.outbound.request"
reply-channel="channel.accounts.outbound.reply" amqp-template="pamRabbitTemplate"
exchange-name="${pam.exchange.service.account}" routing-key="${pam.routingkey.service.account}"
requires-reply="false" />
<int:gateway id="gateway.account"
service-interface="notification.fuelnotification.infrastructure.integration.RetrieveAccountsGateway"
error-channel="channel.error" default-reply-timeout="${gateway.reply.timeout}">
<int:method name="retrieveUnencryptedCards"
request-channel="channel.accounts.request" reply-channel="channel.accounts.reply" />
</int:gateway>
<int:transformer id="accountsReqTf" method="transform"
input-channel="channel.accounts.request" output-channel="channel.accounts.outbound.request">
<bean
class="notification.fuelnotification.infrastructure.transformer.common.AccountsRequestTransformer" />
</int:transformer>
<int:transformer id="accountResTf" method="transform"
input-channel="channel.accounts.outbound.reply" output-channel="channel.accounts.reply">
<bean
class="notification.fuelnotification.infrastructure.transformer.common.UnencryptedCardsResponseTransformer" />
</int:transformer>
<int:transformer id="errorLoggerTransformer"
method="logDetails" input-channel="channel.error">
<bean
class="notification.fuelnotification.infrastructure.config.amqp.ErrorChannelDetailLogger" />
</int:transformer>

Spring integration with Rabbit AMQP for "Client Sends Message -> Server Receives & returns msg on return queue --> Client get correlated msg"

I am able to write a java program using Rabbit Java API's doing the following:
Client sends message over Rabbit MQ exchange/queue with correlation Id (Say UUID - "348a07f5-8342-45ed-b40b-d44bfd9c4dde").
Server receives the message.
Server sends response message over Rabbit MQ exchange/queue with the same correlation Id - "348a07f5-8342-45ed-b40b-d44bfd9c4dde".
Client received the correlated message only in the same thread as 1.
Below is the Send.java and Recv.java using Rabbit APIs. I need help to convert this sample to use Spring AMQP integration especially receiving part on step 4. I am looking for something like receive method which can filter message using correlation Id.
Send.java:
import java.util.UUID;
import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.QueueingConsumer;
public class Send {
private final static String REQUEST_QUEUE = "REQUEST.QUEUE";
private final static String RESPONSE_QUEUE = "RESPONSE.QUEUE";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(REQUEST_QUEUE, false, false, false, null);
String message = "Hello World!";
String cslTransactionId = UUID.randomUUID().toString();
BasicProperties properties = (new BasicProperties.Builder())
.correlationId(cslTransactionId)
.replyTo(RESPONSE_QUEUE).build();
channel.basicPublish("", REQUEST_QUEUE, properties, message.getBytes());
System.out.println("Client Sent '" + message + "'");
Channel responseChannel = connection.createChannel();
responseChannel.queueDeclare(RESPONSE_QUEUE, false, false, false, null);
QueueingConsumer consumer = new QueueingConsumer(channel);
responseChannel.basicConsume(RESPONSE_QUEUE, false, consumer);
String correlationId = null;
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String responseMessage = new String(delivery.getBody());
correlationId = delivery.getProperties().getCorrelationId();
System.out.println("Correlation Id:" + correlationId);
if (correlationId.equals(cslTransactionId)) {
System.out.println("Client Received '" + responseMessage + "'");
responseChannel.basicAck(delivery.getEnvelope().getDeliveryTag(), true);
break;
}
}
channel.close();
connection.close();
}
}
Recv.java
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
import com.rabbitmq.client.AMQP.BasicProperties;
public class Recv {
private final static String REQUEST_QUEUE = "REQUEST.QUEUE";
private final static String RESPONSE_QUEUE = "RESPONSE.QUEUE";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(REQUEST_QUEUE, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(REQUEST_QUEUE, true, consumer);
String correlationId = null;
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
correlationId = delivery.getProperties().getCorrelationId();
System.out.println("Correlation Id:" + correlationId);
System.out.println("Server Received '" + message + "'");
if (correlationId != null)
break;
}
String responseMsg = "Response Message";
Channel responseChannel = connection.createChannel();
responseChannel.queueDeclare(RESPONSE_QUEUE, false, false, false, null);
BasicProperties properties = (new BasicProperties.Builder())
.correlationId(correlationId).build();
channel.basicPublish("", RESPONSE_QUEUE, properties,responseMsg.getBytes());
System.out.println("Server Sent '" + responseMsg + "'");
channel.close();
connection.close();
}
}
After running the Java configuration provided by gary, I am trying to move the configuration to XML format for server side adding listener. Below is the XML configuration:
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean
id="serviceListenerContainer"
class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="queues" ref="requestQueue"/>
<property name="messageListener" ref="messageListenerAdaptor"/>
</bean>
<bean id="messageListenerAdaptor"
class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
<property name="delegate" ref="pojoListener" />
</bean>
<bean
id="pojoListener"
class="PojoListener"/>
<bean
id="replyListenerContainer"
class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="queues" ref="replyQueue"/>
<property name="messageListener" ref="fixedReplyQRabbitTemplate"/>
</bean>
<!-- Infrastructure -->
<rabbit:connection-factory
id="connectionFactory"
host="localhost"
username="guest"
password="guest"
cache-mode="CHANNEL"
channel-cache-size="5"/>
<rabbit:template
id="fixedReplyQRabbitTemplate"
connection-factory="connectionFactory"
exchange="fdms.exchange"
routing-key="response.key"
reply-queue="RESPONSE.QUEUE">
<rabbit:reply-listener/>
</rabbit:template>
<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:queue id="requestQueue" name="REQUEST.QUEUE" />
<rabbit:queue id="replyQueue" name="RESPONSE.QUEUE" />
<rabbit:direct-exchange name="fdms.exchange" durable="true" auto-delete="false">
<rabbit:bindings>
<rabbit:binding queue="RESPONSE.QUEUE" key="response.key" />
</rabbit:bindings>
</rabbit:direct-exchange>
</beans>
SpringReceive.java
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringReceive {
/**
* #param args
*/
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("cslclient.xml");
SimpleMessageListenerContainer serviceListenerContainer = context.getBean("serviceListenerContainer", SimpleMessageListenerContainer.class);
serviceListenerContainer.start();
}
}
You can use RabbitTemplate.sendAndReceive() (or convertSendAndReceive()) with a reply listener container (Docs here); the template will take care of the correlation for you.
If you are using Spring Integration, use an outbound gateway with an appropriately configured rabbit template.

Why is WSPasswordCallback.getPassword null when I try my SOAP request

I have made an Axis2 web service with Rampart security, but I was constantly receiving NullPointerException at this line:
if((pwcb.getIdentifier().equals("bob")) && pwcb.getPassword().equals("bobPW")) )
So I added this code:
if ( pwcb.getPassword()==null) {
throw new Exception ("passsssssssss is null:"+pwcb.getPassword());
}
Which threw the exception; so I know that the problem is that pwcb.getPassword is null, but don't understand why.
This is the SOAP request I'm sending:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:nilo="http://nilo">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="123">
<wsse:Username>bob</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">bobPW</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<nilo:getdataForChecking>
<nilo:data>tranXml</nilo:data>
</nilo:getdataForChecking>
</soapenv:Body>
</soapenv:Envelope>
Here is the handle method that I'm using:
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
//When the server side need to authenticate the user
WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
if ( pwcb.getPassword()==null) {
try {
throw new Exception ("passsssssssss null:"+pwcb.getPassword());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
try {
throw new Exception ("pass nooot null:"+pwcb.getPassword());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(pwcb.getIdentifier().equals("bob") && pwcb.getPassword().equals("bobPW")) {
return;
}
//When the client requests for the password to be added in to the
//UT element
}
}
Whether WSPasswordCallback contains password depends on its usage field. For instance for usage USERNAME_TOKEN_UNKNOWN the password is set and callback handler is supposed to throw an exception, if it does not match username. For SIGNATURE on the other hand, the password field is empty and the callback needs to set it, so that the key can be retrieved from keystore.
You should verify in what scenario callback is called and react appropriately. For instance:
// Rampart expects us to do authentication in this case
if (pwcb.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {
String password = passwordFor(pwcb.getIdentifier());
if (pwcb.getPassword().equals(password))
return;
throw new UnsupportedCallbackException(callback,
"password check failed for user " + pwcb.getIdentifier());
}
if (pwcb.getUsage() == WSPasswordCallback.SIGNATURE) {
pwcb.setPassword(passwordFor(pwcb.getIdentifier()));
The handler needs to know the password of the user that initiated the call. You do not have to do the comparison yourself.
Modifying this line from:
if((pwcb.getIdentifier().equals("bob")) && pwcb.getPassword().equals("bobPW")) )
to:
if (pwcb.getIdentifier().equals("bob"))
{
pwcb.setPassword("bobPW");
}

Solr - Error when posting an "Add" to the server

I'm Posting the following to the Solr Server:
<add>
<doc>
<field name="uniqueid">5453543</field>
<field name="modifieddate">2008-12-03T15:49:00Z</field>
<field name="title">My Record</field>
<field name="description">Descirption
Details
</field>
<field name="startdate">2009-01-21T15:26:05.680Z</field>
<field name="enddate">2009-01-21T15:26:05.697Z</field>
<field name="Telephone_number">11111 111 111(text phone)</field>
<field name="Telephone_number">11111 111 111</field>
<field name="Mobile_number">1111111111</field>
</doc>
</add>
I'm using SolrNet to send the documents here's an extract from the code (s is the above xml):
public string Post(string relativeUrl, string s)
{
var u = new UriBuilder(serverURL);
u.Path += relativeUrl;
var request = httpWebRequestFactory.Create(u.Uri);
request.Method = HttpWebRequestMethod.POST;
request.KeepAlive = false;
if (Timeout > 0)
request.Timeout = Timeout;
request.ContentType = "text/xml; charset=utf-8";
request.ContentLength = s.Length;
request.ProtocolVersion = HttpVersion.Version10;
try
{
using (var postParams = request.GetRequestStream())
{
postParams.Write(xmlEncoding.GetBytes(s), 0, s.Length);
using (var response = request.GetResponse())
{
using (var rStream = response.GetResponseStream())
{
string r = xmlEncoding.GetString(ReadFully(rStream));
//Console.WriteLine(r);
return r;
}
}
}
}
catch (WebException e)
{
throw new SolrConnectionException(e);
}
}
When it gets to request.GetResponse it failed with this error:
base
{System.InvalidOperationException} =
{"The remote server returned an error:
(500) Internal Server Error."}
When i look on the server in the Logs for apache it gives the following reason:
Unexpected end of input block in end
Here's the full stack trace:
Sep 17, 2009 10:13:53 AM
org.apache.solr.common.SolrException
log SEVERE:
com.ctc.wstx.exc.WstxEOFException:
Unexpected end of input block in end
tag at [row,col {unknown-source}]:
[26,1266] at
com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOB(StreamScanner.java:700)
at
com.ctc.wstx.sr.StreamScanner.loadMoreFromCurrent(StreamScanner.java:1054)
at
com.ctc.wstx.sr.StreamScanner.getNextCharFromCurrent(StreamScanner.java:811)
at
com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3211)
at
com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2832)
at
com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1019)
at
org.apache.solr.handler.XmlUpdateRequestHandler.processUpdate(XmlUpdateRequestHandler.java:148)
at
org.apache.solr.handler.XmlUpdateRequestHandler.handleRequestBody(XmlUpdateRequestHandler.java:123)
at
org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:131)
at
org.apache.solr.core.SolrCore.execute(SolrCore.java:1204)
at
org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:303)
at
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:232)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
at
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
at
java.lang.Thread.run(Thread.java:619)
Please note the Solr server is running on the following system:
Microsoft Windows Server 2003 R2
Apache Tomcat 6
Finally here's my question:
The Xml i'm sending looks ok to me.. Does anyone have an ideas as to why Solr is throwing this exception?
Thanks
Dave
Edit Answer is as follows:
public string Post(string relativeUrl, string s)
{
var u = new UriBuilder(serverURL);
u.Path += relativeUrl;
var request = httpWebRequestFactory.Create(u.Uri);
request.Method = HttpWebRequestMethod.POST;
request.KeepAlive = false;
if (Timeout > 0)
request.Timeout = Timeout;
request.ContentType = "text/xml; charset=utf-8";
request.ProtocolVersion = HttpVersion.Version10;
try
{
// Set the Content length after the size of the byte array has been calculated.
byte[] data = xmlEncoding.GetBytes(s);
request.ContentLength = s.Length;
using (var postParams = request.GetRequestStream())
{
postParams.Write(data, 0, data.Length);
using (var response = request.GetResponse())
{
using (var rStream = response.GetResponseStream())
{
string r = xmlEncoding.GetString(ReadFully(rStream));
//Console.WriteLine(r);
return r;
}
}
}
}
catch (WebException e)
{
throw new SolrConnectionException(e);
}
}
I'm not much familiar with .Net or Solr or .Net port of Solr. But, here is my guess.
postParams.Write(xmlEncoding.GetBytes(s), 0, s.Length);
There are two possible errors.
When you are getting bytes from String, you should specify the encoding. It might be the case that the default encoding is different from UTF8, which you have set in content type header in response.
The third parameter in Write() probabably refers to the length of byte array which you got from GetBytes(). The byte array could be longer than the length of string.