SMPP Server

Sumit 7 years ago

Hi,
I was enabling SMPP Server to send some custom commands to the device. I have tried for some 6 times and it worked. I don't know how cause of no enabling the SMPP server on traccar and it suddenly said this after 6th command:

SMPP client is not enabled -
RuntimeException (BaseProtocol:106 < DeviceManager:470 < CommandResource:38 < ...)

I figured it out by some forums so I did not add smpp server in the traccar configuration file. But I did not get if I did not setup any config for smpp how those six commads went.
I want to know if there is any free SMPP Server to enable. And I found msg91.com gateway. It is giving me some free credits not full time.

Anton Tananaev 7 years ago

Probably you sent non SMS commands before and then it failed when you tried SMS.

Sumit 7 years ago

Hey I am getting this log now:

Unable to connect to SMPP server: com.cloudhopper.smpp.type.SmppChannelException: Channel was closed after sending request, but before receiving response

[qtp1455204443-59] WARN org.eclipse.jetty.http.HttpParser - Illegal character 0x0 in state=START for buffer HeapByteBuffer@60931ed5[p=1,l=35,c=16384,r=34]={\x00<<<\x00\x00#\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x01us...\x00password\x00\x004\x00\x00\x00>>>5/engineOff/*HQ,8...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
[qtp1455204443-59] WARN org.eclipse.jetty.http.HttpParser - badMessage: 400 Illegal character 0x0 for HttpChannelOverHttp@d6ed6e9{r=0,c=false,a=IDLE,uri=}
[qtp1455204443-59] WARN org.eclipse.jetty.http.HttpParser - Illegal character 0x0 in state=START for buffer HeapByteBuffer@60931ed5[p=1,l=35,c=16384,r=34]={\x00<<<\x00\x00#\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x01us...\x00password\x00\x004\x00\x00\x00>>>5/engineOff/*HQ,8...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
[qtp1455204443-59] WARN org.eclipse.jetty.http.HttpParser - badMessage: 400 Illegal character 0x0 for HttpChannelOverHttp@d6ed6e9{r=0,c=false,a=IDLE,uri=}
[qtp1455204443-59] WARN org.eclipse.jetty.http.HttpParser - Illegal character 0x0 in state=START for buffer HeapByteBuffer@60931ed5[p=1,l=35,c=16384,r=34]={\x00<<<\x00\x00#\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x01us...\x00password\x00\x004\x00\x00\x00>>>5/engineOff/*HQ,8...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
[qtp1455204443-59] WARN org.eclipse.jetty.http.HttpParser - badMessage: 400 Illegal character 0x0 for HttpChannelOverHttp@d6ed6e9{r=0,c=false,a=IDLE,uri=}

and so on...

Sumit 7 years ago

I have older version of Traccar and I am making API to call to Traccar API to send custom command:
I parsed the phone number of the device and command to be executed:

public synchronized void sendDirectMessageSync(String destAddress, String message, boolean command) throws SmppInvalidArgumentException, RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException {

SubmitSm submit = new SubmitSm();
            byte[] textBytes;
            textBytes = CharsetUtil.encode(message, command ? commandsCharsetName : notificationsCharsetName);
            submit.setDataCoding(command ? commandsDataCoding : notificationsDataCoding);
            submit.setShortMessage(textBytes);
            submit.setSourceAddress(command ? new Address(commandSourceTon, commandSourceNpi, commandSourceAddress)
                    : new Address(sourceTon, sourceNpi, sourceAddress));
            submit.setDestAddress(new Address(destTon, destNpi, destAddress));
            
            
            try {
                
                smppSession = clientBootstrap.bind(sessionConfig, sessionHandler);
                stopReconnectionkTask();
                runEnquireLinkTask();
                System.out.println("SMPP session connected");
                if(getSession()==null){
                    System.out.println("SmppSession failed");
                }
                else{
                    System.out.println("smp success");
                }
                SubmitSmResp submitResponce = getSession().submit(submit, Context.getConfig().getInteger("sms.smpp.submitTimeout", 10000));
                
                if (submitResponce.getCommandStatus() == SmppConstants.STATUS_OK) {
                    System.out.println("SMS submitted, message id: " + submitResponce.getMessageId());
                } else {
                    throw new IllegalStateException(submitResponce.getResultMessage());
                }
                                
            } catch (SmppTimeoutException | SmppChannelException
                    | UnrecoverablePduException | InterruptedException error) {
                System.out.println("Unable to connect to SMPP server: "+error);
            }
            
            disconnect();

}

Please tell me if I have done wrong thing.

Sumit 7 years ago

Hi Anton,
I am getting this error

SEVERE: Following issues have been detected: 
WARNING: No injection source found for a parameter of type public javax.ws.rs.core.Response org.traccar.api.resource.CommandResource.getResponse(java.lang.Long,java.lang.String,java.lang.String,org.traccar.model.Command) throws java.lang.Exception at index 3.

[main] WARN /api - unavailable
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response org.traccar.api.resource.CommandResource.getResponse(java.lang.Long,java.lang.String,java.lang.String,org.traccar.model.Command) throws java.lang.Exception at index 3.; source='ResourceMethod{httpMethod=POST, consumedTypes=[application/json], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class org.traccar.api.resource.CommandResource, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@798cb6d9]}, definitionMethod=public javax.ws.rs.core.Response org.traccar.api.resource.CommandResource.getResponse(java.lang.Long,java.lang.String,java.lang.String,org.traccar.model.Command) throws java.lang.Exception, parameters=[Parameter [type=class java.lang.Long, source=user_id, defaultValue=null], Parameter [type=class java.lang.String, source=phone, defaultValue=null], Parameter [type=class java.lang.String, source=command_name, defaultValue=null], Parameter [type=class org.traccar.model.Command, source=command_value, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']
	at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:555)
	at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
	at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
	at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
	at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
	at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
	at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:392)
	at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
	at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
	at javax.servlet.GenericServlet.init(GenericServlet.java:244)
	at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:616)
	at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:396)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:871)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
	at org.eclipse.jetty.server.Server.start(Server.java:387)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
	at org.eclipse.jetty.server.Server.doStart(Server.java:354)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.traccar.web.WebServer.start(WebServer.java:154)
	at org.traccar.Main.main(Main.java:42)
Sumit 7 years ago

My CommandResource.java file code is this:


package org.traccar.api.resource;

import javax.annotation.security.PermitAll;
import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.model.Command;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.traccar.BaseProtocol;
import org.traccar.database.ActiveDevice;
import org.traccar.model.Device;
import org.traccar.model.Position;
import org.traccar.smpp.SmppClient;

@Path("commands")

public class CommandResource extends BaseResource {
     
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response add(Command entity) throws Exception {
        Context.getPermissionsManager().checkReadonly(getUserId());
        Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
        Context.getDeviceManager().sendCommand(entity);
        return Response.ok(entity).build();
    }
    
    @PermitAll
    @POST
    @Path("/send/{user_id}/{phone}/{command_name}/{command_value}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response getResponse(@PathParam("user_id")Long user_id, @PathParam("phone")String phone,
            @PathParam("command_name")String command_name, @PathParam("command_value")Command command_value) throws Exception{
        
        //command_value += "#";
        //(new SmppClient()).sendDirectMessageSync(phone,command_value, true);
        Context.getDeviceManager().sendCommand(command_value);
        System.out.println(phone+"===>"+command_value);
        
        return Response.ok("Sent").build();
    }

}