openHAB set to use HTTPS only... how to re-enable HTTP?

  • Platform information:
    • Hardware: Mac Mini (late 2012) 2.6 GHz Quad-Core Intel Core i7 16 GB
    • OS: MacOS 10.15.7
    • Java Runtime Environment: OpenJDK Runtime Environment Zulu11.54+25-CA (build 11.0.14.1+1-LTS)
    • openHAB version: 3.4.0.M5
  • Issue of the topic: at some point I set it to only use HTTPS… how can I re-enable HTTP as well as HTTPS?

The question in the topic is pretty much everything. At some point through excessive vigilance, I have configured openHAB to use only HTTPS and not HTTP. Unfortunately, it now looks like I need regular non-secure HTTP for the IpObserver binding to function, and I can’t figure out how to turn it back on!

I don’t think there is a simple way to enable/disable HTTP so I’m guessing you edited userdata/etc/jetty.xml, perhaps commenting out the HTTP section. If not I’ve no idea.

I’m pretty sure I didn’t do that… but here’s the contents of that file in case either I or something automated did so!

<?xml version="1.0"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-->
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <!-- =========================================================== -->
    <!-- Set connectors -->
    <!-- =========================================================== -->
    <!-- One of each type! -->
    <!-- =========================================================== -->

    <!-- Use this connector for many frequently idle connections and for 
        threadless continuations. -->
	<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
		<Set name="secureScheme">https</Set>
		<Set name="securePort">
			<Property name="jetty.secure.port" default="8443" />
		</Set>
		<Set name="outputBufferSize">32768</Set>
		<Set name="requestHeaderSize">8192</Set>
		<Set name="responseHeaderSize">8192</Set>
		<Set name="sendServerVersion">true</Set>
		<Set name="sendDateHeader">false</Set>
		<Set name="headerCacheSize">512</Set>
	</New>

	<!-- =========================================================== -->
    <!-- Special server connectors -->
    <!-- =========================================================== -->
    <!-- This is a sample for alternative connectors, enable if needed -->
    <!-- =========================================================== -->
    <!-- 
	<Call name="addConnector">
		<Arg>
			<New class="org.eclipse.jetty.server.ServerConnector">
				<Arg name="server">
					<Ref refid="Server" />
				</Arg>
				<Arg name="factories">
					<Array type="org.eclipse.jetty.server.ConnectionFactory">
						<Item>
							<New class="org.eclipse.jetty.server.HttpConnectionFactory">
								<Arg name="config">
									<Ref refid="httpConfig" />
								</Arg>
							</New>
						</Item>
					</Array>
				</Arg>
				<Set name="host">
					<Property name="jetty.host" default="localhost" />
				</Set>
				<Set name="port">
					<Property name="jetty.port" default="8282" />
				</Set>
				<Set name="idleTimeout">
					<Property name="http.timeout" default="30000" />
				</Set>
				<Set name="name">jettyConn1</Set>
			</New>
		</Arg>
	</Call>
 	-->

    <!-- =========================================================== -->
    <!-- Configure Authentication Realms -->
    <!-- Realms may be configured for the entire server here, or -->
    <!-- they can be configured for a specific web app in a context -->
    <!-- configuration (see $(jetty.home)/contexts/test.xml for an -->
    <!-- example). -->
    <!-- =========================================================== -->
    <Call name="addBean">
        <Arg>
            <New class="org.eclipse.jetty.jaas.JAASLoginService">
                <Set name="name">karaf</Set>
                <Set name="loginModuleName">karaf</Set>
                <Set name="roleClassNames">
                    <Array type="java.lang.String">
                        <Item>org.apache.karaf.jaas.boot.principal.RolePrincipal
                        </Item>
                    </Array>
                </Set>
            </New>
        </Arg>
    </Call>
    <Call name="addBean">
        <Arg>
            <New class="org.eclipse.jetty.jaas.JAASLoginService">
                <Set name="name">default</Set>
                <Set name="loginModuleName">karaf</Set>
                <Set name="roleClassNames">
                    <Array type="java.lang.String">
                        <Item>org.apache.karaf.jaas.boot.principal.RolePrincipal
                        </Item>
                    </Array>
                </Set>
            </New>
        </Arg>
    </Call>

</Configure>

The setenv file in ${OPENHAB_HOME}/runtime/bin/ sets the HTTP_PORT to a default or uses the value that is set in /etc/default/openhab.
At the end the value that is set in setenv is used during run time -Dorg.osgi.service.http.port=${HTTP_PORT} as part of JAVA_OPTS

You need to check if the above is still part of JAVA_OPTS.

Check if your running instance ( java ) process shows -Dorg.osgi.service.http.port=8080 while it is running ( ps -ef |grep java )

OK, I tracked it down, although I don’t exactly know how it happened except that obviously it remembered it somewhere: the issue was that, at some point, another app occupied port 8080, and openHAB had put its non-secure HTTP portal on 8081. I don’t think I ever told it to change, but it seems to have stored the change away and kept running on 8081 instead of 8080. And yes - the environmental variable given in the output of ps still shows 8080… but nothing is listening on 8080 any more. Not to worry - I don’t really care which port it is on as long as I know which one it is. In the end, I tracked it down with netstat.

Thanks all for the help!

OH doesn’t automatically change ports. It will simply report a bind exception to openhab.log if it cannot connect to one of the ports it needs. You must have made this change at some point in the past.

I believe you - I just don’t know when or how I did it… or therefore, how to undo it!

You could try something like:

find /etc /usr/share/openhab /var/lib/openhab -type f -exec grep -l 8081 {} \;

This will search the three directories ( etc, /usr/share/openhab, /var/lib7openhab ) for files.
Within all the found files the command will search for string 8081.
In case it is found in one file the name of the file will be printed out.
In case it is found in several files you will get one file per line.

It does not necessarily mean if 8081 is found in one file this is cause for your ‘problem’. The files manually need to be checked.

I’ve found one relevant instance of “8081” within the openhab directory: in userdata/etc/org.ops4j.pax.web.cfg

#
# http port. 
# This is currently also in the setenv
org.osgi.service.http.port = 8081

… so I guess that’s where it has kept the setting, and where I’d go if I wanted to change it back to the default in future. I must have given it the port using an environmental variable way back when, and it stored it in there for me automatically, because I doubt I would have found this particular file to make the change otherwise, unless I stumbled across a different forum thread or set of instructions directing me to it.

Mine looks like:

#
# http port. 
# This is currently also in the setenv
# org.osgi.service.http.port = 8080

As stated in these comments this is also found in setenv part which I reported earlier.
So it really looks like you did a modification to these files because an other server wanted to use port 8080 at that time.